diff options
author | Eric Blake <ebb9@byu.net> | 2008-08-18 07:22:44 -0600 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2008-08-22 19:25:36 -0600 |
commit | 8eb70fbb1969717d7cfefea93ee9f117fd3933cd (patch) | |
tree | c3272cb7242f5dd5c47c720915a1a7c6d6f3e40c | |
parent | 67b3df0525590a61db71bab023d11cded89a024e (diff) | |
download | m4-8eb70fbb1969717d7cfefea93ee9f117fd3933cd.tar.gz |
Improve --debugmode behavior.
* m4/m4module.h (m4_debug_decode): Simplify interface.
* m4/debug.c (m4_debug_decode): Remove parameter, and handle
setting the new value.
* modules/gnu.c (debugmode): Adjust caller.
* src/freeze.c (reload_frozen_state): Likewise.
* src/main.c (main): Likewise.
(usage): Fix default for --debug.
* doc/m4.texinfo (Debugging options): Add an example.
Signed-off-by: Eric Blake <ebb9@byu.net>
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | doc/m4.texinfo | 31 | ||||
-rw-r--r-- | m4/debug.c | 7 | ||||
-rw-r--r-- | m4/m4module.h | 2 | ||||
-rw-r--r-- | modules/gnu.c | 15 | ||||
-rw-r--r-- | src/freeze.c | 12 | ||||
-rw-r--r-- | src/main.c | 28 |
7 files changed, 55 insertions, 52 deletions
@@ -1,3 +1,15 @@ +2008-08-22 Eric Blake <ebb9@byu.net> + + Improve --debugmode behavior. + * m4/m4module.h (m4_debug_decode): Simplify interface. + * m4/debug.c (m4_debug_decode): Remove parameter, and handle + setting the new value. + * modules/gnu.c (debugmode): Adjust caller. + * src/freeze.c (reload_frozen_state): Likewise. + * src/main.c (main): Likewise. + (usage): Fix default for --debug. + * doc/m4.texinfo (Debugging options): Add an example. + 2008-08-21 Eric Blake <ebb9@byu.net> Avoid regression in defn(undef). diff --git a/doc/m4.texinfo b/doc/m4.texinfo index 06b2ab0a..0b84d089 100644 --- a/doc/m4.texinfo +++ b/doc/m4.texinfo @@ -937,23 +937,34 @@ Finally, there are several options for aiding in debugging @code{m4} scripts. @table @code -@item -d@r{[}@var{FLAGS}@r{]} -@itemx --debug@r{[}=@var{FLAGS}@r{]} -@itemx --debugmode@r{[}=@var{FLAGS}@r{]} +@item -d@r{[}@r{[}-@r{|}+@r{]}@var{FLAGS}@r{]} +@itemx --debug@r{[}=@r{[}-@r{|}+@r{]}@var{FLAGS}@r{]} +@itemx --debugmode@r{[}=@r{[}-@r{|}+@r{]}@var{FLAGS}@r{]} Set the debug-level according to the flags @var{FLAGS}. The debug-level controls the format and amount of information presented by the debugging functions. @xref{Debugmode}, for more details on the format and meaning of @var{FLAGS}. If omitted, @var{FLAGS} defaults to -@samp{+aeq}. When the option is presented multiple times, if later -@var{FLAGS} starts with @samp{-} or @samp{+}, they are cumulative, -otherwise the later flags override all earlier occurrences. Therefore, -to disable all previously set flags, specify an explicit @var{FLAGS} of -@samp{-V}. The +@samp{+aeq}. If the option occurs multiple times, @var{FLAGS} starting +with @samp{-} or @samp{+} are cumulative, while @var{FLAGS} starting +with a letter override all earlier settings. Therefore, to disable all +previously set flags, specify an explicit @var{FLAGS} of @samp{-V}. The spelling @option{--debug} is recognized as an unambiguous option for compatibility with earlier versions of @acronym{GNU} M4, but for consistency with the builtin name, you can also use the spelling -@option{--debugmode}. Order is significant with respect to -file names. +@option{--debugmode}. Order is significant with respect to file names. + +The cumulative effect of the various options in this example is +equivalent to a single invocation of @code{debugmode(alqx)}: + +@comment options: -d-V -d+lx --debug --debugmode=-e +@example +$ @kbd{m4 -d+lx --debug --debugmode=-e} +traceon(`len') +@result{} +len(`123') +@error{}m4trace:2: -1- id 2: len(`123') +@result{}3 +@end example @item --debugfile=@var{FILE} @itemx -o @var{FILE} @@ -33,8 +33,9 @@ static void set_debug_file (m4 *, const m4_call_info *, FILE *); /* Function to decode the debugging flags OPTS. Used by main while processing option -d, and by the builtin debugmode (). */ int -m4_debug_decode (m4 *context, int previous, const char *opts) +m4_debug_decode (m4 *context, const char *opts) { + int previous = context->debug_level; int level; char mode = '\0'; @@ -123,9 +124,9 @@ m4_debug_decode (m4 *context, int previous, const char *opts) break; default: - assert (!"INTERNAL ERROR: impossible mode from flags"); + assert (!"m4_debug_decode"); } - + context->debug_level = level; return level; } diff --git a/m4/m4module.h b/m4/m4module.h index c17c98ab..6c0587b9 100644 --- a/m4/m4module.h +++ b/m4/m4module.h @@ -413,7 +413,7 @@ enum { #define m4_is_debug_bit(C,B) ((m4_get_debug_level_opt (C) & (B)) != 0) -extern int m4_debug_decode (m4 *, int, const char *); +extern int m4_debug_decode (m4 *, const char *); extern bool m4_debug_set_output (m4 *, const m4_call_info *, const char *); extern void m4_debug_message_prefix (m4 *); diff --git a/modules/gnu.c b/modules/gnu.c index 75e53634..2e960305 100644 --- a/modules/gnu.c +++ b/modules/gnu.c @@ -599,20 +599,11 @@ M4BUILTIN_HANDLER (debuglen) **/ M4BUILTIN_HANDLER (debugmode) { - int debug_level = m4_get_debug_level_opt (context); - int new_debug_level; - if (argc == 1) m4_set_debug_level_opt (context, 0); - else - { - new_debug_level = m4_debug_decode (context, debug_level, M4ARG (1)); - if (new_debug_level < 0) - m4_error (context, 0, 0, m4_arg_info (argv), - _("bad debug flags: `%s'"), M4ARG (1)); - else - m4_set_debug_level_opt (context, new_debug_level); - } + else if (m4_debug_decode (context, M4ARG (1)) < 0) + m4_error (context, 0, 0, m4_arg_info (argv), + _("bad debug flags: `%s'"), M4ARG (1)); } diff --git a/src/freeze.c b/src/freeze.c index d61a8df3..4d3a2b0f 100644 --- a/src/freeze.c +++ b/src/freeze.c @@ -627,9 +627,11 @@ ill-formed frozen file, version 2 directive `%c' encountered"), 'd'); GET_STRING (file, string[0], allocated[0], number[0], false); VALIDATE ('\n'); - m4_set_debug_level_opt (context, m4_debug_decode (context, 0, - string[0])); - + if (m4_debug_decode (context, string[0]) < 0) + m4_error (context, EXIT_FAILURE, 0, NULL, + _("unknown debug mode `%s'"), + quotearg_style_mem (locale_quoting_style, string[0], + number[0])); break; case 'F': @@ -747,7 +749,9 @@ ill-formed frozen file, version 2 directive `%c' encountered"), 'R'); if (m4_get_regexp_syntax_opt (context) < 0) { m4_error (context, EXIT_FAILURE, 0, NULL, - _("unknown regexp syntax code `%s'"), string[0]); + _("unknown regexp syntax code `%s'"), + quotearg_style_mem (locale_quoting_style, string[0], + number[0])); } break; @@ -148,8 +148,8 @@ Frozen state files:\n\ puts (""); fputs (_("\ Debugging:\n\ - -d, --debug[=FLAGS], --debugmode[=FLAGS]\n\ - set debug level (no FLAGS implies `aeq')\n\ + -d, --debug[=[-|+]FLAGS], --debugmode[=[-|+]FLAGS]\n\ + set debug level (no FLAGS implies `+aeq')\n\ --debugfile=FILE redirect debug and trace output\n\ -l, --debuglen=NUM restrict macro tracing size\n\ -t, --trace=NAME, --traceon=NAME\n\ @@ -532,16 +532,8 @@ main (int argc, char *const *argv, char *const *envp) have effect between files. */ if (seen_file || frozen_file_to_read) goto defer; - { - int old = m4_get_debug_level_opt (context); - m4_set_debug_level_opt (context, m4_debug_decode (context, old, - optarg)); - } - if (m4_get_debug_level_opt (context) < 0) - { - error (0, 0, _("bad debug flags: `%s'"), optarg); - m4_set_debug_level_opt (context, 0); - } + if (m4_debug_decode (context, optarg) < 0) + error (0, 0, _("bad debug flags: `%s'"), optarg); break; case 'e': @@ -689,16 +681,8 @@ main (int argc, char *const *argv, char *const *envp) break; case 'd': - { - int old = m4_get_debug_level_opt (context); - m4_set_debug_level_opt (context, m4_debug_decode (context, old, - arg)); - } - if (m4_get_debug_level_opt (context) < 0) - { - error (0, 0, _("bad debug flags: `%s'"), arg); - m4_set_debug_level_opt (context, 0); - } + if (m4_debug_decode (context, arg) < 0) + error (0, 0, _("bad debug flags: `%s'"), arg); break; case 'm': |