* cfg (indent_args): Inform indent of our no-TAB policy. * src/*: Run 'make indent'. * src/builtin.c (define_user_macro): Touch up odd split in _() by reducing a layer of indentation. * src/symtab.c (struct profile): Reformat comment to avoid long line from indent. * src/input.c (next_char_1): Likewise. * src/m4.c (long_options): Likewise. (includes): Prefer <error.h> over "error.h". * src/m4.h: Likewise for <assert.h>. (m4_error, m4_placeholder): Work around indent's inability to grok ATTRIBUTE_COLD. * Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Rename to AM_DISTCHECK_CONFIGURE_FLAGS. ---
Pushing this one, then rebasing the eval patches on top. It also resulted in a bug-report against GNU indent: https://lists.gnu.org/archive/html/bug-indent/2025-04/msg00000.html Makefile.am | 2 +- cfg.mk | 1 + src/builtin.c | 228 ++++++++++++++++++++++++++------------------------ src/debug.c | 15 ++-- src/eval.c | 92 ++++++++++---------- src/format.c | 58 ++++++------- src/freeze.c | 5 +- src/input.c | 86 +++++++++---------- src/m4.c | 52 ++++++------ src/m4.h | 82 ++++++++++-------- src/macro.c | 14 ++-- src/output.c | 77 +++++++++++------ src/path.c | 10 +-- src/symtab.c | 37 ++++---- 14 files changed, 406 insertions(+), 353 deletions(-) diff --git a/Makefile.am b/Makefile.am index 3e27e67d..8d76b29d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,7 +35,7 @@ MAINTAINERCLEANFILES = INSTALL Makefile.in aclocal.m4 \ ACLOCAL_AMFLAGS = -I m4 ## Enough users install GNU M4 as gm4 that we make sure 'make installcheck' ## will handle that, prior to making a release. -DISTCHECK_CONFIGURE_FLAGS = --enable-changeword --program-prefix=g \ +AM_DISTCHECK_CONFIGURE_FLAGS = --enable-changeword --program-prefix=g \ --enable-gcc-warnings --enable-silent-rules --enable-cxx # Generate the ChangeLog from git history. diff --git a/cfg.mk b/cfg.mk index f04f57ba..6cdfc3e9 100644 --- a/cfg.mk +++ b/cfg.mk @@ -44,6 +44,7 @@ sc_prohibit_tab_based_indentation: @re='^ * ' \ msg='TAB in indentation; use only spaces' \ $(_prohibit_regexp) +indent_args = --ignore-profile --preprocessor-indentation 1 --no-tabs # List all syntax-check exemptions: exclude_file_name_regexp--sc_prohibit_tab_based_indentation = \ diff --git a/src/builtin.c b/src/builtin.c index efd51d9e..2d4e402e 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -90,91 +90,89 @@ DECLARE (m4_undivert); #undef DECLARE -static builtin const builtin_tab[] = -{ +static builtin const builtin_tab[] = { /* name GNUext macros blind function */ - { "__file__", true, false, false, m4___file__ }, - { "__line__", true, false, false, m4___line__ }, - { "__program__", true, false, false, m4___program__ }, - { "builtin", true, true, true, m4_builtin }, - { "changecom", false, false, false, m4_changecom }, - { "changequote", false, false, false, m4_changequote }, + {"__file__", true, false, false, m4___file__}, + {"__line__", true, false, false, m4___line__}, + {"__program__", true, false, false, m4___program__}, + {"builtin", true, true, true, m4_builtin}, + {"changecom", false, false, false, m4_changecom}, + {"changequote", false, false, false, m4_changequote}, #ifdef ENABLE_CHANGEWORD - { "changeword", true, false, true, m4_changeword }, + {"changeword", true, false, true, m4_changeword}, #endif - { "debugmode", true, false, false, m4_debugmode }, - { "debugfile", true, false, false, m4_debugfile }, - { "decr", false, false, true, m4_decr }, - { "define", false, true, true, m4_define }, - { "defn", false, false, true, m4_defn }, - { "divert", false, false, false, m4_divert }, - { "divnum", false, false, false, m4_divnum }, - { "dnl", false, false, false, m4_dnl }, - { "dumpdef", false, false, false, m4_dumpdef }, - { "errprint", false, false, true, m4_errprint }, - { "esyscmd", true, false, true, m4_esyscmd }, - { "eval", false, false, true, m4_eval }, - { "format", true, false, true, m4_format }, - { "ifdef", false, false, true, m4_ifdef }, - { "ifelse", false, false, true, m4_ifelse }, - { "include", false, false, true, m4_include }, - { "incr", false, false, true, m4_incr }, - { "index", false, false, true, m4_index }, - { "indir", true, true, true, m4_indir }, - { "len", false, false, true, m4_len }, - { "m4exit", false, false, false, m4_m4exit }, - { "m4wrap", false, false, true, m4_m4wrap }, - { "maketemp", false, false, true, m4_maketemp }, - { "mkstemp", false, false, true, m4_mkstemp }, - { "patsubst", true, false, true, m4_patsubst }, - { "popdef", false, false, true, m4_popdef }, - { "pushdef", false, true, true, m4_pushdef }, - { "regexp", true, false, true, m4_regexp }, - { "shift", false, false, true, m4_shift }, - { "sinclude", false, false, true, m4_sinclude }, - { "substr", false, false, true, m4_substr }, - { "syscmd", false, false, true, m4_syscmd }, - { "sysval", false, false, false, m4_sysval }, - { "traceoff", false, false, false, m4_traceoff }, - { "traceon", false, false, false, m4_traceon }, - { "translit", false, false, true, m4_translit }, - { "undefine", false, false, true, m4_undefine }, - { "undivert", false, false, false, m4_undivert }, + {"debugmode", true, false, false, m4_debugmode}, + {"debugfile", true, false, false, m4_debugfile}, + {"decr", false, false, true, m4_decr}, + {"define", false, true, true, m4_define}, + {"defn", false, false, true, m4_defn}, + {"divert", false, false, false, m4_divert}, + {"divnum", false, false, false, m4_divnum}, + {"dnl", false, false, false, m4_dnl}, + {"dumpdef", false, false, false, m4_dumpdef}, + {"errprint", false, false, true, m4_errprint}, + {"esyscmd", true, false, true, m4_esyscmd}, + {"eval", false, false, true, m4_eval}, + {"format", true, false, true, m4_format}, + {"ifdef", false, false, true, m4_ifdef}, + {"ifelse", false, false, true, m4_ifelse}, + {"include", false, false, true, m4_include}, + {"incr", false, false, true, m4_incr}, + {"index", false, false, true, m4_index}, + {"indir", true, true, true, m4_indir}, + {"len", false, false, true, m4_len}, + {"m4exit", false, false, false, m4_m4exit}, + {"m4wrap", false, false, true, m4_m4wrap}, + {"maketemp", false, false, true, m4_maketemp}, + {"mkstemp", false, false, true, m4_mkstemp}, + {"patsubst", true, false, true, m4_patsubst}, + {"popdef", false, false, true, m4_popdef}, + {"pushdef", false, true, true, m4_pushdef}, + {"regexp", true, false, true, m4_regexp}, + {"shift", false, false, true, m4_shift}, + {"sinclude", false, false, true, m4_sinclude}, + {"substr", false, false, true, m4_substr}, + {"syscmd", false, false, true, m4_syscmd}, + {"sysval", false, false, false, m4_sysval}, + {"traceoff", false, false, false, m4_traceoff}, + {"traceon", false, false, false, m4_traceon}, + {"translit", false, false, true, m4_translit}, + {"undefine", false, false, true, m4_undefine}, + {"undivert", false, false, false, m4_undivert}, - { 0, false, false, false, 0 }, + {0, false, false, false, 0}, /* placeholder is intentionally stuck after the table end delimiter, so that we can easily find it, while not treating it as a real builtin. */ - { "placeholder", true, false, false, m4_placeholder }, + {"placeholder", true, false, false, m4_placeholder}, }; -static predefined const predefined_tab[] = -{ +static predefined const predefined_tab[] = { #if UNIX - { "unix", "__unix__", "" }, + {"unix", "__unix__", ""}, #endif #if W32_NATIVE - { "windows", "__windows__", "" }, + {"windows", "__windows__", ""}, #endif #if OS2 - { "os2", "__os2__", "" }, + {"os2", "__os2__", ""}, #endif #if !UNIX && !W32_NATIVE && !OS2 # warning Platform macro not provided #endif - { NULL, "__gnu__", "" }, + {NULL, "__gnu__", ""}, - { NULL, NULL, NULL }, + {NULL, NULL, NULL}, }; /*----------------------------------------. | Find the builtin, which lives on ADDR. | `----------------------------------------*/ -const builtin * ATTRIBUTE_PURE +const builtin *ATTRIBUTE_PURE find_builtin_by_addr (builtin_func *func) { const builtin *bp; @@ -192,7 +190,7 @@ find_builtin_by_addr (builtin_func *func) | placeholder builtin. | `----------------------------------------------------------*/ -const builtin * ATTRIBUTE_PURE +const builtin *ATTRIBUTE_PURE find_builtin_by_name (const char *name) { const builtin *bp; @@ -251,7 +249,7 @@ set_macro_sequence (const char *regexp) { const char *msg; - if (! regexp) + if (!regexp) regexp = DEFAULT_MACRO_SEQUENCE; else if (regexp[0] == '\0') { @@ -261,11 +259,12 @@ set_macro_sequence (const char *regexp) msg = re_compile_pattern (regexp, strlen (regexp), ¯o_sequence_buf); if (msg != NULL) - m4_failure (0, _("--warn-macro-sequence: bad regular expression `%s': %s"), + m4_failure (0, + _("--warn-macro-sequence: bad regular expression `%s': %s"), regexp, msg); re_set_registers (¯o_sequence_buf, ¯o_sequence_regs, - macro_sequence_regs.num_regs, - macro_sequence_regs.start, macro_sequence_regs.end); + macro_sequence_regs.num_regs, macro_sequence_regs.start, + macro_sequence_regs.end); macro_sequence_inuse = true; } @@ -307,20 +306,23 @@ define_user_macro (const char *name, const char *text, symbol_lookup mode) while ((offset = re_search (¯o_sequence_buf, defn, len, offset, len - offset, ¯o_sequence_regs)) >= 0) { + char tmp; + /* Skip empty matches. */ if (macro_sequence_regs.start[0] == macro_sequence_regs.end[0]) - offset++; - else { - char tmp; - offset = macro_sequence_regs.end[0]; - tmp = defn[offset]; - defn[offset] = '\0'; - M4ERROR ((warning_status, 0, - _("Warning: definition of `%s' contains sequence `%s'"), - name, defn + macro_sequence_regs.start[0])); - defn[offset] = tmp; + offset++; + continue; } + + offset = macro_sequence_regs.end[0]; + tmp = defn[offset]; + defn[offset] = '\0'; + M4ERROR ((warning_status, 0, + _("Warning: definition of `%s' contains sequence `%s'"), + name, defn + macro_sequence_regs.start[0])); + defn[offset] = tmp; + } if (offset == -2) M4ERROR ((warning_status, 0, @@ -600,7 +602,7 @@ m4_undefine (struct obstack *obs MAYBE_UNUSED, int argc, token_data **argv) static void m4_pushdef (struct obstack *obs MAYBE_UNUSED, int argc, token_data **argv) { - define_macro (argc, argv, SYMBOL_PUSHDEF); + define_macro (argc, argv, SYMBOL_PUSHDEF); } static void @@ -715,8 +717,8 @@ dump_symbol (symbol *sym, void *arg) static int dumpdef_cmp (const void *s1, const void *s2) { - return strcmp (SYMBOL_NAME (* (symbol *const *) s1), - SYMBOL_NAME (* (symbol *const *) s2)); + return strcmp (SYMBOL_NAME (*(symbol * const *) s1), + SYMBOL_NAME (*(symbol * const *) s2)); } /*-------------------------------------------------------------. @@ -768,7 +770,8 @@ m4_dumpdef (struct obstack *obs, int argc, token_data **argv) case TOKEN_TEXT: if (debug_level & DEBUG_TRACE_QUOTE) DEBUG_PRINT3 ("%s%s%s\n", - lquote.string, SYMBOL_TEXT (data.base[0]), rquote.string); + lquote.string, SYMBOL_TEXT (data.base[0]), + rquote.string); else DEBUG_PRINT1 ("%s\n", SYMBOL_TEXT (data.base[0])); break; @@ -819,12 +822,11 @@ m4_builtin (struct obstack *obs, int argc, token_data **argv) name = ARG (1); bp = find_builtin_by_name (name); if (bp->func == m4_placeholder) - M4ERROR ((warning_status, 0, - _("undefined builtin `%s'"), name)); + M4ERROR ((warning_status, 0, _("undefined builtin `%s'"), name)); else { int i; - if (! bp->groks_macro_args) + if (!bp->groks_macro_args) for (i = 2; i < argc; i++) if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT) { @@ -860,12 +862,11 @@ m4_indir (struct obstack *obs, int argc, token_data **argv) name = ARG (1); s = lookup_symbol (name, SYMBOL_LOOKUP); if (s == NULL || SYMBOL_TYPE (s) == TOKEN_VOID) - M4ERROR ((warning_status, 0, - _("undefined macro `%s'"), name)); + M4ERROR ((warning_status, 0, _("undefined macro `%s'"), name)); else { int i; - if (! SYMBOL_MACRO_ARGS (s)) + if (!SYMBOL_MACRO_ARGS (s)) for (i = 2; i < argc; i++) if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT) { @@ -895,7 +896,7 @@ m4_defn (struct obstack *obs, int argc, token_data **argv) assert (0 < argc); for (i = 1; i < (unsigned) argc; i++) { - const char *arg = ARG((int) i); + const char *arg = ARG ((int) i); s = lookup_symbol (arg, SYMBOL_LOOKUP); if (s == NULL) continue; @@ -915,8 +916,7 @@ m4_defn (struct obstack *obs, int argc, token_data **argv) builtin `%s' requested by frozen file is not supported"), arg)); else if (argc != 2) M4ERROR ((warning_status, 0, - _("Warning: cannot concatenate builtin `%s'"), - arg)); + _("Warning: cannot concatenate builtin `%s'"), arg)); else push_macro (b); break; @@ -1099,8 +1099,7 @@ m4_eval (struct obstack *obs, int argc, token_data **argv) if (radix < 1 || radix > (int) strlen (digits)) { M4ERROR ((warning_status, 0, - _("radix %d in builtin `%s' out of range"), - radix, ARG (0))); + _("radix %d in builtin `%s' out of range"), radix, ARG (0))); return; } @@ -1298,15 +1297,14 @@ m4_shift (struct obstack *obs, int argc, token_data **argv) `--------------------------------------------------------------------------*/ static void -m4_changequote (struct obstack *obs MAYBE_UNUSED, int argc, - token_data **argv) +m4_changequote (struct obstack *obs MAYBE_UNUSED, int argc, token_data **argv) { if (bad_argc (argv[0], argc, 1, 3)) return; /* Explicit NULL distinguishes between empty and missing argument. */ set_quotes ((argc >= 2) ? TOKEN_DATA_TEXT (argv[1]) : NULL, - (argc >= 3) ? TOKEN_DATA_TEXT (argv[2]) : NULL); + (argc >= 3) ? TOKEN_DATA_TEXT (argv[2]) : NULL); } /*-----------------------------------------------------------------. @@ -1455,11 +1453,11 @@ m4_maketemp (struct obstack *obs, int argc, token_data **argv) are in traditional mode. For reference, Solaris m4 does: - maketemp() -> `' - maketemp(X) -> `X' - maketemp(XX) -> `Xn', where n is last digit of pid - maketemp(XXXXXXXX) -> `X00nnnnn', where nnnnn is 16-bit pid - */ + maketemp() -> `' + maketemp(X) -> `X' + maketemp(XX) -> `Xn', where n is last digit of pid + maketemp(XXXXXXXX) -> `X00nnnnn', where nnnnn is 16-bit pid + */ const char *str = ARG (1); int len = strlen (str); int i; @@ -1923,9 +1921,9 @@ m4_translit (struct obstack *obs, int argc, token_data **argv) hence the found map. */ memset (map, 0, sizeof map); memset (found, 0, sizeof found); - for ( ; (ch = *from) != '\0'; from++) + for (; (ch = *from) != '\0'; from++) { - if (! found[ch]) + if (!found[ch]) { found[ch] = 1; map[ch] = *to; @@ -1936,7 +1934,7 @@ m4_translit (struct obstack *obs, int argc, token_data **argv) for (data = ARG (1); (ch = *data) != '\0'; data++) { - if (! found[ch]) + if (!found[ch]) obstack_1grow (obs, ch); else if (map[ch]) obstack_1grow (obs, map[ch]); @@ -2000,8 +1998,15 @@ Warning: \\0 will disappear, use \\& instead in replacements"))); repl++; break; - case '1': case '2': case '3': case '4': case '5': case '6': - case '7': case '8': case '9': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': ind = ch -= '0'; if (regs->num_regs - 1 <= ind) M4ERROR ((warning_status, 0, @@ -2206,8 +2211,7 @@ m4_patsubst (struct obstack *obs, int argc, token_data **argv) `--------------------------------------------------------------------*/ void -m4_placeholder (struct obstack *obs MAYBE_UNUSED, int argc, - token_data **argv) +m4_placeholder (struct obstack *obs MAYBE_UNUSED, int argc, token_data **argv) { M4ERROR ((warning_status, 0, _("\ builtin `%s' requested by frozen file is not supported"), ARG (0))); @@ -2239,8 +2243,16 @@ expand_user_macro (struct obstack *obs, symbol *sym, text = dollar; switch (*++text) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': if (no_gnu_extensions) { i = *text++ - '0'; @@ -2248,20 +2260,20 @@ expand_user_macro (struct obstack *obs, symbol *sym, else { for (i = 0; c_isdigit (*text); text++) - i = i*10 + (*text - '0'); + i = i * 10 + (*text - '0'); } if (i < argc) obstack_grow (obs, TOKEN_DATA_TEXT (argv[i]), strlen (TOKEN_DATA_TEXT (argv[i]))); break; - case '#': /* number of arguments */ + case '#': /* number of arguments */ shipout_int (obs, argc - 1); text++; break; - case '*': /* all arguments */ - case '@': /* ... same, but quoted */ + case '*': /* all arguments */ + case '@': /* ... same, but quoted */ dump_args (obs, argc, argv, ",", *text == '@'); text++; break; diff --git a/src/debug.c b/src/debug.c index a4017660..acc83e5e 100644 --- a/src/debug.c +++ b/src/debug.c @@ -186,8 +186,7 @@ debug_flush_files (void) this attempt. The stdio-safer module and friends are essential, so that if stdin was closed, this lseek is not on some other file that we have since opened. */ - if (lseek (STDIN_FILENO, 0, SEEK_CUR) >= 0 - && fflush (stdin) == 0) + if (lseek (STDIN_FILENO, 0, SEEK_CUR) >= 0 && fflush (stdin) == 0) { fseeko (stdin, 0, SEEK_CUR); } @@ -228,12 +227,12 @@ debug_message_prefix (void) { xfprintf (debug, "m4debug:"); if (current_line) - { - if (debug_level & DEBUG_TRACE_FILE) - xfprintf (debug, "%s:", current_file); - if (debug_level & DEBUG_TRACE_LINE) - xfprintf (debug, "%d:", current_line); - } + { + if (debug_level & DEBUG_TRACE_FILE) + xfprintf (debug, "%s:", current_file); + if (debug_level & DEBUG_TRACE_LINE) + xfprintf (debug, "%d:", current_line); + } putc (' ', debug); } diff --git a/src/eval.c b/src/eval.c index 97eeb3eb..90362918 100644 --- a/src/eval.c +++ b/src/eval.c @@ -29,37 +29,37 @@ /* Evaluates token types. */ typedef enum eval_token - { - ERROR, BADOP, - PLUS, MINUS, - EXPONENT, - TIMES, DIVIDE, MODULO, - ASSIGN, EQ, NOTEQ, GT, GTEQ, LS, LSEQ, - LSHIFT, RSHIFT, - LNOT, LAND, LOR, - NOT, AND, OR, XOR, - LEFTP, RIGHTP, - NUMBER, EOTEXT - } +{ + ERROR, BADOP, + PLUS, MINUS, + EXPONENT, + TIMES, DIVIDE, MODULO, + ASSIGN, EQ, NOTEQ, GT, GTEQ, LS, LSEQ, + LSHIFT, RSHIFT, + LNOT, LAND, LOR, + NOT, AND, OR, XOR, + LEFTP, RIGHTP, + NUMBER, EOTEXT +} eval_token; /* Error types. */ typedef enum eval_error - { - NO_ERROR, - DIVIDE_ZERO, - MODULO_ZERO, - NEGATIVE_EXPONENT, - /* All errors prior to SYNTAX_ERROR can be ignored in a dead - branch of && and ||. All errors after are just more details - about a syntax error. */ - SYNTAX_ERROR, - MISSING_RIGHT, - UNKNOWN_INPUT, - EXCESS_INPUT, - INVALID_OPERATOR - } +{ + NO_ERROR, + DIVIDE_ZERO, + MODULO_ZERO, + NEGATIVE_EXPONENT, + /* All errors prior to SYNTAX_ERROR can be ignored in a dead + branch of && and ||. All errors after are just more details + about a syntax error. */ + SYNTAX_ERROR, + MISSING_RIGHT, + UNKNOWN_INPUT, + EXCESS_INPUT, + INVALID_OPERATOR +} eval_error; static eval_error logical_or_term (eval_token, int32_t *); @@ -320,8 +320,7 @@ evaluate (const char *expr, int32_t *val) break; case SYNTAX_ERROR: - M4ERROR ((warning_status, 0, - _("bad expression in eval: %s"), expr)); + M4ERROR ((warning_status, 0, _("bad expression in eval: %s"), expr)); break; case UNKNOWN_INPUT: @@ -335,24 +334,20 @@ evaluate (const char *expr, int32_t *val) break; case INVALID_OPERATOR: - M4ERROR ((warning_status, 0, - _("invalid operator in eval: %s"), expr)); + M4ERROR ((warning_status, 0, _("invalid operator in eval: %s"), expr)); retcode = EXIT_FAILURE; break; case DIVIDE_ZERO: - M4ERROR ((warning_status, 0, - _("divide by zero in eval: %s"), expr)); + M4ERROR ((warning_status, 0, _("divide by zero in eval: %s"), expr)); break; case MODULO_ZERO: - M4ERROR ((warning_status, 0, - _("modulo by zero in eval: %s"), expr)); + M4ERROR ((warning_status, 0, _("modulo by zero in eval: %s"), expr)); break; case NEGATIVE_EXPONENT: - M4ERROR ((warning_status, 0, - _("negative exponent in eval: %s"), expr)); + M4ERROR ((warning_status, 0, _("negative exponent in eval: %s"), expr)); break; default: @@ -419,7 +414,7 @@ logical_and_term (eval_token et, int32_t *v1) if (er == NO_ERROR) *v1 = *v1 && v2; else if (*v1 == 0 && er < SYNTAX_ERROR) - ; /* v1 is already 0 */ + ; /* v1 is already 0 */ else return er; } @@ -534,11 +529,11 @@ equality_term (eval_token et, int32_t *v1) return er; if (op == ASSIGN) - { - M4ERROR ((warning_status, 0, _("\ + { + M4ERROR ((warning_status, 0, _("\ Warning: recommend ==, not =, for equality operator"))); - op = EQ; - } + op = EQ; + } *v1 = (op == EQ) == (*v1 == v2); } if (op == ERROR) @@ -558,8 +553,7 @@ cmp_term (eval_token et, int32_t *v1) if ((er = shift_term (et, v1)) != NO_ERROR) return er; - while ((op = eval_lex (&v2)) == GT || op == GTEQ - || op == LS || op == LSEQ) + while ((op = eval_lex (&v2)) == GT || op == GTEQ || op == LS || op == LSEQ) { et = eval_lex (&v2); @@ -678,9 +672,9 @@ add_term (eval_token et, int32_t *v1) unsigned to signed is a silent twos-complement wrap-around. */ if (op == PLUS) - *v1 = (int32_t) ((uint32_t) *v1 + (uint32_t) v2); + *v1 = (int32_t) ((uint32_t) * v1 + (uint32_t) v2); else - *v1 = (int32_t) ((uint32_t) *v1 - (uint32_t) v2); + *v1 = (int32_t) ((uint32_t) * v1 - (uint32_t) v2); } if (op == ERROR) return UNKNOWN_INPUT; @@ -715,7 +709,7 @@ mult_term (eval_token et, int32_t *v1) switch (op) { case TIMES: - *v1 = (int32_t) ((uint32_t) *v1 * (uint32_t) v2); + *v1 = (int32_t) ((uint32_t) * v1 * (uint32_t) v2); break; case DIVIDE: @@ -723,7 +717,7 @@ mult_term (eval_token et, int32_t *v1) return DIVIDE_ZERO; else if (v2 == -1) /* Avoid overflow, and the x86 SIGFPE on INT_MIN / -1. */ - *v1 = (int32_t) -(uint32_t) *v1; + *v1 = (int32_t) - (uint32_t) * v1; else *v1 /= v2; break; @@ -780,7 +774,7 @@ exp_term (eval_token et, int32_t *v1) if (*v1 == 0 && v2 == 0) return DIVIDE_ZERO; while (v2-- > 0) - result *= (uint32_t) *v1; + result *= (uint32_t) * v1; *v1 = result; } if (et == ERROR) @@ -809,7 +803,7 @@ unary_term (eval_token et, int32_t *v1) unsigned to signed is a silent twos-complement wrap-around. */ if (et == MINUS) - *v1 = (int32_t) -(uint32_t) *v1; + *v1 = (int32_t) - (uint32_t) * v1; else if (et == NOT) *v1 = ~*v1; else if (et == LNOT) diff --git a/src/format.c b/src/format.c index 74e5d614..4ba292c3 100644 --- a/src/format.c +++ b/src/format.c @@ -126,22 +126,23 @@ arg_double (const char *str) void expand_format (struct obstack *obs, int argc, token_data **argv) { - const char *f; /* format control string */ - const char *fmt; /* position within f */ + const char *f; /* format control string */ + const char *fmt; /* position within f */ char fstart[] = "%'+- 0#*.*hhd"; /* current format spec */ - char *p; /* position within fstart */ - unsigned char c; /* a simple character */ + char *p; /* position within fstart */ + unsigned char c; /* a simple character */ /* Flags. */ - char flags; /* flags to use in fstart */ - enum { - THOUSANDS = 0x01, /* ' */ - PLUS = 0x02, /* + */ - MINUS = 0x04, /* - */ - SPACE = 0x08, /* */ - ZERO = 0x10, /* 0 */ - ALT = 0x20, /* # */ - DONE = 0x40 /* no more flags */ + char flags; /* flags to use in fstart */ + enum + { + THOUSANDS = 0x01, /* ' */ + PLUS = 0x02, /* + */ + MINUS = 0x04, /* - */ + SPACE = 0x08, /* */ + ZERO = 0x10, /* 0 */ + ALT = 0x20, /* # */ + DONE = 0x40 /* no more flags */ }; /* Precision specifiers. */ @@ -156,7 +157,8 @@ expand_format (struct obstack *obs, int argc, token_data **argv) /* Buffer and stuff. */ char *str; /* malloc'd buffer of formatted text */ - enum {CHAR, INT, LONG, DOUBLE, STR} datatype; + enum + { CHAR, INT, LONG, DOUBLE, STR } datatype; f = fmt = ARG_STR (argc, argv); memset (ok, 0, sizeof ok); @@ -178,7 +180,7 @@ expand_format (struct obstack *obs, int argc, token_data **argv) continue; } - p = fstart + 1; /* % */ + p = fstart + 1; /* % */ lflag = 0; ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] = ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] @@ -190,33 +192,33 @@ expand_format (struct obstack *obs, int argc, token_data **argv) { switch (*fmt) { - case '\'': /* thousands separator */ + case '\'': /* thousands separator */ ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] = ok['o'] = ok['s'] = ok['x'] = ok['X'] = 0; flags |= THOUSANDS; break; - case '+': /* mandatory sign */ + case '+': /* mandatory sign */ ok['c'] = ok['o'] = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 0; flags |= PLUS; break; - case ' ': /* space instead of positive sign */ + case ' ': /* space instead of positive sign */ ok['c'] = ok['o'] = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 0; flags |= SPACE; break; - case '0': /* zero padding */ + case '0': /* zero padding */ ok['c'] = ok['s'] = 0; flags |= ZERO; break; - case '#': /* alternate output */ + case '#': /* alternate output */ ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = 0; flags |= ALT; break; - case '-': /* left justification */ + case '-': /* left justification */ flags |= MINUS; break; @@ -315,7 +317,7 @@ expand_format (struct obstack *obs, int argc, token_data **argv) { case 'c': datatype = CHAR; - p -= 2; /* %.*c is undefined, so undo the '.*'. */ + p -= 2; /* %.*c is undefined, so undo the '.*'. */ break; case 's': @@ -357,27 +359,27 @@ expand_format (struct obstack *obs, int argc, token_data **argv) switch (datatype) { case CHAR: - str = xasprintf (fstart, width, ARG_INT(argc, argv)); + str = xasprintf (fstart, width, ARG_INT (argc, argv)); break; case INT: - str = xasprintf (fstart, width, prec, ARG_INT(argc, argv)); + str = xasprintf (fstart, width, prec, ARG_INT (argc, argv)); break; case LONG: - str = xasprintf (fstart, width, prec, ARG_LONG(argc, argv)); + str = xasprintf (fstart, width, prec, ARG_LONG (argc, argv)); break; case DOUBLE: - str = xasprintf (fstart, width, prec, ARG_DOUBLE(argc, argv)); + str = xasprintf (fstart, width, prec, ARG_DOUBLE (argc, argv)); break; case STR: - str = xasprintf (fstart, width, prec, ARG_STR(argc, argv)); + str = xasprintf (fstart, width, prec, ARG_STR (argc, argv)); break; default: - abort(); + abort (); } #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) # pragma GCC diagnostic pop diff --git a/src/freeze.c b/src/freeze.c index d0b5cecd..50b1966a 100644 --- a/src/freeze.c +++ b/src/freeze.c @@ -117,12 +117,13 @@ produce_frozen_state (const char *name) /* Write a recognizable header. */ xfprintf (file, "# This is a frozen state file generated by %s\n", - PACKAGE_STRING); + PACKAGE_STRING); xfprintf (file, "V1\n"); /* Dump quote delimiters. */ - if (strcmp (lquote.string, DEF_LQUOTE) || strcmp (rquote.string, DEF_RQUOTE)) + if (strcmp (lquote.string, DEF_LQUOTE) + || strcmp (rquote.string, DEF_RQUOTE)) { xfprintf (file, "Q%d,%d\n", (int) lquote.length, (int) rquote.length); fputs (lquote.string, file); diff --git a/src/input.c b/src/input.c index f8d5c0ba..754bf4ee 100644 --- a/src/input.c +++ b/src/input.c @@ -61,14 +61,14 @@ accordingly. */ #ifdef ENABLE_CHANGEWORD -#include "regex.h" +# include "regex.h" #endif enum input_type { - INPUT_STRING, /* String resulting from macro expansion. */ - INPUT_FILE, /* File from command line or include. */ - INPUT_MACRO /* Builtin resulting from defn. */ + INPUT_STRING, /* String resulting from macro expansion. */ + INPUT_FILE, /* File from command line or include. */ + INPUT_MACRO /* Builtin resulting from defn. */ }; typedef enum input_type input_type; @@ -80,29 +80,29 @@ struct input_block const char *file; /* file where this input is from */ int line; /* line where this input is from */ union + { + struct { - struct - { - char *string; /* remaining string value */ - char *end; /* terminating NUL of string */ - } - u_s; /* INPUT_STRING */ - struct - { - FILE *fp; /* input file handle */ - bool_bitfield end : 1; /* true if peek has seen EOF */ - bool_bitfield close : 1; /* true if we should close file on pop */ - bool_bitfield advance : 1; /* track previous start_of_input_line */ - } - u_f; /* INPUT_FILE */ - builtin_func *func; /* pointer to macro's function */ + char *string; /* remaining string value */ + char *end; /* terminating NUL of string */ } + u_s; /* INPUT_STRING */ + struct + { + FILE *fp; /* input file handle */ + bool_bitfield end:1; /* true if peek has seen EOF */ + bool_bitfield close:1; /* true if we should close file on pop */ + bool_bitfield advance:1; /* track previous start_of_input_line */ + } + u_f; /* INPUT_FILE */ + builtin_func *func; /* pointer to macro's function */ + } u; }; typedef struct input_block input_block; - + /* Current input file name. */ const char *current_file; @@ -167,9 +167,9 @@ static const char *token_type_string (token_type); #endif static void pop_input (void); - + /*-------------------------------------------------------------------. | push_file () pushes an input file on the input stack, saving the | | current file name and line number. If next is non-NULL, this push | @@ -248,8 +248,7 @@ push_string_init (void) { if (next != NULL) { - M4ERROR ((warning_status, 0, - "INTERNAL ERROR: recursive push_string!")); + M4ERROR ((warning_status, 0, "INTERNAL ERROR: recursive push_string!")); abort (); } @@ -291,7 +290,7 @@ push_string_finish (void) next->u.u_s.end = next->u.u_s.string + len; next->prev = isp; isp = next; - ret = isp->u.u_s.string; /* for immediate use only */ + ret = isp->u.u_s.string; /* for immediate use only */ input_change = true; } else @@ -376,7 +375,7 @@ pop_input (void) abort (); } obstack_free (current_input, isp); - next = NULL; /* might be set in push_string_init () */ + next = NULL; /* might be set in push_string_init () */ isp = tmp; input_change = true; @@ -554,7 +553,8 @@ next_char_1 (void) break; case INPUT_MACRO: - pop_input (); /* INPUT_MACRO input sources has only one token */ + /* INPUT_MACRO input sources has only one token */ + pop_input (); return CHAR_MACRO; default: @@ -615,17 +615,17 @@ match_input (const char *s, bool consume) ch = peek_input (); if (ch != to_uchar (*s)) - return false; /* fail */ + return false; /* fail */ if (s[1] == '\0') { if (consume) next_char (); - return true; /* short match */ + return true; /* short match */ } next_char (); - for (n = 1, t = s++; peek_input () == to_uchar (*s++); ) + for (n = 1, t = s++; peek_input () == to_uchar (*s++);) { next_char (); n++; @@ -843,7 +843,7 @@ next_token (token_data *td, int *line) if (!line) line = &dummy; - /* Can't consume character until after CHAR_MACRO is handled. */ + /* Can't consume character until after CHAR_MACRO is handled. */ ch = peek_input (); if (ch == CHAR_EOF) { @@ -864,7 +864,7 @@ next_token (token_data *td, int *line) return TOKEN_MACDEF; } - next_char (); /* Consume character we already peeked at. */ + next_char (); /* Consume character we already peeked at. */ file = current_file; *line = current_line; if (MATCH (ch, bcomm.string, true)) @@ -878,14 +878,16 @@ next_token (token_data *td, int *line) else /* current_file changed to "" if we see CHAR_EOF, use the previous value we stored earlier. */ - m4_failure_at_line (0, file, *line, _("ERROR: end of file in comment")); + m4_failure_at_line (0, file, *line, + _("ERROR: end of file in comment")); type = TOKEN_STRING; } else if (default_word_regexp && (c_isalpha (ch) || ch == '_')) { obstack_1grow (&token_stack, ch); - while ((ch = peek_input ()) != CHAR_EOF && (c_isalnum (ch) || ch == '_')) + while ((ch = peek_input ()) != CHAR_EOF + && (c_isalnum (ch) || ch == '_')) { obstack_1grow (&token_stack, ch); next_char (); @@ -909,7 +911,7 @@ next_token (token_data *td, int *line) obstack_object_size (&token_stack), 0, 0, ®s); if (startpos || - regs.end [0] != (regoff_t) obstack_object_size (&token_stack)) + regs.end[0] != (regoff_t) obstack_object_size (&token_stack)) { *(((char *) obstack_base (&token_stack) + obstack_object_size (&token_stack)) - 1) = '\0'; @@ -922,10 +924,10 @@ next_token (token_data *td, int *line) orig_text = (char *) obstack_finish (&token_stack); if (regs.start[1] != -1) - obstack_grow (&token_stack,orig_text + regs.start[1], + obstack_grow (&token_stack, orig_text + regs.start[1], regs.end[1] - regs.start[1]); else - obstack_grow (&token_stack, orig_text,regs.end[0]); + obstack_grow (&token_stack, orig_text, regs.end[0]); type = TOKEN_WORD; } @@ -1057,9 +1059,9 @@ peek_token (void) } else if ((default_word_regexp && (c_isalpha (ch) || ch == '_')) #ifdef ENABLE_CHANGEWORD - || (! default_word_regexp && word_regexp.fastmap[ch]) + || (!default_word_regexp && word_regexp.fastmap[ch]) #endif /* ENABLE_CHANGEWORD */ - ) + ) { result = TOKEN_WORD; } @@ -1095,8 +1097,8 @@ peek_token (void) static const char * token_type_string (token_type t) { - switch (t) - { /* TOKSW */ + switch (t) + { /* TOKSW */ case TOKEN_EOF: return "EOF"; case TOKEN_STRING: @@ -1116,14 +1118,14 @@ token_type_string (token_type t) default: abort (); } - } +} static void print_token (const char *s, token_type t, token_data *td) { xfprintf (stderr, "%s: ", s); switch (t) - { /* TOKSW */ + { /* TOKSW */ case TOKEN_OPEN: case TOKEN_COMMA: case TOKEN_CLOSE: diff --git a/src/m4.c b/src/m4.c index db66d8df..14f4f753 100644 --- a/src/m4.c +++ b/src/m4.c @@ -33,7 +33,7 @@ #include "version-etc.h" #ifdef DEBUG_STKOVF -# include "assert.h" +# include <assert.h> #endif /* TRANSLATORS: This is a non-ASCII name: The first name is (with @@ -84,7 +84,7 @@ int retcode; struct macro_definition { struct macro_definition *next; - int code; /* D, U, s, t, '\1', or DEBUGFILE_OPTION. */ + int code; /* D, U, s, t, '\1', or DEBUGFILE_OPTION. */ const char *arg; }; typedef struct macro_definition macro_definition; @@ -102,7 +102,7 @@ m4_error (int status, int errnum, const char *format, ...) va_start (args, format); verror_at_line (status, errnum, current_line ? current_file : NULL, current_line, format, args); - if (fatal_warnings && ! retcode) + if (fatal_warnings && !retcode) retcode = EXIT_FAILURE; va_end (args); } @@ -128,7 +128,7 @@ m4_error_at_line (int status, int errnum, const char *file, int line, va_list args; va_start (args, format); verror_at_line (status, errnum, line ? file : NULL, line, format, args); - if (fatal_warnings && ! retcode) + if (fatal_warnings && !retcode) retcode = EXIT_FAILURE; va_end (args); } @@ -159,8 +159,8 @@ m4_failure_at_line (int errnum, const char *file, int line, /* Pre-translated messages for program errors. Do not translate in the signal handler, since gettext and strsignal are not async-signal-safe. */ -static const char * volatile program_error_message; -static const char * volatile signal_message[NSIG]; +static const char *volatile program_error_message; +static const char *volatile signal_message[NSIG]; /* Print a nicer message about any programmer errors, then exit. This must be aysnc-signal safe, since it is executed as a signal @@ -315,19 +315,21 @@ mismatch, or whatever value was passed to the m4exit macro.\n\ enum { DEBUGFILE_OPTION = CHAR_MAX + 1, /* no short opt */ - DIVERSIONS_OPTION, /* not quite -N, because of message */ - WARN_MACRO_SEQUENCE_OPTION, /* no short opt */ + DIVERSIONS_OPTION, /* not quite -N, because of message */ + WARN_MACRO_SEQUENCE_OPTION, /* no short opt */ - HELP_OPTION, /* no short opt */ - VERSION_OPTION /* no short opt */ + HELP_OPTION, /* no short opt */ + VERSION_OPTION /* no short opt */ }; -static const struct option long_options[] = -{ +static const struct option long_options[] = { {"arglength", required_argument, NULL, 'l'}, {"debug", optional_argument, NULL, 'd'}, {"define", required_argument, NULL, 'D'}, - {"error-output", required_argument, NULL, 'o'}, /* FIXME: deprecate in 2.0 */ + + /* FIXME: deprecate in 2.0 */ + {"error-output", required_argument, NULL, 'o'}, + {"fatal-warnings", no_argument, NULL, 'E'}, {"freeze-state", required_argument, NULL, 'F'}, {"gnu", no_argument, NULL, 'g'}, @@ -349,12 +351,13 @@ static const struct option long_options[] = {"debugfile", optional_argument, NULL, DEBUGFILE_OPTION}, {"diversions", required_argument, NULL, DIVERSIONS_OPTION}, - {"warn-macro-sequence", optional_argument, NULL, WARN_MACRO_SEQUENCE_OPTION}, + {"warn-macro-sequence", optional_argument, NULL, + WARN_MACRO_SEQUENCE_OPTION}, {"help", no_argument, NULL, HELP_OPTION}, {"version", no_argument, NULL, VERSION_OPTION}, - { NULL, 0, NULL, 0 }, + {NULL, 0, NULL, 0}, }; /* Process a command line file NAME, and return true only if it was @@ -394,9 +397,9 @@ process_file (const char *name) '-' forces getopt_long to hand back file names as arguments to opt '\1', rather than reordering the command line. */ #ifdef ENABLE_CHANGEWORD -#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:W:d::egil:o:st:" +# define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:W:d::egil:o:st:" #else -#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:d::egil:o:st:" +# define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:d::egil:o:st:" #endif int @@ -467,7 +470,7 @@ main (int argc, char *const *argv) if (crash) { if (!strtol (crash, NULL, 10)) - ++*(int *) 8; + ++ * (int *) 8; assert (false); abort (); } @@ -490,7 +493,8 @@ main (int argc, char *const *argv) /* Compatibility junk: options that other implementations support, but which we ignore as no-ops and don't list in --help. */ - error (0, 0, _("warning: `m4 -%c' may be removed in a future release"), + error (0, 0, + _("warning: `m4 -%c' may be removed in a future release"), optchar); break; @@ -523,7 +527,7 @@ main (int argc, char *const *argv) break; case 'E': - if (! fatal_warnings) + if (!fatal_warnings) fatal_warnings = true; else warning_status = EXIT_FAILURE; @@ -605,10 +609,10 @@ main (int argc, char *const *argv) break; case WARN_MACRO_SEQUENCE_OPTION: - /* Don't call set_macro_sequence here, as it can exit. - --warn-macro-sequence sets optarg to NULL (which uses the - default regexp); --warn-macro-sequence= sets optarg to "" - (which disables these warnings). */ + /* Don't call set_macro_sequence here, as it can exit. + --warn-macro-sequence sets optarg to NULL (which uses the + default regexp); --warn-macro-sequence= sets optarg to "" + (which disables these warnings). */ macro_sequence = optarg; break; diff --git a/src/m4.h b/src/m4.h index c1fb806b..168023ab 100644 --- a/src/m4.h +++ b/src/m4.h @@ -28,6 +28,7 @@ #include <assert.h> #include <c-ctype.h> #include <errno.h> +#include <error.h> #include <limits.h> #include <locale.h> #include <stdbool.h> @@ -43,7 +44,6 @@ #include "close-stream.h" #include "closein.h" #include "dirname.h" -#include "error.h" #include "exitfail.h" #include "filenamecat.h" #include "intprops.h" @@ -88,7 +88,7 @@ # undef textdomain # define textdomain(Domainname) /* empty */ # undef bindtextdomain -# define bindtextdomain(Domainname, Dirname) /* empty */ +# define bindtextdomain(Domainname, Dirname) /* empty */ #endif #define _(msgid) gettext (msgid) @@ -96,10 +96,10 @@ /* Various declarations. */ struct string - { - char *string; /* characters of the string */ - size_t length; /* length of the string */ - }; +{ + char *string; /* characters of the string */ + size_t length; /* length of the string */ +}; typedef struct string STRING; /* Memory allocation. */ @@ -122,15 +122,15 @@ typedef unsigned int bool_bitfield; /* File: m4.c --- global definitions. */ /* Option flags. */ -extern int sync_output; /* -s */ -extern int debug_level; /* -d */ -extern size_t hash_table_size; /* -H */ -extern int no_gnu_extensions; /* -G */ -extern int prefix_all_builtins; /* -P */ +extern int sync_output; /* -s */ +extern int debug_level; /* -d */ +extern size_t hash_table_size; /* -H */ +extern int no_gnu_extensions; /* -G */ +extern int prefix_all_builtins; /* -P */ extern int max_debug_argument_length; /* -l */ -extern int suppress_warnings; /* -Q */ -extern int warning_status; /* -E */ -extern int nesting_limit; /* -L */ +extern int suppress_warnings; /* -Q */ +extern int warning_status; /* -E */ +extern int nesting_limit; /* -L */ #ifdef ENABLE_CHANGEWORD extern const char *user_word_regexp; /* -W */ #endif @@ -138,6 +138,8 @@ extern const char *user_word_regexp; /* -W */ /* Error handling. */ extern int retcode; + +/* *INDENT-OFF* */ extern void m4_error (int, int, const char *, ...) ATTRIBUTE_COLD ATTRIBUTE_FORMAT ((__printf__, 3, 4)); extern void m4_error_at_line (int, int, const char *, int, const char *, ...) @@ -147,11 +149,12 @@ extern _Noreturn void m4_failure (int, const char *, ...) extern _Noreturn void m4_failure_at_line (int, const char *, int, const char *, ...) ATTRIBUTE_FORMAT ((__printf__, 4, 5)); +/* *INDENT-ON* */ #define M4ERROR(Arglist) (m4_error Arglist) #define M4ERROR_AT_LINE(Arglist) (m4_error_at_line Arglist) - + /* File: debug.c --- debugging and tracing function. */ extern FILE *debug; @@ -273,17 +276,17 @@ struct token_data { enum token_data_type type; union + { + struct { - struct - { - char *text; + char *text; #ifdef ENABLE_CHANGEWORD - char *original_text; + char *original_text; #endif - } - u_t; - builtin_func *func; } + u_t; + builtin_func *func; + } u; }; @@ -359,12 +362,12 @@ enum symbol_lookup /* Symbol table entry. */ struct symbol { - struct symbol *stack; /* pushdef stack */ - struct symbol *next; /* hash bucket chain */ - bool_bitfield traced : 1; - bool_bitfield macro_args : 1; - bool_bitfield blind_no_args : 1; - bool_bitfield deleted : 1; + struct symbol *stack; /* pushdef stack */ + struct symbol *next; /* hash bucket chain */ + bool_bitfield traced:1; + bool_bitfield macro_args:1; + bool_bitfield blind_no_args:1; + bool_bitfield deleted:1; int pending_expansions; size_t hash; @@ -387,9 +390,9 @@ typedef enum symbol_lookup symbol_lookup; typedef struct symbol symbol; typedef void hack_symbol (symbol *, void *); -#define HASHMAX 65537 /* default, overridden by -Hsize */ +#define HASHMAX 65537 /* default, overridden by -Hsize */ -extern void free_symbol (symbol *sym); +extern void free_symbol (symbol * sym); extern void symtab_init (void); extern symbol *lookup_symbol (const char *, symbol_lookup); extern void hack_all_symbols (hack_symbol *, void *); @@ -406,9 +409,9 @@ extern void call_macro (symbol *, int, token_data **, struct obstack *); struct builtin { const char *name; - bool_bitfield gnu_extension : 1; - bool_bitfield groks_macro_args : 1; - bool_bitfield blind_if_no_args : 1; + bool_bitfield gnu_extension:1; + bool_bitfield groks_macro_args:1; + bool_bitfield blind_if_no_args:1; builtin_func *func; }; @@ -435,9 +438,14 @@ extern void set_macro_sequence (const char *); extern void free_macro_sequence (void); extern void define_user_macro (const char *, const char *, symbol_lookup); extern void undivert_all (void); -extern void expand_user_macro (struct obstack *, symbol *, int, token_data **); +extern void expand_user_macro (struct obstack *, symbol *, int, + token_data **); + +/* *INDENT-OFF* */ extern void m4_placeholder (struct obstack *, int, token_data **) ATTRIBUTE_COLD; +/* *INDENT-ON* */ + extern void init_pattern_buffer (struct re_pattern_buffer *, struct re_registers *); extern const char *ntoa (int32_t, int); @@ -487,7 +495,11 @@ extern void reload_frozen_state (const char *); a bit safer than casting to unsigned char, since it catches some type errors that the cast doesn't. */ #if HAVE_INLINE -static inline unsigned char to_uchar (char ch) { return ch; } +static inline unsigned char +to_uchar (char ch) +{ + return ch; +} #else # define to_uchar(C) ((unsigned char) (C)) #endif diff --git a/src/macro.c b/src/macro.c index 0e02b43c..ea81a330 100644 --- a/src/macro.c +++ b/src/macro.c @@ -85,7 +85,7 @@ expand_token (struct obstack *obs, token_type t, token_data *td, int line) symbol *sym; switch (t) - { /* TOKSW */ + { /* TOKSW */ case TOKEN_EOF: case TOKEN_MACDEF: break; @@ -103,8 +103,7 @@ expand_token (struct obstack *obs, token_type t, token_data *td, int line) sym = lookup_symbol (TOKEN_DATA_TEXT (td), SYMBOL_LOOKUP); if (sym == NULL || SYMBOL_TYPE (sym) == TOKEN_VOID || (SYMBOL_TYPE (sym) == TOKEN_FUNC - && SYMBOL_BLIND_NO_ARGS (sym) - && peek_token () != TOKEN_OPEN)) + && SYMBOL_BLIND_NO_ARGS (sym) && peek_token () != TOKEN_OPEN)) { #ifdef ENABLE_CHANGEWORD shipout_text (obs, TOKEN_DATA_ORIG_TEXT (td), @@ -161,7 +160,7 @@ expand_argument (struct obstack *obs, token_data *argp) { switch (t) - { /* TOKSW */ + { /* TOKSW */ case TOKEN_COMMA: case TOKEN_CLOSE: if (paren_level == 0) @@ -240,7 +239,7 @@ collect_arguments (symbol *sym, struct obstack *argptr, if (peek_token () == TOKEN_OPEN) { - next_token (&td, NULL); /* gobble parenthesis */ + next_token (&td, NULL); /* gobble parenthesis */ do { more_args = expand_argument (arguments, &td); @@ -270,7 +269,7 @@ collect_arguments (symbol *sym, struct obstack *argptr, void call_macro (symbol *sym, int argc, token_data **argv, - struct obstack *expansion) + struct obstack *expansion) { switch (SYMBOL_TYPE (sym)) { @@ -329,7 +328,8 @@ expand_macro (symbol *sym) SYMBOL_PENDING_EXPANSIONS (sym)++; expansion_level++; if (nesting_limit > 0 && expansion_level > nesting_limit) - m4_failure (0, _("recursion limit of %d exceeded, use -L<N> to change it"), + m4_failure (0, + _("recursion limit of %d exceeded, use -L<N> to change it"), nesting_limit); macro_call_id++; diff --git a/src/output.c b/src/output.c index 84f1513e..381ef6fb 100644 --- a/src/output.c +++ b/src/output.c @@ -62,17 +62,17 @@ typedef struct temp_dir m4_temp_dir; typedef struct m4_diversion m4_diversion; struct m4_diversion +{ + union { - union - { - FILE *file; /* Diversion file on disk. */ - char *buffer; /* Malloc'd diversion buffer. */ - m4_diversion *next; /* Free-list pointer */ - } u; - int divnum; /* Which diversion this represents. */ - int size; /* Usable size before reallocation. */ - int used; /* Used buffer length, or tmp file exists. */ - }; + FILE *file; /* Diversion file on disk. */ + char *buffer; /* Malloc'd diversion buffer. */ + m4_diversion *next; /* Free-list pointer */ + } u; + int divnum; /* Which diversion this represents. */ + int size; /* Usable size before reallocation. */ + int used; /* Used buffer length, or tmp file exists. */ +}; /* Table of diversions 1 through INT_MAX. */ static gl_oset_t diversion_table; @@ -129,8 +129,8 @@ static int tmp_file2_owner; /* True if tmp_file2 is more recently used. */ static bool tmp_file2_recent; - + /* Internal routines. */ /* Callback for comparing list elements ELT1 and ELT2 for order in @@ -331,7 +331,7 @@ m4_tmpremove (int divnum) /* Transfer the temporary file for diversion OLDNUM to the previously unused diversion NEWNUM. Return an open stream visiting the new temporary file, positioned at the end, or exit on failure. */ -static FILE* +static FILE * m4_tmprename (int oldnum, int newnum) { /* m4_tmpname reuses its return buffer. */ @@ -346,7 +346,8 @@ m4_tmprename (int oldnum, int newnum) else { if (close_stream_temp (tmp_file1)) - m4_failure (errno, _("cannot close temporary file for diversion")); + m4_failure (errno, + _("cannot close temporary file for diversion")); tmp_file1_owner = 0; } } @@ -358,7 +359,8 @@ m4_tmprename (int oldnum, int newnum) else { if (close_stream_temp (tmp_file2)) - m4_failure (errno, _("cannot close temporary file for diversion")); + m4_failure (errno, + _("cannot close temporary file for diversion")); tmp_file2_owner = 0; } } @@ -370,8 +372,8 @@ m4_tmprename (int oldnum, int newnum) free (oldname); return m4_tmpopen (newnum, false); } - + /*------------------------. | Output initialization. | `------------------------*/ @@ -627,14 +629,37 @@ shipout_text (struct obstack *obs, const char *text, int length, int line) /* In-line short texts. */ - case 8: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 7: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 6: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 5: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 4: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 3: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 2: OUTPUT_CHARACTER (*text); text++; FALLTHROUGH; - case 1: OUTPUT_CHARACTER (*text); FALLTHROUGH; + case 8: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 7: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 6: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 5: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 4: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 3: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 2: + OUTPUT_CHARACTER (*text); + text++; + FALLTHROUGH; + case 1: + OUTPUT_CHARACTER (*text); + FALLTHROUGH; case 0: return; @@ -655,7 +680,7 @@ shipout_text (struct obstack *obs, const char *text, int length, int line) output_current_line++; #ifdef DEBUG_OUTPUT xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n", - line, current_line, output_current_line); + line, current_line, output_current_line); #endif /* Output a `#line NUM' synchronization directive if needed. @@ -694,7 +719,7 @@ shipout_text (struct obstack *obs, const char *text, int length, int line) output_current_line++; #ifdef DEBUG_OUTPUT xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n", - line, current_line, output_current_line); + line, current_line, output_current_line); #endif } OUTPUT_CHARACTER (*text); @@ -975,7 +1000,7 @@ freeze_diversions (FILE *file) saved_number = current_diversion; last_inserted = 0; make_diversion (0); - output_file = file; /* kludge in the frozen file */ + output_file = file; /* kludge in the frozen file */ iter = gl_oset_iterator (diversion_table); while (gl_oset_iterator_next (&iter, &elt)) diff --git a/src/path.c b/src/path.c index 33524a5f..4ff51f41 100644 --- a/src/path.c +++ b/src/path.c @@ -33,11 +33,11 @@ struct includes typedef struct includes includes; -static includes *dir_list; /* the list of path directories */ -static includes *dir_list_end; /* the end of same */ -static int dir_max_length; /* length of longest directory name */ - +static includes *dir_list; /* the list of path directories */ +static includes *dir_list_end; /* the end of same */ +static int dir_max_length; /* length of longest directory name */ + void include_init (void) { @@ -91,7 +91,7 @@ add_include_directory (const char *dir) incl->len = strlen (dir); incl->dir = xstrdup (dir); - if (incl->len > dir_max_length) /* remember len of longest directory */ + if (incl->len > dir_max_length) /* remember len of longest directory */ dir_max_length = incl->len; if (dir_list_end == NULL) diff --git a/src/symtab.c b/src/symtab.c index ec3ba2a3..f4a5197b 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -40,10 +40,11 @@ struct profile { - int entry; /* Number of times lookup_symbol called with this mode. */ - int comparisons; /* Number of times strcmp was called. */ - int misses; /* Number of times strcmp did not return 0. */ - long long bytes; /* Number of bytes compared. */ + int entry; /* Number of times lookup_symbol called with + this mode. */ + int comparisons; /* Number of times strcmp was called. */ + int misses; /* Number of times strcmp did not return 0. */ + long long bytes; /* Number of bytes compared. */ }; static struct profile profiles[5]; @@ -56,10 +57,10 @@ show_profile (void) int i; for (i = 0; i < 5; i++) { - xfprintf(stderr, "m4: lookup mode %d called %d times, %d compares, " - "%d misses, %lld bytes\n", - i, profiles[i].entry, profiles[i].comparisons, - profiles[i].misses, profiles[i].bytes); + xfprintf (stderr, "m4: lookup mode %d called %d times, %d compares, " + "%d misses, %lld bytes\n", + i, profiles[i].entry, profiles[i].comparisons, + profiles[i].misses, profiles[i].bytes); } } @@ -85,8 +86,8 @@ profile_strcmp (const char *s1, const char *s2) # define strcmp profile_strcmp #endif /* DEBUG_SYM */ - + /*------------------------------------------------------------------. | Initialise the symbol table, by allocating the necessary storage, | | and zeroing all the entries. | @@ -108,7 +109,7 @@ symtab_init (void) #ifdef DEBUG_SYM { - int e = atexit(show_profile); + int e = atexit (show_profile); if (e != 0) M4ERROR ((warning_status, 0, "INTERNAL ERROR: unable to show symtab profile")); @@ -143,10 +144,11 @@ free_symbol (symbol *sym) if (SYMBOL_PENDING_EXPANSIONS (sym) > 0) { SYMBOL_DELETED (sym) = true; - if (SYMBOL_STACK (sym)) { - SYMBOL_NAME (sym) = xstrdup (SYMBOL_NAME (sym)); - SYMBOL_STACK (sym) = NULL; - } + if (SYMBOL_STACK (sym)) + { + SYMBOL_NAME (sym) = xstrdup (SYMBOL_NAME (sym)); + SYMBOL_STACK (sym) = NULL; + } } else { @@ -203,7 +205,7 @@ lookup_symbol (const char *name, symbol_lookup mode) /* Symbol not found. */ - spp = (prev != NULL) ? &prev->next : &symtab[h % hash_table_size]; + spp = (prev != NULL) ? &prev->next : &symtab[h % hash_table_size]; switch (mode) { @@ -285,12 +287,11 @@ lookup_symbol (const char *name, symbol_lookup mode) if (cmp != 0) return NULL; if (sym == NULL) - return NULL; + return NULL; { bool traced = false; symbol *next; - if (SYMBOL_STACK (sym) != NULL - && mode == SYMBOL_POPDEF) + if (SYMBOL_STACK (sym) != NULL && mode == SYMBOL_POPDEF) { SYMBOL_TRACED (SYMBOL_STACK (sym)) = SYMBOL_TRACED (sym); SYMBOL_STACK (sym)->next = sym->next; -- 2.48.1 _______________________________________________ M4-patches mailing list [email protected] https://lists.gnu.org/mailman/listinfo/m4-patches
