X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ed4d67dcbe00ca687a6de988aada4ab90a6e03fa..44c124a3896b149561b3b9cee411b4a479ab04d7:/src/getargs.c diff --git a/src/getargs.c b/src/getargs.c index c9fc9bfc..bb060c55 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -26,6 +26,7 @@ #include #include #include +#include /* Hack to get to declare getopt with a prototype. */ #if lint && ! defined __GNU_LIBRARY__ @@ -43,6 +44,7 @@ #include "complain.h" #include "files.h" #include "getargs.h" +#include "muscle_tab.h" #include "uniqstr.h" bool debug_flag; @@ -70,9 +72,9 @@ static struct bison_language const valid_languages[] = { { "", "", "", "", false } }; -static int skeleton_prio = 2; +int skeleton_prio = default_prio; const char *skeleton = NULL; -static int language_prio = 2; +int language_prio = default_prio; struct bison_language const *language = &valid_languages[0]; const char *include = NULL; @@ -174,6 +176,7 @@ static const char * const trace_args[] = "grammar - reading, reducing the grammar", "resource - memory consumption (where available)", "sets - grammar sets: firsts, nullable etc.", + "muscles - m4 definitions passed to the skeleton", "tools - m4 invocation", "m4 - m4 traces", "skeleton - skeleton postprocessing", @@ -192,6 +195,7 @@ static const int trace_types[] = trace_grammar, trace_resource, trace_sets, + trace_muscles, trace_tools, trace_m4, trace_skeleton, @@ -212,7 +216,7 @@ static const char * const warnings_args[] = that argmatch_valid be more readable. */ "none - no warnings", "midrule-values - unset or unused midrule values", - "yacc - incompatibilities with POSIX YACC", + "yacc - incompatibilities with POSIX Yacc", "all - all of the above", "error - warnings are errors", 0 @@ -244,6 +248,11 @@ usage (int status) program_name); else { + /* For ../build-aux/cross-options.pl to work, use the format: + ^ -S, --long[=ARGS] (whitespace) + A --long option is required. + Otherwise, add exceptions to ../build-aux/cross-options.pl. */ + printf (_("Usage: %s [OPTION]... FILE\n"), program_name); fputs (_("\ Generate LALR(1) and GLR parsers.\n\ @@ -265,7 +274,7 @@ Operation modes:\n\ --print-localedir output directory containing locale-dependent data\n\ --print-datadir output directory containing skeletons and XSLT\n\ -y, --yacc emulate POSIX Yacc\n\ - -W, --warnings=[CATEGORY] report the warnings falling in CATEGORY\n\ + -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\ \n\ "), stdout); @@ -275,7 +284,8 @@ Parser:\n\ (this is an experimental feature)\n\ -S, --skeleton=FILE specify the skeleton to use\n\ -t, --debug instrument the parser for debugging\n\ - --locations enable locations computation\n\ + --locations enable location support\n\ + -D, --define=NAME[=VALUE] same as `%define NAME \"VALUE\"'\n\ -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\ -l, --no-lines don't generate `#line' directives\n\ -k, --token-table include a table of token names\n\ @@ -302,7 +312,7 @@ Output:\n\ fputs (_("\ Warning categories include:\n\ `midrule-values' unset or unused midrule values\n\ - `yacc' incompatibilities with POSIX YACC\n\ + `yacc' incompatibilities with POSIX Yacc\n\ `all' all the warnings\n\ `no-CATEGORY' turn off warnings in CATEGORY\n\ `none' turn off all the warnings\n\ @@ -358,7 +368,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ `--------------------------------------*/ void -skeleton_arg (char const *arg, int prio, location const *loc) +skeleton_arg (char const *arg, int prio, location loc) { if (prio < skeleton_prio) { @@ -369,15 +379,12 @@ skeleton_arg (char const *arg, int prio, location const *loc) { char const *msg = _("multiple skeleton declarations are invalid"); - if (loc) - complain_at (*loc, msg); - else - complain (msg); + complain_at (loc, msg); } } void -language_argmatch (char const *arg, int prio, location const *loc) +language_argmatch (char const *arg, int prio, location loc) { char const *msg; @@ -398,10 +405,7 @@ language_argmatch (char const *arg, int prio, location const *loc) else return; - if (loc) - complain_at (*loc, msg, arg); - else - complain (msg, arg); + complain_at (loc, msg, arg); } /*----------------------. @@ -411,6 +415,7 @@ language_argmatch (char const *arg, int prio, location const *loc) /* Shorts options. Should be computed from long_options. */ static char const short_options[] = + "D:" "L:" "S:" "T::" @@ -477,6 +482,7 @@ static struct option const long_options[] = /* Parser. */ { "debug", no_argument, 0, 't' }, + { "define", required_argument, 0, 'D' }, { "locations", no_argument, 0, LOCATIONS_OPTION }, { "no-lines", no_argument, 0, 'l' }, { "raw", no_argument, 0, 0 }, @@ -495,6 +501,19 @@ static struct option const long_options[] = # define AS_FILE_NAME(File) (File) #endif +/* Build a location for the current command line argument. */ +static +location +command_line_location (void) +{ + location res; + /* "" is used in GCC's messages about -D. */ + boundary_set (&res.start, uniqstr_new (""), optind, -1); + res.end = res.start; + return res; +} + + void getargs (int argc, char *argv[]) { @@ -504,15 +523,22 @@ getargs (int argc, char *argv[]) != -1) switch (c) { + /* ASCII Sorting for short options (i.e., upper case then + lower case), and then long-only options. */ + case 0: /* Certain long options cause getopt_long to return 0. */ break; - case 'd': - /* Here, the -d and --defines options are differentiated. */ - defines_flag = true; - if (optarg) - spec_defines_file = xstrdup (AS_FILE_NAME (optarg)); + case 'D': /* -DNAME[=VALUE]. */ + { + char* name = optarg; + char* value = strchr (optarg, '='); + if (value) + *value++ = 0; + muscle_percent_define_insert (name, command_line_location (), + value ? value : ""); + } break; case 'I': @@ -520,11 +546,13 @@ getargs (int argc, char *argv[]) break; case 'L': - language_argmatch (optarg, 0, NULL); + language_argmatch (optarg, command_line_prio, + command_line_location ()); break; case 'S': - skeleton_arg (AS_FILE_NAME (optarg), 0, NULL); + skeleton_arg (AS_FILE_NAME (optarg), command_line_prio, + command_line_location ()); break; case 'T': @@ -546,6 +574,13 @@ getargs (int argc, char *argv[]) spec_file_prefix = AS_FILE_NAME (optarg); break; + case 'd': + /* Here, the -d and --defines options are differentiated. */ + defines_flag = true; + if (optarg) + spec_defines_file = xstrdup (AS_FILE_NAME (optarg)); + break; + case 'g': graph_flag = true; if (optarg) @@ -623,4 +658,5 @@ getargs (int argc, char *argv[]) } current_file = grammar_file = uniqstr_new (argv[optind]); + MUSCLE_INSERT_C_STRING ("file_name", grammar_file); }