189 |
|
|
190 |
/* Print the header of a one-line debug message, starting by "m4 debug". */ |
/* Print the header of a one-line debug message, starting by "m4 debug". */ |
191 |
void |
void |
192 |
m4_debug_message_prefix (void) |
m4_debug_message_prefix (m4 *context) |
193 |
{ |
{ |
194 |
fprintf (m4_debug, "m4 debug: "); |
fprintf (m4_debug, "m4 debug: "); |
195 |
if (debug_level & M4_DEBUG_TRACE_FILE) |
if (BIT_TEST (m4_get_debug_level_opt (context), M4_DEBUG_TRACE_FILE)) |
196 |
fprintf (m4_debug, "%s: ", m4_current_file); |
fprintf (m4_debug, "%s: ", m4_current_file); |
197 |
if (debug_level & M4_DEBUG_TRACE_LINE) |
if (BIT_TEST (m4_get_debug_level_opt (context), M4_DEBUG_TRACE_LINE)) |
198 |
fprintf (m4_debug, "%d: ", m4_current_line); |
fprintf (m4_debug, "%d: ", m4_current_line); |
199 |
} |
} |
200 |
|
|
210 |
left quote) and %r (optional right quote). */ |
left quote) and %r (optional right quote). */ |
211 |
#if (defined __STDC__ && __STDC__) || defined PROTOTYPES |
#if (defined __STDC__ && __STDC__) || defined PROTOTYPES |
212 |
static void |
static void |
213 |
m4_trace_format (const char *fmt, ...) |
m4_trace_format (m4 *context, const char *fmt, ...) |
214 |
#else |
#else |
215 |
static void |
static void |
216 |
m4_trace_format (va_alist) |
m4_trace_format (m4 *context, va_alist) |
217 |
va_dcl |
va_dcl |
218 |
#endif |
#endif |
219 |
{ |
{ |
248 |
switch (*fmt++) |
switch (*fmt++) |
249 |
{ |
{ |
250 |
case 'S': |
case 'S': |
251 |
maxlen = max_debug_argument_length; |
maxlen = m4_get_max_debug_arg_length_opt (context); |
252 |
/* fall through */ |
/* fall through */ |
253 |
|
|
254 |
case 's': |
case 's': |
256 |
break; |
break; |
257 |
|
|
258 |
case 'l': |
case 'l': |
259 |
s = (debug_level & M4_DEBUG_TRACE_QUOTE) ? (char *)lquote.string : ""; |
s = BIT_TEST(m4_get_debug_level_opt(context), M4_DEBUG_TRACE_QUOTE) |
260 |
|
? (char *) lquote.string |
261 |
|
: ""; |
262 |
break; |
break; |
263 |
|
|
264 |
case 'r': |
case 'r': |
265 |
s = (debug_level & M4_DEBUG_TRACE_QUOTE) ? (char *)rquote.string : ""; |
s = BIT_TEST(m4_get_debug_level_opt(context), M4_DEBUG_TRACE_QUOTE) |
266 |
|
? (char *) rquote.string |
267 |
|
: ""; |
268 |
break; |
break; |
269 |
|
|
270 |
case 'd': |
case 'd': |
293 |
|
|
294 |
/* Format the standard header attached to all tracing output lines. */ |
/* Format the standard header attached to all tracing output lines. */ |
295 |
static void |
static void |
296 |
m4_trace_header (int id) |
m4_trace_header (m4 *context, int id) |
297 |
{ |
{ |
298 |
m4_trace_format ("m4trace:"); |
m4_trace_format (context, "m4trace:"); |
299 |
if (debug_level & M4_DEBUG_TRACE_FILE) |
if (BIT_TEST(m4_get_debug_level_opt(context), M4_DEBUG_TRACE_FILE)) |
300 |
m4_trace_format ("%s:", m4_current_file); |
m4_trace_format (context, "%s:", m4_current_file); |
301 |
if (debug_level & M4_DEBUG_TRACE_LINE) |
if (BIT_TEST(m4_get_debug_level_opt(context), M4_DEBUG_TRACE_LINE)) |
302 |
m4_trace_format ("%d:", m4_current_line); |
m4_trace_format (context, "%d:", m4_current_line); |
303 |
m4_trace_format (" -%d- ", m4_expansion_level); |
m4_trace_format (context, " -%d- ", m4_expansion_level); |
304 |
if (debug_level & M4_DEBUG_TRACE_CALLID) |
if (BIT_TEST(m4_get_debug_level_opt(context), M4_DEBUG_TRACE_CALLID)) |
305 |
m4_trace_format ("id %d: ", id); |
m4_trace_format (context, "id %d: ", id); |
306 |
} |
} |
307 |
|
|
308 |
/* Print current tracing line, and clear the obstack. */ |
/* Print current tracing line, and clear the obstack. */ |
320 |
/* Do pre-argument-collction tracing for macro NAME. Used from |
/* Do pre-argument-collction tracing for macro NAME. Used from |
321 |
expand_macro (). */ |
expand_macro (). */ |
322 |
void |
void |
323 |
m4_trace_prepre (const char *name, int id) |
m4_trace_prepre (m4 *context, const char *name, int id) |
324 |
{ |
{ |
325 |
m4_trace_header (id); |
m4_trace_header (context, id); |
326 |
m4_trace_format ("%s ...", name); |
m4_trace_format (context, "%s ...", name); |
327 |
m4_trace_flush (); |
m4_trace_flush (); |
328 |
} |
} |
329 |
|
|
330 |
/* Format the parts of a trace line, that can be made before the macro is |
/* Format the parts of a trace line, that can be made before the macro is |
331 |
actually expanded. Used from expand_macro (). */ |
actually expanded. Used from expand_macro (). */ |
332 |
void |
void |
333 |
m4_trace_pre (const char *name, int id, int argc, m4_symbol_value **argv) |
m4_trace_pre (m4 *context, const char *name, int id, |
334 |
|
int argc, m4_symbol_value **argv) |
335 |
{ |
{ |
336 |
int i; |
int i; |
337 |
const m4_builtin *bp; |
const m4_builtin *bp; |
338 |
|
|
339 |
m4_trace_header (id); |
m4_trace_header (context, id); |
340 |
m4_trace_format ("%s", name); |
m4_trace_format (context, "%s", name); |
341 |
|
|
342 |
if (argc > 1 && (debug_level & M4_DEBUG_TRACE_ARGS)) |
if (argc > 1 |
343 |
|
&& BIT_TEST (m4_get_debug_level_opt (context), M4_DEBUG_TRACE_ARGS)) |
344 |
{ |
{ |
345 |
m4_trace_format ("("); |
m4_trace_format (context, "("); |
346 |
|
|
347 |
for (i = 1; i < argc; i++) |
for (i = 1; i < argc; i++) |
348 |
{ |
{ |
349 |
if (i != 1) |
if (i != 1) |
350 |
m4_trace_format (", "); |
m4_trace_format (context, ", "); |
351 |
|
|
352 |
if (m4_is_symbol_value_text (argv[i])) |
if (m4_is_symbol_value_text (argv[i])) |
353 |
{ |
{ |
354 |
m4_trace_format ("%l%S%r", M4ARG (i)); |
m4_trace_format (context, "%l%S%r", M4ARG (i)); |
355 |
} |
} |
356 |
else if (m4_is_symbol_value_func (argv[i])) |
else if (m4_is_symbol_value_func (argv[i])) |
357 |
{ |
{ |
359 |
m4_get_symbol_value_func(argv[i])); |
m4_get_symbol_value_func(argv[i])); |
360 |
if (bp == NULL) |
if (bp == NULL) |
361 |
{ |
{ |
362 |
M4ERROR ((warning_status, 0, "\ |
M4ERROR ((m4_get_warning_status_opt (context), 0, "\ |
363 |
INTERNAL ERROR: Builtin not found in builtin table! (m4_trace_pre ())")); |
INTERNAL ERROR: Builtin not found in builtin table! (m4_trace_pre ())")); |
364 |
abort (); |
abort (); |
365 |
} |
} |
366 |
m4_trace_format ("<%s>", bp->name); |
m4_trace_format (context, "<%s>", bp->name); |
367 |
} |
} |
368 |
else |
else |
369 |
{ |
{ |
370 |
M4ERROR ((warning_status, 0, |
M4ERROR ((m4_get_warning_status_opt (context), 0, |
371 |
"INTERNAL ERROR: Bad token data type (m4_trace_pre ())")); |
"INTERNAL ERROR: Bad token data type (m4_trace_pre ())")); |
372 |
abort (); |
abort (); |
373 |
} |
} |
374 |
} |
} |
375 |
m4_trace_format (")"); |
m4_trace_format (context, ")"); |
376 |
} |
} |
377 |
|
|
378 |
if (debug_level & M4_DEBUG_TRACE_CALL) |
if (BIT_TEST (m4_get_debug_level_opt (context), M4_DEBUG_TRACE_CALL)) |
379 |
{ |
{ |
380 |
m4_trace_format (" -> ???"); |
m4_trace_format (context, " -> ???"); |
381 |
m4_trace_flush (); |
m4_trace_flush (); |
382 |
} |
} |
383 |
} |
} |
385 |
/* Format the final part of a trace line and print it all. Used from |
/* Format the final part of a trace line and print it all. Used from |
386 |
expand_macro (). */ |
expand_macro (). */ |
387 |
void |
void |
388 |
m4_trace_post (const char *name, int id, |
m4_trace_post (m4 *context, const char *name, int id, |
389 |
int argc, m4_symbol_value **argv, const char *expanded) |
int argc, m4_symbol_value **argv, const char *expanded) |
390 |
{ |
{ |
391 |
if (debug_level & M4_DEBUG_TRACE_CALL) |
if (BIT_TEST (m4_get_debug_level_opt (context), M4_DEBUG_TRACE_CALL)) |
392 |
{ |
{ |
393 |
m4_trace_header (id); |
m4_trace_header (context, id); |
394 |
m4_trace_format ("%s%s", name, (argc > 1) ? "(...)" : ""); |
m4_trace_format (context, "%s%s", name, (argc > 1) ? "(...)" : ""); |
395 |
|
} |
396 |
|
|
397 |
|
if (expanded && (BIT_TEST (m4_get_debug_level_opt (context), |
398 |
|
M4_DEBUG_TRACE_EXPANSION))) |
399 |
|
{ |
400 |
|
m4_trace_format (context, " -> %l%S%r", expanded); |
401 |
} |
} |
402 |
|
|
|
if (expanded && (debug_level & M4_DEBUG_TRACE_EXPANSION)) |
|
|
m4_trace_format (" -> %l%S%r", expanded); |
|
403 |
m4_trace_flush (); |
m4_trace_flush (); |
404 |
} |
} |