X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/8e55b3aac25caf25d6976a455729aef3f4f20f80..96002de2e149fb4be00764aa29d766c3afe18fee:/src/getargs.c diff --git a/src/getargs.c b/src/getargs.c index 92846b64..9ffa4cf5 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -20,13 +20,13 @@ #include #include "system.h" -#include "revision.h" #include "output.h" #include #include #include #include +#include /* Hack to get to declare getopt with a prototype. */ #if lint && ! defined __GNU_LIBRARY__ @@ -44,6 +44,7 @@ #include "complain.h" #include "files.h" #include "getargs.h" +#include "muscle_tab.h" #include "uniqstr.h" bool debug_flag; @@ -71,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; @@ -245,6 +246,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\ @@ -266,16 +272,18 @@ 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); fputs (_("\ Parser:\n\ -L, --language=LANGUAGE specify the output programming language\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\ @@ -338,7 +346,6 @@ version (void) continue. */ printf (_("bison (GNU Bison) %s"), VERSION); putc ('\n', stdout); - printf ("%s", revision); fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout); putc ('\n', stdout); @@ -359,7 +366,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) { @@ -370,15 +377,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; @@ -399,10 +403,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); } /*----------------------. @@ -412,6 +413,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::" @@ -478,6 +480,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 }, @@ -496,6 +499,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[]) { @@ -505,15 +521,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': @@ -521,11 +544,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': @@ -547,6 +572,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) @@ -624,4 +656,5 @@ getargs (int argc, char *argv[]) } current_file = grammar_file = uniqstr_new (argv[optind]); + MUSCLE_INSERT_C_STRING ("file_name", grammar_file); }