65
65
struct macro_definition
67
67
struct macro_definition *next;
68
int code; /* D, U or t */
68
int code; /* D, U, s, t, or '\1' */
71
71
typedef struct macro_definition macro_definition;
205
205
printf ("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
208
if (close_stream (stdout) != 0)
209
M4ERROR ((EXIT_FAILURE, errno, "write error"));
260
257
where we try to continue execution in the meantime. */
260
/* Process a command line file NAME, and return true only if it was
263
process_file (const char *name)
266
if (strcmp (name, "-") == 0)
268
/* If stdin is a terminal, we want to allow 'm4 - file -'
269
to read input from stdin twice, like GNU cat. Besides,
270
there is no point closing stdin before wrapped text, to
271
minimize bugs in syscmd called from wrapped text. */
272
push_file (stdin, "stdin", false);
278
FILE *fp = m4_path_search (name, &full_name);
281
error (0, errno, "%s", name);
282
/* Set the status to EXIT_FAILURE, even though we
283
continue to process files after a missing file. */
284
retcode = EXIT_FAILURE;
287
push_file (fp, full_name, true);
294
/* POSIX requires only -D, -U, and -s; and says that the first two
295
must be recognized when interspersed with file names. Traditional
296
behavior also handles -s between files. Starting OPTSTRING with
297
'-' forces getopt_long to hand back file names as arguments to opt
298
'\1', rather than reordering the command line. */
263
299
#ifdef ENABLE_CHANGEWORD
264
#define OPTSTRING "B:D:EF:GH:I:L:N:PQR:S:T:U:W:d::eil:o:st:"
300
#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:W:d::eil:o:st:"
266
#define OPTSTRING "B:D:EF:GH:I:L:N:PQR:S:T:U:d::eil:o:st:"
302
#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:d::eil:o:st:"
272
308
macro_definition *head; /* head of deferred argument list */
273
309
macro_definition *tail;
274
macro_definition *new;
310
macro_definition *defn;
275
311
int optchar; /* option character */
277
313
macro_definition *defines;
279
boolean read_stdin = FALSE;
280
boolean interactive = FALSE;
314
bool read_stdin = false;
315
bool interactive = false;
316
bool seen_file = false;
317
const char *debugfile = NULL;
281
318
const char *frozen_file_to_read = NULL;
282
319
const char *frozen_file_to_write = NULL;
284
321
program_name = argv[0];
285
322
retcode = EXIT_SUCCESS;
323
atexit (close_stdout);
295
333
head = tail = NULL;
297
while (optchar = getopt_long (argc, (char **) argv, OPTSTRING,
335
while ((optchar = getopt_long (argc, (char **) argv, OPTSTRING,
336
long_options, NULL)) != -1)
409
447
or later is more widely established, as such a warning
410
448
would interfere with all earlier versions of autoconf. */
411
449
case DEBUGFILE_OPTION:
412
if (!debug_set_output (optarg))
413
error (0, errno, "%s", optarg);
450
/* Don't call debug_set_output here, as it has side effects. */
420
454
case VERSION_OPTION:
421
printf ("%s\n", PACKAGE_STRING);
455
printf ("%s\n", PACKAGE_STRING);
423
457
Copyright (C) 2006 Free Software Foundation, Inc.\n\
424
458
This is free software; see the source for copying conditions. There is NO\n\
425
459
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
427
461
Written by Rene' Seindal.\n\
430
if (close_stream (stdout) != 0)
431
M4ERROR ((EXIT_FAILURE, errno, "write error"));
435
466
case HELP_OPTION:
442
/* Do the basic initialisations. */
473
/* Do the basic initializations. */
474
if (debugfile && !debug_set_output (debugfile))
475
M4ERROR ((0, errno, "cannot set debug file `%s'", debugfile));
487
/* Interactive mode means unbuffered output, and interrupts ignored. */
491
signal (SIGINT, SIG_IGN);
492
setbuf (stdout, (char *) NULL);
454
495
/* Handle deferred command line macro definitions. Must come after
455
initialisation of the symbol table. */
496
initialization of the symbol table. */
457
498
while (defines != NULL)
459
500
macro_definition *next;
463
503
switch (defines->code)
466
macro_value = strchr (defines->macro, '=');
467
if (macro_value == NULL)
470
*macro_value++ = '\0';
471
define_user_macro (defines->macro, macro_value, SYMBOL_INSERT);
507
/* defines->arg is read-only, so we need a copy. */
508
char *macro_name = xstrdup (defines->arg);
509
char *macro_value = strchr (macro_name, '=');
511
*macro_value++ = '\0';
512
define_user_macro (macro_name, macro_value, SYMBOL_INSERT);
475
lookup_symbol (defines->macro, SYMBOL_DELETE);
518
lookup_symbol (defines->arg, SYMBOL_DELETE);
479
sym = lookup_symbol (defines->macro, SYMBOL_INSERT);
480
SYMBOL_TRACED (sym) = TRUE;
522
sym = lookup_symbol (defines->arg, SYMBOL_INSERT);
523
SYMBOL_TRACED (sym) = true;
532
if (process_file (defines->arg))
494
/* Interactive mode means unbuffered output, and interrupts ignored. */
498
signal (SIGINT, SIG_IGN);
499
setbuf (stdout, (char *) NULL);
502
/* Handle the various input files. Each file is pushed on the input,
547
/* Handle remaining input files. Each file is pushed on the input,
503
548
and the input read. Wrapup text is handled separately later. */
507
/* No point closing stdin until after wrapped text is
509
push_file (stdin, "stdin", FALSE);
550
if (optind == argc && !seen_file)
551
read_stdin = process_file ("-");
514
553
for (; optind < argc; optind++)
516
if (strcmp (argv[optind], "-") == 0)
518
/* If stdin is a terminal, we want to allow 'm4 - file -'
519
to read input from stdin twice, like GNU cat. Besides,
520
there is no point closing stdin before wrapped text, to
521
minimize bugs in syscmd called from wrapped text. */
522
push_file (stdin, "stdin", FALSE);
528
fp = path_search (argv[optind], &name);
531
error (0, errno, "%s", argv[optind]);
532
/* Set the status to EXIT_FAILURE, even though we
533
continue to process files after a missing file. */
534
retcode = EXIT_FAILURE;
537
push_file (fp, name, TRUE);
538
free ((char *) name);
554
if (process_file (defines->arg))
544
557
/* Now handle wrapup text. */