28 |
static int produce_char_dump (char *buf, int ch); |
static int produce_char_dump (char *buf, int ch); |
29 |
static void produce_syntax_dump (FILE *file, char ch, int mask); |
static void produce_syntax_dump (FILE *file, char ch, int mask); |
30 |
static void produce_module_dump (FILE *file, lt_dlhandle handle); |
static void produce_module_dump (FILE *file, lt_dlhandle handle); |
31 |
static void produce_symbol_dump (FILE *file, m4_hash *hash); |
static void produce_symbol_dump (m4 *context, FILE *file, |
32 |
|
m4_symtab *symtab); |
33 |
|
static void *dump_symbol_CB (m4_symtab *symtab, const char *symbol_name, |
34 |
|
m4_symbol *symbol, void *userdata); |
35 |
|
|
36 |
|
|
37 |
/* Produce a frozen state to the given file NAME. */ |
/* Produce a frozen state to the given file NAME. */ |
125 |
This order ensures that, at reload time, pushdef's will be |
This order ensures that, at reload time, pushdef's will be |
126 |
executed with the oldest definitions first. */ |
executed with the oldest definitions first. */ |
127 |
void |
void |
128 |
produce_symbol_dump (FILE *file, m4_hash *hash) |
produce_symbol_dump (m4 *context, FILE *file, m4_symtab *symtab) |
129 |
{ |
{ |
130 |
m4_hash_iterator *place = 0; |
const char *errormsg = m4_symtab_apply (symtab, dump_symbol_CB, file); |
131 |
|
|
132 |
while ((place = m4_get_hash_iterator_next (hash, place))) |
if (errormsg) |
133 |
{ |
{ |
134 |
const char *symbol_name = (const char *) m4_get_hash_iterator_key (place); |
M4ERROR ((m4_get_warning_status_opt (context), 0, errormsg)); |
135 |
m4_symbol *symbol = m4_get_hash_iterator_value (place); |
abort (); |
136 |
lt_dlhandle handle = SYMBOL_HANDLE (symbol); |
} |
137 |
const char *module_name = handle ? m4_get_module_name (handle) : NULL; |
} |
|
const m4_builtin *bp; |
|
138 |
|
|
139 |
if (m4_is_symbol_text (symbol)) |
static void * |
140 |
{ |
dump_symbol_CB (m4_symtab *symtab, const char *symbol_name, m4_symbol *symbol, |
141 |
fprintf (file, "T%lu,%lu", |
void *userdata) |
142 |
(unsigned long) strlen (symbol_name), |
{ |
143 |
(unsigned long) strlen (m4_get_symbol_text (symbol))); |
lt_dlhandle handle = SYMBOL_HANDLE (symbol); |
144 |
if (handle) |
const char *module_name = handle ? m4_get_module_name (handle) : NULL; |
145 |
fprintf (file, ",%lu", (unsigned long) strlen (module_name)); |
FILE * file = (FILE *) userdata; |
146 |
fputc ('\n', file); |
|
147 |
|
if (m4_is_symbol_text (symbol)) |
148 |
fputs (symbol_name, file); |
{ |
149 |
fputs (m4_get_symbol_text (symbol), file); |
fprintf (file, "T%lu,%lu", |
150 |
if (handle) |
(unsigned long) strlen (symbol_name), |
151 |
fputs (module_name, file); |
(unsigned long) strlen (m4_get_symbol_text (symbol))); |
152 |
fputc ('\n', file); |
if (handle) |
153 |
} |
fprintf (file, ",%lu", (unsigned long) strlen (module_name)); |
154 |
else if (m4_is_symbol_func (symbol)) |
fputc ('\n', file); |
155 |
{ |
|
156 |
bp = m4_builtin_find_by_func |
fputs (symbol_name, file); |
157 |
(m4_get_module_builtin_table (SYMBOL_HANDLE (symbol)), |
fputs (m4_get_symbol_text (symbol), file); |
158 |
|
if (handle) |
159 |
|
fputs (module_name, file); |
160 |
|
fputc ('\n', file); |
161 |
|
} |
162 |
|
else if (m4_is_symbol_func (symbol)) |
163 |
|
{ |
164 |
|
const m4_builtin *bp = m4_builtin_find_by_func |
165 |
|
(m4_get_module_builtin_table (SYMBOL_HANDLE (symbol)), |
166 |
m4_get_symbol_func (symbol)); |
m4_get_symbol_func (symbol)); |
167 |
|
|
168 |
if (bp == NULL) |
if (bp == NULL) |
169 |
{ |
return "INTERNAL ERROR: Builtin not found in builtin table!"; |
|
M4ERROR ((warning_status, 0, |
|
|
"INTERNAL ERROR: Builtin not found in builtin table!")); |
|
|
abort (); |
|
|
} |
|
170 |
|
|
171 |
fprintf (file, "F%lu,%lu", |
fprintf (file, "F%lu,%lu", |
172 |
(unsigned long) strlen (symbol_name), |
(unsigned long) strlen (symbol_name), |
173 |
(unsigned long) strlen (bp->name)); |
(unsigned long) strlen (bp->name)); |
174 |
|
|
175 |
if (handle) |
if (handle) |
176 |
fprintf (file, ",%lu", |
fprintf (file, ",%lu", |
177 |
(unsigned long) strlen (module_name)); |
(unsigned long) strlen (module_name)); |
178 |
fputc ('\n', file); |
fputc ('\n', file); |
179 |
|
|
180 |
fputs (symbol_name, file); |
fputs (symbol_name, file); |
181 |
fputs (bp->name, file); |
fputs (bp->name, file); |
182 |
if (handle) |
if (handle) |
183 |
fputs (module_name, file); |
fputs (module_name, file); |
184 |
fputc ('\n', file); |
fputc ('\n', file); |
|
} |
|
|
else |
|
|
{ |
|
|
M4ERROR ((warning_status, 0, |
|
|
"INTERNAL ERROR: Bad token data type in produce_symbol_dump ()")); |
|
|
abort (); |
|
|
} |
|
185 |
} |
} |
186 |
|
else |
187 |
|
return "INTERNAL ERROR: Bad token data type in produce_symbol_dump ()"; |
188 |
|
|
189 |
|
return NULL; |
190 |
} |
} |
191 |
|
|
192 |
void |
void |
196 |
|
|
197 |
if (file = fopen (name, "w"), !file) |
if (file = fopen (name, "w"), !file) |
198 |
{ |
{ |
199 |
M4ERROR ((warning_status, errno, name)); |
M4ERROR ((m4_get_warning_status_opt (context), errno, name)); |
200 |
return; |
return; |
201 |
} |
} |
202 |
|
|
255 |
produce_module_dump (file, lt_dlhandle_next (0)); |
produce_module_dump (file, lt_dlhandle_next (0)); |
256 |
|
|
257 |
/* Dump all symbols. */ |
/* Dump all symbols. */ |
258 |
produce_symbol_dump (file, M4SYMTAB); |
produce_symbol_dump (context, file, M4SYMTAB); |
259 |
|
|
260 |
/* Let diversions be issued from output.c module, its cleaner to have this |
/* Let diversions be issued from output.c module, its cleaner to have this |
261 |
piece of code there. */ |
piece of code there. */ |
381 |
} \ |
} \ |
382 |
while (0) |
while (0) |
383 |
|
|
384 |
file = m4_path_search (name, (char **)NULL); |
file = m4_path_search (context, name, (char **)NULL); |
385 |
if (file == NULL) |
if (file == NULL) |
386 |
M4ERROR ((EXIT_FAILURE, errno, _("Cannot open %s"), name)); |
M4ERROR ((EXIT_FAILURE, errno, _("Cannot open %s"), name)); |
387 |
|
|
489 |
m4_symbol_pushdef (M4SYMTAB, string[0], token); |
m4_symbol_pushdef (M4SYMTAB, string[0], token); |
490 |
} |
} |
491 |
else |
else |
492 |
M4ERROR ((warning_status, 0, |
M4ERROR ((m4_get_warning_status_opt (context), 0, |
493 |
_("`%s' from frozen file not found in builtin table!"), |
_("`%s' from frozen file not found in builtin table!"), |
494 |
string[0])); |
string[0])); |
495 |
} |
} |
550 |
} |
} |
551 |
string[0][number[0]] = '\0'; |
string[0][number[0]] = '\0'; |
552 |
|
|
553 |
m4_set_syntax (syntax, string[0]); |
m4_set_syntax (context, syntax, string[0]); |
554 |
break; |
break; |
555 |
|
|
556 |
case 'C': |
case 'C': |
599 |
|
|
600 |
m4_make_diversion (number[0]); |
m4_make_diversion (number[0]); |
601 |
if (number[1] > 0) |
if (number[1] > 0) |
602 |
m4_shipout_text (NULL, string[1], number[1]); |
m4_shipout_text (context, NULL, string[1], number[1]); |
603 |
break; |
break; |
604 |
|
|
605 |
case 'Q': |
case 'Q': |