Bruno Haible pointed out that allowing a C++ compilation on Linux can catch type errors. Most other platforms suck in too much of gnulib, including bits that won't work with C++, but this patch allows a Linux system to complete the testsuite with './configure CC=g++ --enable-changeword --without-included- regex'. It mainly involves adding casts to uses of obstacks, using <stdbool.h> instead of rolling our own boolean, and being careful when translating between char* and unsigned char*. Fortunately, I didn't detect any real bugs in this exercise.
2006-11-01 Eric Blake <[EMAIL PROTECTED]> Allow C++ compilation on Linux, as a safety measure in type checking. * m4/gnulib-cache.m4: Augment with 'gnulib-tool --import stdbool'. * src/m4.h (hack_symbol, hack_all_symbols): Use full prototype. (boolean): Kill this, and use stdbool.h instead. * src/debug.c, src/eval.c, src/input.c, src/macro.c, src/m4.c: * src/output.c, src/symtab.c: All users changed. * src/symtab.c (hack_all_symbols): Update prototype. * src/builtin.c (dump_symbol, set_trace): Update signature. (m4_dumpdef, m4_traceon, m4_traceoff): Update callers. (mkstemp_helper, m4_m4wrap, expand_ranges, m4_translit): Allow C++ compilation. * src/debug.c (trace_flush): Likewise. * src/freeze.c (reload_frozen_state): Likewise. * src/input.c (push_file, push_string_finish, push_wrapup): (token_bottom, next_token): Likewise. * src/m4.c (main): Likewise. Index: m4/gnulib-cache.m4 =================================================================== RCS file: /sources/m4/m4/m4/Attic/gnulib-cache.m4,v retrieving revision 1.1.2.18 diff -u -r1.1.2.18 gnulib-cache.m4 --- m4/gnulib-cache.m4 31 Oct 2006 14:13:41 -0000 1.1.2.18 +++ m4/gnulib-cache.m4 1 Nov 2006 22:22:49 -0000 @@ -15,11 +15,11 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libm4 --source-base=lib --m4-base=m4 -- doc-base=doc --aux-dir=. --no-libtool --macro-prefix=M4 binary-io clean-temp cloexec close-stream closeout config-h error fdl fopen-safer free gendocs getopt gnupload mkstemp obstack regex stdlib-safer strstr strtol unlocked-io verror xalloc xvasprintf +# gnulib-tool --import --dir=. --lib=libm4 --source-base=lib --m4-base=m4 -- doc-base=doc --aux-dir=. --no-libtool --macro-prefix=M4 binary-io clean-temp cloexec close-stream closeout config-h error fdl fopen-safer free gendocs getopt gnupload mkstemp obstack regex stdbool stdlib-safer strstr strtol unlocked-io verror xalloc xvasprintf # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) -gl_MODULES([binary-io clean-temp cloexec close-stream closeout config-h error fdl fopen-safer free gendocs getopt gnupload mkstemp obstack regex stdlib-safer strstr strtol unlocked-io verror xalloc xvasprintf]) +gl_MODULES([binary-io clean-temp cloexec close-stream closeout config-h error fdl fopen-safer free gendocs getopt gnupload mkstemp obstack regex stdbool stdlib-safer strstr strtol unlocked-io verror xalloc xvasprintf]) gl_AVOID([]) gl_SOURCE_BASE([lib]) gl_M4_BASE([m4]) Index: src/builtin.c =================================================================== RCS file: /sources/m4/m4/src/Attic/builtin.c,v retrieving revision 1.1.1.1.2.49 diff -u -r1.1.1.1.2.49 builtin.c --- src/builtin.c 1 Nov 2006 13:44:54 -0000 1.1.1.1.2.49 +++ src/builtin.c 1 Nov 2006 22:22:49 -0000 @@ -98,60 +98,60 @@ /* 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 @@ -288,10 +288,10 @@ | applicable. | `------------------------------------------------------------------------*/ -static boolean +static bool bad_argc (token_data *name, int argc, int min, int max) { - boolean isbad = FALSE; + bool isbad = false; if (min > 0 && argc < min) { @@ -299,7 +299,7 @@ M4ERROR ((warning_status, 0, "Warning: too few arguments to builtin `%s'", TOKEN_DATA_TEXT (name))); - isbad = TRUE; + isbad = true; } else if (max > 0 && argc > max && !suppress_warnings) M4ERROR ((warning_status, 0, @@ -312,10 +312,10 @@ /*--------------------------------------------------------------------------. | The function numeric_arg () converts ARG to an int pointed to by VALUEP. | | If the conversion fails, print error message for macro MACRO. Return | -| TRUE iff conversion succeeds. | +| true iff conversion succeeds. | `--------------------------------------------------------------------------*/ -static boolean +static bool numeric_arg (token_data *macro, const char *arg, int *valuep) { char *endp; @@ -336,7 +336,7 @@ M4ERROR ((warning_status, 0, "non-numeric argument to builtin `%s'", TOKEN_DATA_TEXT (macro))); - return FALSE; + return false; } if (isspace (to_uchar (*arg))) M4ERROR ((warning_status, 0, @@ -347,7 +347,7 @@ "numeric overflow detected in builtin `%s'", TOKEN_DATA_TEXT (macro))); } - return TRUE; + return true; } /*------------------------------------------------------------------------. @@ -361,7 +361,7 @@ static const char * ntoa (register eval_t value, int radix) { - boolean negative; + bool negative; unsigned_eval_t uvalue; static char str[256]; register char *s = &str[sizeof str]; @@ -370,12 +370,12 @@ if (value < 0) { - negative = TRUE; + negative = true; uvalue = (unsigned_eval_t) -value; } else { - negative = FALSE; + negative = false; uvalue = (unsigned_eval_t) value; } @@ -407,12 +407,12 @@ /*----------------------------------------------------------------------. | Print ARGC arguments from the table ARGV to obstack OBS, separated by | -| SEP, and quoted by the current quotes, if QUOTED is TRUE. | +| SEP, and quoted by the current quotes, if QUOTED is true. | `----------------------------------------------------------------------*/ static void dump_args (struct obstack *obs, int argc, token_data **argv, - const char *sep, boolean quoted) + const char *sep, bool quoted) { int i; size_t len = strlen (sep); @@ -609,8 +609,9 @@ }; static void -dump_symbol (symbol *sym, struct dump_symbol_data *data) +dump_symbol (symbol *sym, void *arg) { + struct dump_symbol_data *data = (struct dump_symbol_data *) arg; if (!SYMBOL_SHADOWED (sym) && SYMBOL_TYPE (sym) != TOKEN_VOID) { obstack_blank (data->obs, sizeof (symbol *)); @@ -649,7 +650,7 @@ if (argc == 1) { - hack_all_symbols (dump_symbol, (char *) &data); + hack_all_symbols (dump_symbol, &data); } else { @@ -1134,7 +1135,7 @@ { if (bad_argc (argv[0], argc, 2, -1)) return; - dump_args (obs, argc - 1, argv + 1, ",", TRUE); + dump_args (obs, argc - 1, argv + 1, ",", true); } /*--------------------------------------------------------------------------. @@ -1192,11 +1193,11 @@ /*-------------------------------------------------------------------------. | Generic include function. Include the file given by the first argument, | -| if it exists. Complain about inaccesible files iff SILENT is FALSE. | +| if it exists. Complain about inaccesible files iff SILENT is false. | `-------------------------------------------------------------------------*/ static void -include (int argc, token_data **argv, boolean silent) +include (int argc, token_data **argv, bool silent) { FILE *fp; char *name; @@ -1213,7 +1214,7 @@ return; } - push_file (fp, name, TRUE); + push_file (fp, name, true); free (name); } @@ -1224,7 +1225,7 @@ static void m4_include (struct obstack *obs, int argc, token_data **argv) { - include (argc, argv, FALSE); + include (argc, argv, false); } /*----------------------------------. @@ -1234,7 +1235,7 @@ static void m4_sinclude (struct obstack *obs, int argc, token_data **argv) { - include (argc, argv, TRUE); + include (argc, argv, true); } /* More miscellaneous builtins -- "maketemp", "errprint", "__file__", @@ -1265,7 +1266,7 @@ obstack_1grow (obs, '\0'); errno = 0; - fd = mkstemp (obstack_base (obs)); + fd = mkstemp ((char *) obstack_base (obs)); if (fd < 0) { M4ERROR ((0, errno, "cannot create tempfile `%s'", name)); @@ -1335,7 +1336,7 @@ { if (bad_argc (argv[0], argc, 2, -1)) return; - dump_args (obs, argc, argv, " ", FALSE); + dump_args (obs, argc, argv, " ", false); obstack_1grow (obs, '\0'); debug_flush_files (); fprintf (stderr, "%s", (char *) obstack_finish (obs)); @@ -1420,9 +1421,9 @@ if (no_gnu_extensions) obstack_grow (obs, ARG (1), strlen (ARG (1))); else - dump_args (obs, argc, argv, " ", FALSE); + dump_args (obs, argc, argv, " ", false); obstack_1grow (obs, '\0'); - push_wrapup (obstack_finish (obs)); + push_wrapup ((char *) obstack_finish (obs)); } /* Enable tracing of all specified macros, or all, if none is specified. @@ -1436,9 +1437,9 @@ `-----------------------------------------------------------------------*/ static void -set_trace (symbol *sym, const char *data) +set_trace (symbol *sym, void *data) { - SYMBOL_TRACED (sym) = (boolean) (data != NULL); + SYMBOL_TRACED (sym) = data != NULL; /* Remove placeholder from table if macro is undefined and untraced. */ if (SYMBOL_TYPE (sym) == TOKEN_VOID && data == NULL) lookup_symbol (SYMBOL_NAME (sym), SYMBOL_POPDEF); @@ -1451,12 +1452,12 @@ int i; if (argc == 1) - hack_all_symbols (set_trace, (char *) obs); + hack_all_symbols (set_trace, obs); else for (i = 1; i < argc; i++) { s = lookup_symbol (TOKEN_DATA_TEXT (argv[i]), SYMBOL_INSERT); - set_trace (s, (char *) obs); + set_trace (s, obs); } } @@ -1673,7 +1674,7 @@ obstack_1grow (obs, *s); } obstack_1grow (obs, '\0'); - return obstack_finish (obs); + return (char *) obstack_finish (obs); } /*----------------------------------------------------------------------. @@ -1687,9 +1688,9 @@ static void m4_translit (struct obstack *obs, int argc, token_data **argv) { - const unsigned char *data; - const unsigned char *from; - const unsigned char *to; + const char *data; + const char *from; + const char *to; char map[256] = {0}; char found[256] = {0}; @@ -1725,10 +1726,10 @@ hence the found map. */ for ( ; *from; from++) { - if (! found[*from]) + if (! found[to_uchar (*from)]) { - found[*from] = 1; - map[*from] = *to; + found[to_uchar (*from)] = 1; + map[to_uchar (*from)] = *to; } if (*to != '\0') to++; @@ -1736,10 +1737,10 @@ for (data = ARG (1); *data; data++) { - if (! found[*data]) + if (! found[to_uchar (*data)]) obstack_1grow (obs, *data); - else if (map[*data]) - obstack_1grow (obs, map[*data]); + else if (map[to_uchar (*data)]) + obstack_1grow (obs, map[to_uchar (*data)]); } } Index: src/debug.c =================================================================== RCS file: /sources/m4/m4/src/Attic/debug.c,v retrieving revision 1.1.1.1.2.10 diff -u -r1.1.1.1.2.10 debug.c --- src/debug.c 11 Sep 2006 13:17:21 -0000 1.1.1.1.2.10 +++ src/debug.c 1 Nov 2006 22:22:49 -0000 @@ -200,11 +200,11 @@ /*-------------------------------------------------------------------------. | Change the debug output to file NAME. If NAME is NULL, debug output is | -| reverted to stderr, and if empty debug output is discarded. Return TRUE | +| reverted to stderr, and if empty debug output is discarded. Return true | | iff the output stream was changed. | `-------------------------------------------------------------------------*/ -boolean +bool debug_set_output (const char *name) { FILE *fp; @@ -217,14 +217,14 @@ { fp = fopen (name, "a"); if (fp == NULL) - return FALSE; + return false; if (set_cloexec_flag (fileno (fp), true) != 0) M4ERROR ((warning_status, errno, "Warning: cannot protect debug file across forks")); debug_set_file (fp); } - return TRUE; + return true; } /*-----------------------------------------------------------------------. @@ -271,7 +271,7 @@ va_start (args, fmt); - while (TRUE) + while (true) { while ((ch = *fmt++) != '\0' && ch != '%') obstack_1grow (&trace, ch); @@ -352,7 +352,7 @@ char *line; obstack_1grow (&trace, '\0'); - line = obstack_finish (&trace); + line = (char *) obstack_finish (&trace); DEBUG_PRINT1 ("%s\n", line); obstack_free (&trace, line); } Index: src/eval.c =================================================================== RCS file: /sources/m4/m4/src/Attic/eval.c,v retrieving revision 1.1.1.1.2.6 diff -u -r1.1.1.1.2.6 eval.c --- src/eval.c 27 Jul 2006 21:41:12 -0000 1.1.1.1.2.6 +++ src/eval.c 1 Nov 2006 22:22:49 -0000 @@ -267,7 +267,7 @@ | Main entry point, called from "eval". | `---------------------------------------*/ -boolean +bool evaluate (const char *expr, eval_t *val) { eval_token et; @@ -322,7 +322,7 @@ abort (); } - return (boolean) (err != NO_ERROR); + return err != NO_ERROR; } /*---------------------------. Index: src/freeze.c =================================================================== RCS file: /sources/m4/m4/src/freeze.c,v retrieving revision 1.1.1.1.2.13 diff -u -r1.1.1.1.2.13 freeze.c --- src/freeze.c 13 Oct 2006 22:25:32 -0000 1.1.1.1.2.13 +++ src/freeze.c 1 Nov 2006 22:22:49 -0000 @@ -227,9 +227,9 @@ M4ERROR ((EXIT_FAILURE, errno, "cannot open %s", name)); allocated[0] = 100; - string[0] = xmalloc ((size_t) allocated[0]); + string[0] = xcharalloc ((size_t) allocated[0]); allocated[1] = 100; - string[1] = xmalloc ((size_t) allocated[1]); + string[1] = xcharalloc ((size_t) allocated[1]); /* Validate format version. Only `1' is acceptable for now. */ GET_DIRECTIVE; @@ -285,7 +285,7 @@ { free (string[0]); allocated[0] = number[0] + 1; - string[0] = xmalloc ((size_t) allocated[0]); + string[0] = xcharalloc ((size_t) allocated[0]); } if (number[0] > 0) @@ -301,7 +301,7 @@ { free (string[1]); allocated[1] = number[1] + 1; - string[1] = xmalloc ((size_t) allocated[1]); + string[1] = xcharalloc ((size_t) allocated[1]); } if (number[1] > 0) Index: src/input.c =================================================================== RCS file: /sources/m4/m4/src/Attic/input.c,v retrieving revision 1.1.1.1.2.31 diff -u -r1.1.1.1.2.31 input.c --- src/input.c 29 Oct 2006 15:22:42 -0000 1.1.1.1.2.31 +++ src/input.c 1 Nov 2006 22:22:49 -0000 @@ -87,9 +87,9 @@ struct { FILE *fp; /* input file handle */ - boolean end : 1; /* true if peek has seen EOF */ - boolean close : 1; /* true if we should close file on pop */ - boolean advance_line : 1; /* track previous start_of_input_line */ + bool end : 1; /* true if peek has seen EOF */ + bool close : 1; /* true if we should close file on pop */ + bool advance_line : 1; /* track previous start_of_input_line */ } u_f; /* INPUT_FILE */ builtin_func *func; /* pointer to macro's function */ @@ -119,7 +119,7 @@ static struct obstack *current_input; /* Bottom of token_stack, for obstack_free. */ -static char *token_bottom; +static void *token_bottom; /* Pointer to top of current_input. */ static input_block *isp; @@ -131,10 +131,10 @@ static input_block *next; /* Flag for next_char () to increment current_line. */ -static boolean start_of_input_line; +static bool start_of_input_line; /* Flag for next_char () to recognize change in input block. */ -static boolean input_change; +static bool input_change; #define CHAR_EOF 256 /* character return on EOF */ #define CHAR_MACRO 257 /* character return for MACRO token */ @@ -174,7 +174,7 @@ `-------------------------------------------------------------------*/ void -push_file (FILE *fp, const char *title, boolean close) +push_file (FILE *fp, const char *title, bool close) { input_block *i; @@ -190,12 +190,12 @@ i = (input_block *) obstack_alloc (current_input, sizeof (struct input_block)); i->type = INPUT_FILE; - i->file = obstack_copy0 (&file_names, title, strlen (title)); + i->file = (char *) obstack_copy0 (&file_names, title, strlen (title)); i->line = 1; - input_change = TRUE; + input_change = true; i->u.u_f.fp = fp; - i->u.u_f.end = FALSE; + i->u.u_f.end = false; i->u.u_f.close = close; i->u.u_f.advance_line = start_of_input_line; output_current_line = -1; @@ -226,7 +226,7 @@ i->type = INPUT_MACRO; i->file = current_file; i->line = current_line; - input_change = TRUE; + input_change = true; i->u.func = func; i->prev = isp; @@ -277,11 +277,11 @@ if (obstack_object_size (current_input) > 0) { obstack_1grow (current_input, '\0'); - next->u.u_s.string = obstack_finish (current_input); + next->u.u_s.string = (char *) obstack_finish (current_input); next->prev = isp; isp = next; ret = isp->u.u_s.string; /* for immediate use only */ - input_change = TRUE; + input_change = true; } else obstack_free (current_input, next); /* people might leave garbage on it. */ @@ -308,7 +308,7 @@ i->type = INPUT_STRING; i->file = current_file; i->line = current_line; - i->u.u_s.string = obstack_copy0 (wrapup_stack, s, strlen (s)); + i->u.u_s.string = (char *) obstack_copy0 (wrapup_stack, s, strlen (s)); wsp = i; } @@ -365,16 +365,16 @@ next = NULL; /* might be set in push_string_init () */ isp = tmp; - input_change = TRUE; + input_change = true; } /*------------------------------------------------------------------------. | To switch input over to the wrapup stack, main () calls pop_wrapup (). | | Since wrapup text can install new wrapup text, pop_wrapup () returns | -| FALSE when there is no wrapup text on the stack, and TRUE otherwise. | +| false when there is no wrapup text on the stack, and true otherwise. | `------------------------------------------------------------------------*/ -boolean +bool pop_wrapup (void) { next = NULL; @@ -389,7 +389,7 @@ obstack_free (&file_names, NULL); obstack_free (wrapup_stack, NULL); free (wrapup_stack); - return FALSE; + return false; } current_input = wrapup_stack; @@ -398,9 +398,9 @@ isp = wsp; wsp = NULL; - input_change = TRUE; + input_change = true; - return TRUE; + return true; } /*-------------------------------------------------------------------. @@ -456,7 +456,7 @@ ungetc (ch, block->u.u_f.fp); return ch; } - block->u.u_f.end = TRUE; + block->u.u_f.end = true; break; case INPUT_MACRO: @@ -505,7 +505,7 @@ { current_file = isp->file; current_line = isp->line; - input_change = FALSE; + input_change = false; } switch (isp->type) @@ -519,7 +519,7 @@ case INPUT_FILE: if (start_of_input_line) { - start_of_input_line = FALSE; + start_of_input_line = false; current_line = ++isp->line; } @@ -530,7 +530,7 @@ if (ch != EOF) { if (ch == '\n') - start_of_input_line = TRUE; + start_of_input_line = true; return ch; } break; @@ -576,35 +576,35 @@ current_line, and that update will be undone as we return to expand_macro. This informs next_char to fix things again. */ if (file != current_file || line != current_line) - input_change = TRUE; + input_change = true; } /*------------------------------------------------------------------. | This function is for matching a string against a prefix of the | | input stream. If the string matches the input and consume is | -| TRUE, the input is discarded; otherwise any characters read are | +| true, the input is discarded; otherwise any characters read are | | pushed back again. The function is used only when multicharacter | | quotes or comment delimiters are used. | `------------------------------------------------------------------*/ -static boolean -match_input (const char *s, boolean consume) +static bool +match_input (const char *s, bool consume) { int n; /* number of characters matched */ int ch; /* input character */ const char *t; - boolean result = FALSE; + bool result = false; ch = peek_input (); if (ch != to_uchar (*s)) - return FALSE; /* fail */ + return false; /* fail */ if (s[1] == '\0') { if (consume) (void) next_char (); - return TRUE; /* short match */ + return true; /* short match */ } (void) next_char (); @@ -615,8 +615,8 @@ if (*s == '\0') /* long match */ { if (consume) - return TRUE; - result = TRUE; + return true; + result = true; break; } } @@ -676,7 +676,7 @@ wsp = NULL; next = NULL; - start_of_input_line = FALSE; + start_of_input_line = false; lquote.string = xstrdup (DEF_LQUOTE); lquote.length = strlen (lquote.string); @@ -771,7 +771,7 @@ if (!*regexp || !strcmp (regexp, DEFAULT_WORD_REGEXP)) { - default_word_regexp = TRUE; + default_word_regexp = true; return; } @@ -800,10 +800,10 @@ regexp, msg)); } - default_word_regexp = FALSE; + default_word_regexp = false; if (word_start == NULL) - word_start = xmalloc (256); + word_start = (char *) xmalloc (256); word_start[0] = '\0'; test[1] = '\0'; @@ -870,11 +870,11 @@ next_char (); /* Consume character we already peeked at. */ file = current_file; line = current_line; - if (MATCH (ch, bcomm.string, TRUE)) + if (MATCH (ch, bcomm.string, true)) { obstack_grow (&token_stack, bcomm.string, bcomm.length); while ((ch = next_char ()) != CHAR_EOF - && !MATCH (ch, ecomm.string, TRUE)) + && !MATCH (ch, ecomm.string, true)) obstack_1grow (&token_stack, ch); if (ch != CHAR_EOF) obstack_grow (&token_stack, ecomm.string, ecomm.length); @@ -908,7 +908,8 @@ if (ch == CHAR_EOF) break; obstack_1grow (&token_stack, ch); - startpos = re_search (&word_regexp, obstack_base (&token_stack), + startpos = re_search (&word_regexp, + (char *) obstack_base (&token_stack), obstack_object_size (&token_stack), 0, 0, ®s); if (startpos != 0 || @@ -922,7 +923,7 @@ } obstack_1grow (&token_stack, '\0'); - orig_text = obstack_finish (&token_stack); + orig_text = (char *) obstack_finish (&token_stack); if (regs.start[1] != -1) obstack_grow (&token_stack,orig_text + regs.start[1], @@ -935,7 +936,7 @@ #endif /* ENABLE_CHANGEWORD */ - else if (!MATCH (ch, lquote.string, TRUE)) + else if (!MATCH (ch, lquote.string, true)) { switch (ch) { @@ -966,13 +967,13 @@ M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line, "ERROR: end of file in string")); - if (MATCH (ch, rquote.string, TRUE)) + if (MATCH (ch, rquote.string, true)) { if (--quote_level == 0) break; obstack_grow (&token_stack, rquote.string, rquote.length); } - else if (MATCH (ch, lquote.string, TRUE)) + else if (MATCH (ch, lquote.string, true)) { quote_level++; obstack_grow (&token_stack, lquote.string, lquote.length); @@ -986,7 +987,7 @@ obstack_1grow (&token_stack, '\0'); TOKEN_DATA_TYPE (td) = TOKEN_TEXT; - TOKEN_DATA_TEXT (td) = obstack_finish (&token_stack); + TOKEN_DATA_TEXT (td) = (char *) obstack_finish (&token_stack); #ifdef ENABLE_CHANGEWORD if (orig_text == NULL) orig_text = TOKEN_DATA_TEXT (td); @@ -1017,7 +1018,7 @@ { result = TOKEN_MACDEF; } - else if (MATCH (ch, bcomm.string, FALSE)) + else if (MATCH (ch, bcomm.string, false)) { result = TOKEN_STRING; } @@ -1029,7 +1030,7 @@ { result = TOKEN_WORD; } - else if (MATCH (ch, lquote.string, FALSE)) + else if (MATCH (ch, lquote.string, false)) { result = TOKEN_STRING; } Index: src/m4.c =================================================================== RCS file: /sources/m4/m4/src/Attic/m4.c,v retrieving revision 1.1.1.1.2.36 diff -u -r1.1.1.1.2.36 m4.c --- src/m4.c 1 Nov 2006 13:44:54 -0000 1.1.1.1.2.36 +++ src/m4.c 1 Nov 2006 22:22:49 -0000 @@ -257,20 +257,20 @@ where we try to continue execution in the meantime. */ int retcode; -/* Process a command line file NAME, and return TRUE only if it was +/* Process a command line file NAME, and return true only if it was stdin. */ -static boolean +static bool process_file (const char *name) { - boolean result = FALSE; + bool result = false; if (strcmp (name, "-") == 0) { /* If stdin is a terminal, we want to allow 'm4 - file -' to read input from stdin twice, like GNU cat. Besides, there is no point closing stdin before wrapped text, to minimize bugs in syscmd called from wrapped text. */ - push_file (stdin, "stdin", FALSE); - result = TRUE; + push_file (stdin, "stdin", false); + result = true; } else { @@ -282,9 +282,9 @@ /* Set the status to EXIT_FAILURE, even though we continue to process files after a missing file. */ retcode = EXIT_FAILURE; - return FALSE; + return false; } - push_file (fp, full_name, TRUE); + push_file (fp, full_name, true); free (full_name); } expand_input (); @@ -311,9 +311,9 @@ int optchar; /* option character */ macro_definition *defines; - boolean read_stdin = FALSE; - boolean interactive = FALSE; - boolean seen_file = FALSE; + bool read_stdin = false; + bool interactive = false; + bool seen_file = false; const char *debugfile = NULL; const char *frozen_file_to_read = NULL; const char *frozen_file_to_write = NULL; @@ -432,7 +432,7 @@ error (0, 0, "Warning: `m4 -e' is deprecated, use `-i' instead"); /* fall through */ case 'i': - interactive = TRUE; + interactive = true; break; case 'l': @@ -520,7 +520,7 @@ case 't': sym = lookup_symbol (defines->arg, SYMBOL_INSERT); - SYMBOL_TRACED (sym) = TRUE; + SYMBOL_TRACED (sym) = true; break; case 's': @@ -528,8 +528,9 @@ break; case '\1': - seen_file = TRUE; - read_stdin |= process_file (defines->arg); + seen_file = true; + if (process_file (defines->arg)) + read_stdin = true; break; default: @@ -550,7 +551,8 @@ read_stdin = process_file ("-"); else for (; optind < argc; optind++) - read_stdin |= process_file (argv[optind]); + if (process_file (defines->arg)) + read_stdin = true; /* Now handle wrapup text. */ Index: src/m4.h =================================================================== RCS file: /sources/m4/m4/src/m4.h,v retrieving revision 1.1.1.1.2.32 diff -u -r1.1.1.1.2.32 m4.h --- src/m4.h 1 Nov 2006 13:44:54 -0000 1.1.1.1.2.32 +++ src/m4.h 1 Nov 2006 22:22:49 -0000 @@ -27,6 +27,7 @@ #include <ctype.h> #include <errno.h> +#include <stdbool.h> #include <string.h> #include <sys/types.h> @@ -64,19 +65,6 @@ # define OS2 1 #endif -/* If FALSE is defined, we presume TRUE is defined too. In this case, - merely typedef boolean as being int. Or else, define these all. */ -#ifndef FALSE -/* Do not use `enum boolean': this tag is used in SVR4 <sys/types.h>. */ -typedef enum { FALSE = 0, TRUE = 1 } boolean; -#else -typedef int boolean; -#endif - -#if ! HAVE_MKSTEMP -int mkstemp (char *); -#endif - /* Used for version mismatch, when -R detects a frozen file it can't parse. */ #define EXIT_MISMATCH 63 @@ -228,7 +216,7 @@ void debug_init (void); int debug_decode (const char *); void debug_flush_files (void); -boolean debug_set_output (const char *); +bool debug_set_output (const char *); void debug_message_prefix (void); void trace_prepre (const char *, int); @@ -292,12 +280,12 @@ void skip_line (void); /* push back input */ -void push_file (FILE *, const char *, boolean); +void push_file (FILE *, const char *, bool); void push_macro (builtin_func *); struct obstack *push_string_init (void); const char *push_string_finish (void); void push_wrapup (const char *); -boolean pop_wrapup (void); +bool pop_wrapup (void); /* current input file, and line */ extern const char *current_file; @@ -345,11 +333,11 @@ struct symbol { struct symbol *next; - boolean traced : 1; - boolean shadowed : 1; - boolean macro_args : 1; - boolean blind_no_args : 1; - boolean deleted : 1; + bool traced : 1; + bool shadowed : 1; + bool macro_args : 1; + bool blind_no_args : 1; + bool deleted : 1; int pending_expansions; char *name; @@ -370,7 +358,7 @@ typedef enum symbol_lookup symbol_lookup; typedef struct symbol symbol; -typedef void hack_symbol (); +typedef void hack_symbol (symbol *, void *); #define HASHMAX 509 /* default, overridden by -Hsize */ @@ -379,7 +367,7 @@ void free_symbol (symbol *sym); void symtab_init (void); symbol *lookup_symbol (const char *, symbol_lookup); -void hack_all_symbols (hack_symbol *, const char *); +void hack_all_symbols (hack_symbol *, void *); /* File: macro.c --- macro expansion. */ @@ -391,9 +379,9 @@ struct builtin { const char *name; - boolean gnu_extension : 1; - boolean groks_macro_args : 1; - boolean blind_if_no_args : 1; + bool gnu_extension : 1; + bool groks_macro_args : 1; + bool blind_if_no_args : 1; builtin_func *func; }; @@ -430,7 +418,7 @@ typedef int eval_t; typedef unsigned int unsigned_eval_t; -boolean evaluate (const char *, eval_t *); +bool evaluate (const char *, eval_t *); /* File: format.c --- printf like formatting. */ Index: src/macro.c =================================================================== RCS file: /sources/m4/m4/src/Attic/macro.c,v retrieving revision 1.1.1.1.2.15 diff -u -r1.1.1.1.2.15 macro.c --- src/macro.c 26 Oct 2006 21:11:56 -0000 1.1.1.1.2.15 +++ src/macro.c 1 Nov 2006 22:22:49 -0000 @@ -134,7 +134,7 @@ | obstack OBS, indirectly through expand_token (). | `-------------------------------------------------------------------------*/ -static boolean +static bool expand_argument (struct obstack *obs, token_data *argp) { token_type t; @@ -166,14 +166,14 @@ { /* The argument MUST be finished, whether we want it or not. */ obstack_1grow (obs, '\0'); - text = obstack_finish (obs); + text = (char *) obstack_finish (obs); if (TOKEN_DATA_TYPE (argp) == TOKEN_VOID) { TOKEN_DATA_TYPE (argp) = TOKEN_TEXT; TOKEN_DATA_TEXT (argp) = text; } - return (boolean) (t == TOKEN_COMMA); + return t == TOKEN_COMMA; } /* fallthru */ case TOKEN_OPEN: @@ -229,8 +229,8 @@ { token_data td; token_data *tdp; - boolean more_args; - boolean groks_macro_args = SYMBOL_MACRO_ARGS (sym); + bool more_args; + bool groks_macro_args = SYMBOL_MACRO_ARGS (sym); TOKEN_DATA_TYPE (&td) = TOKEN_TEXT; TOKEN_DATA_TEXT (&td) = SYMBOL_NAME (sym); @@ -302,12 +302,12 @@ { struct obstack arguments; /* Alternate obstack if argc_stack is busy. */ unsigned argv_base; /* Size of argv_stack on entry. */ - boolean use_argc_stack = TRUE; /* Whether argc_stack is safe. */ + bool use_argc_stack = true; /* Whether argc_stack is safe. */ token_data **argv; int argc; struct obstack *expansion; const char *expanded; - boolean traced; + bool traced; int my_call_id; /* Report errors at the location where the open parenthesis (if any) @@ -331,17 +331,17 @@ macro_call_id++; my_call_id = macro_call_id; - traced = (boolean) ((debug_level & DEBUG_TRACE_ALL) || SYMBOL_TRACED (sym)); + traced = (debug_level & DEBUG_TRACE_ALL) || SYMBOL_TRACED (sym); argv_base = obstack_object_size (&argv_stack); if (obstack_object_size (&argc_stack) > 0) - { - /* We cannot use argc_stack if this is a nested invocation, and an - outer invocation has an unfinished argument being - collected. */ - obstack_init (&arguments); - use_argc_stack = FALSE; - } + { + /* We cannot use argc_stack if this is a nested invocation, and an + outer invocation has an unfinished argument being + collected. */ + obstack_init (&arguments); + use_argc_stack = false; + } if (traced && (debug_level & DEBUG_TRACE_CALL)) trace_prepre (SYMBOL_NAME (sym), my_call_id); Index: src/output.c =================================================================== RCS file: /sources/m4/m4/src/Attic/output.c,v retrieving revision 1.1.1.1.2.13 diff -u -r1.1.1.1.2.13 output.c --- src/output.c 26 Oct 2006 21:11:56 -0000 1.1.1.1.2.13 +++ src/output.c 1 Nov 2006 22:22:49 -0000 @@ -325,7 +325,7 @@ void shipout_text (struct obstack *obs, const char *text, int length) { - static boolean start_of_output_line = TRUE; + static bool start_of_output_line = true; char line[20]; const char *cursor; @@ -371,7 +371,7 @@ { if (start_of_output_line) { - start_of_output_line = FALSE; + start_of_output_line = false; output_current_line++; #ifdef DEBUG_OUTPUT @@ -402,7 +402,7 @@ } OUTPUT_CHARACTER (*text); if (*text == '\n') - start_of_output_line = TRUE; + start_of_output_line = true; } } Index: src/symtab.c =================================================================== RCS file: /sources/m4/m4/src/Attic/symtab.c,v retrieving revision 1.1.1.1.2.14 diff -u -r1.1.1.1.2.14 symtab.c --- src/symtab.c 26 Oct 2006 04:55:20 -0000 1.1.1.1.2.14 +++ src/symtab.c 1 Nov 2006 22:22:49 -0000 @@ -141,7 +141,7 @@ free_symbol (symbol *sym) { if (SYMBOL_PENDING_EXPANSIONS (sym) > 0) - SYMBOL_DELETED (sym) = TRUE; + SYMBOL_DELETED (sym) = true; else { free (SYMBOL_NAME (sym)); @@ -211,16 +211,16 @@ if (SYMBOL_PENDING_EXPANSIONS (sym) > 0) { symbol *old = sym; - SYMBOL_DELETED (old) = TRUE; + SYMBOL_DELETED (old) = true; sym = (symbol *) xmalloc (sizeof (symbol)); SYMBOL_TYPE (sym) = TOKEN_VOID; SYMBOL_TRACED (sym) = SYMBOL_TRACED (old); SYMBOL_NAME (sym) = xstrdup (name); - SYMBOL_SHADOWED (sym) = FALSE; - SYMBOL_MACRO_ARGS (sym) = FALSE; - SYMBOL_BLIND_NO_ARGS (sym) = FALSE; - SYMBOL_DELETED (sym) = FALSE; + SYMBOL_SHADOWED (sym) = false; + SYMBOL_MACRO_ARGS (sym) = false; + SYMBOL_BLIND_NO_ARGS (sym) = false; + SYMBOL_DELETED (sym) = false; SYMBOL_PENDING_EXPANSIONS (sym) = 0; SYMBOL_NEXT (sym) = SYMBOL_NEXT (old); @@ -239,12 +239,12 @@ sym = (symbol *) xmalloc (sizeof (symbol)); SYMBOL_TYPE (sym) = TOKEN_VOID; - SYMBOL_TRACED (sym) = FALSE; + SYMBOL_TRACED (sym) = false; SYMBOL_NAME (sym) = xstrdup (name); - SYMBOL_SHADOWED (sym) = FALSE; - SYMBOL_MACRO_ARGS (sym) = FALSE; - SYMBOL_BLIND_NO_ARGS (sym) = FALSE; - SYMBOL_DELETED (sym) = FALSE; + SYMBOL_SHADOWED (sym) = false; + SYMBOL_MACRO_ARGS (sym) = false; + SYMBOL_BLIND_NO_ARGS (sym) = false; + SYMBOL_DELETED (sym) = false; SYMBOL_PENDING_EXPANSIONS (sym) = 0; SYMBOL_NEXT (sym) = *spp; @@ -252,7 +252,7 @@ if (mode == SYMBOL_PUSHDEF && cmp == 0) { - SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = TRUE; + SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = true; SYMBOL_TRACED (sym) = SYMBOL_TRACED (SYMBOL_NEXT (sym)); } return sym; @@ -270,12 +270,12 @@ if (cmp != 0 || sym == NULL) return NULL; { - boolean traced = FALSE; + bool traced = false; if (SYMBOL_NEXT (sym) != NULL && SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) && mode == SYMBOL_POPDEF) { - SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = FALSE; + SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = false; SYMBOL_TRACED (SYMBOL_NEXT (sym)) = SYMBOL_TRACED (sym); } else @@ -292,12 +292,12 @@ { sym = (symbol *) xmalloc (sizeof (symbol)); SYMBOL_TYPE (sym) = TOKEN_VOID; - SYMBOL_TRACED (sym) = TRUE; + SYMBOL_TRACED (sym) = true; SYMBOL_NAME (sym) = xstrdup (name); - SYMBOL_SHADOWED (sym) = FALSE; - SYMBOL_MACRO_ARGS (sym) = FALSE; - SYMBOL_BLIND_NO_ARGS (sym) = FALSE; - SYMBOL_DELETED (sym) = FALSE; + SYMBOL_SHADOWED (sym) = false; + SYMBOL_MACRO_ARGS (sym) = false; + SYMBOL_BLIND_NO_ARGS (sym) = false; + SYMBOL_DELETED (sym) = false; SYMBOL_PENDING_EXPANSIONS (sym) = 0; SYMBOL_NEXT (sym) = *spp; @@ -325,7 +325,7 @@ `-----------------------------------------------------------------*/ void -hack_all_symbols (hack_symbol *func, const char *data) +hack_all_symbols (hack_symbol *func, void *data) { size_t h; symbol *sym; @@ -339,7 +339,7 @@ for (sym = symtab[h]; sym != NULL; sym = next) { next = SYMBOL_NEXT (sym); - (*func) (sym, data); + func (sym, data); } } } _______________________________________________ M4-patches mailing list M4-patches@gnu.org http://lists.gnu.org/mailman/listinfo/m4-patches