CVSROOT: /sources/m4 Module name: m4 Changes by: Eric Blake <ericb> 07/08/07 20:59:23
Index: src/main.c =================================================================== RCS file: /sources/m4/m4/src/main.c,v retrieving revision 1.114 retrieving revision 1.115 diff -u -b -r1.114 -r1.115 --- src/main.c 7 Aug 2007 03:15:31 -0000 1.114 +++ src/main.c 7 Aug 2007 20:59:23 -0000 1.115 @@ -216,12 +216,37 @@ VERSION_OPTION /* no short opt */ }; +/* Use OPT_IDX to decide whether to return either a short option + string "-C", or a long option string derived from LONG_OPTIONS. + OPT_IDX is -1 if the short option C was used; otherwise it is an + index into LONG_OPTIONS, which should have a name preceded by two + '-' characters. */ +#define OPT_STR(opt_idx, c, long_options) \ + ((opt_idx) < 0 \ + ? short_opt_str (c) \ + : LONG_OPT_STR (opt_idx, long_options)) + +/* Likewise, but assume OPT_IDX is nonnegative. */ +#define LONG_OPT_STR(opt_idx, long_options) ((long_options)[opt_idx].name - 2) + +/* Given the byte, C, return the string "-C" in static storage. */ +static inline char * +short_opt_str (char c) +{ + static char opt_str_storage[3] = {'-', 0, 0}; + opt_str_storage[1] = c; + return opt_str_storage; +} + +/* Define an option string that will be used with OPT_STR or LONG_OPT_STR. */ +#define OPT_STR_INIT(name) ("--" name + 2) + /* Decode options and launch execution. */ static const struct option long_options[] = { {"batch", no_argument, NULL, 'b'}, {"debug", optional_argument, NULL, 'd'}, - {"debuglen", required_argument, NULL, 'l'}, + {OPT_STR_INIT ("debuglen"), required_argument, NULL, 'l'}, {"debugmode", optional_argument, NULL, 'd'}, {"define", required_argument, NULL, 'D'}, {"discard-comments", no_argument, NULL, 'c'}, @@ -232,7 +257,7 @@ {"interactive", no_argument, NULL, 'i'}, {"load-module", required_argument, NULL, 'm'}, {"module-directory", required_argument, NULL, 'M'}, - {"nesting-limit", required_argument, NULL, 'L'}, + {OPT_STR_INIT ("nesting-limit"), required_argument, NULL, 'L'}, {"posix", no_argument, NULL, 'G'}, {"prefix-builtins", no_argument, NULL, 'P'}, {"pushdef", required_argument, NULL, 'p'}, @@ -247,7 +272,7 @@ {"undefine", required_argument, NULL, 'U'}, {"warnings", no_argument, NULL, 'W'}, - {"arglength", required_argument, NULL, ARGLENGTH_OPTION}, + {OPT_STR_INIT ("arglength"), required_argument, NULL, ARGLENGTH_OPTION}, {"debugfile", required_argument, NULL, DEBUGFILE_OPTION}, {"diversions", required_argument, NULL, DIVERSIONS_OPTION}, {"hashsize", required_argument, NULL, HASHSIZE_OPTION}, @@ -282,17 +307,17 @@ INTERACTIVE_NO /* -b specified last */ }; -/* Convert OPT to size_t, reporting an error using MSGID if it does - not fit. */ +/* Convert OPT to size_t, reporting an error using long option index + OI or short option character OPTCHAR if it does not fit. */ static size_t -size_opt (char const *opt, char const *msgid) +size_opt (char const *opt, int oi, int optchar) { unsigned long int size; strtol_error status = xstrtoul (opt, NULL, 10, &size, "kKmMgGtTPEZY0"); if (SIZE_MAX < size && status == LONGINT_OK) status = LONGINT_OVERFLOW; if (status != LONGINT_OK) - STRTOL_FATAL_ERROR (opt, _(msgid), status); + STRTOL_FATAL_ERROR (OPT_STR (oi, optchar, long_options), opt, status); return size; } @@ -326,7 +351,6 @@ deferred *head = NULL; /* head of deferred argument list */ deferred *tail = NULL; deferred *defn; - int optchar; /* option character */ size_t size; /* for parsing numeric option arguments */ bool import_environment = false; /* true to import environment */ @@ -368,8 +392,14 @@ /* First, we decode the arguments, to size up tables and stuff. Avoid lasting side effects; for example 'm4 --debugfile=oops --help' must not create the file `oops'. */ - while ((optchar = getopt_long (argc, (char **) argv, OPTSTRING, - long_options, NULL)) != -1) + while (1) + { + int oi = -1; + int optchar = getopt_long (argc, (char **) argv, OPTSTRING, + long_options, &oi); + if (optchar == -1) + break; + switch (optchar) { default: @@ -476,7 +506,7 @@ break; case 'L': - size = size_opt (optarg, N_("nesting limit")); + size = size_opt (optarg, oi, optchar); m4_set_nesting_limit_opt (context, size); break; @@ -552,8 +582,7 @@ "--arglength", "--debuglen"); /* fall through */ case 'l': - size = size_opt (optarg, - N_("debug argument length")); + size = size_opt (optarg, oi, optchar); m4_set_max_debug_arg_length_opt (context, size); break; @@ -590,6 +619,7 @@ usage (EXIT_SUCCESS); break; } + } /* Interactive if specified, or if no input files and stdin and stderr are terminals, to match sh behavior. Interactive mode