]>
git.saurik.com Git - bison.git/blob - src/getargs.c
   1 /* Parse command line arguments for Bison. 
   3    Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003 
   4    Free Software Foundation, Inc. 
   6    This file is part of Bison, the GNU Compiler Compiler. 
   8    Bison is free software; you can redistribute it and/or modify it 
   9    under the terms of the GNU General Public License as published by 
  10    the Free Software Foundation; either version 2, or (at your option) 
  13    Bison is distributed in the hope that it will be useful, but 
  14    WITHOUT ANY WARRANTY; without even the implied warranty of 
  15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
  16    General Public License for more details. 
  18    You should have received a copy of the GNU General Public License 
  19    along with Bison; see the file COPYING.  If not, write to the Free 
  20    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
  28 /* Hack to get <getopt.h> to declare getopt with a prototype.  */ 
  29 #if lint && ! defined __GNU_LIBRARY__ 
  30 # define __GNU_LIBRARY__ 
  31 # define HACK_FOR___GNU_LIBRARY___PROTOTYPE 1 
  36 #ifdef HACK_FOR___GNU_LIBRARY___PROTOTYPE 
  37 # undef __GNU_LIBRARY__ 
  38 # undef HACK_FOR___GNU_LIBRARY___PROTOTYPE 
  51 int report_flag 
= report_none
; 
  52 bool token_table_flag
; 
  53 bool yacc_flag
; /* for -y */ 
  55 int trace_flag 
= trace_none
; 
  57 bool nondeterministic_parser 
= false; 
  58 bool glr_parser 
= false; 
  59 bool pure_parser 
= false; 
  61 const char *skeleton 
= NULL
; 
  62 const char *include 
= NULL
; 
  64 extern char *program_name
; 
  67 /*---------------------. 
  68 | --trace's handling.  | 
  69 `---------------------*/ 
  71 static const char * const trace_args
[] = 
  73   /* In a series of synonyms, present the most meaningful first, so 
  74      that argmatch_valid be more readable.  */ 
  76   "scan       - grammar scanner traces", 
  77   "parse      - grammar parser traces", 
  78   "automaton  - contruction of the automaton", 
  79   "bitsets    - use of bitsets", 
  80   "grammar    - reading, reducing of the grammar", 
  81   "resource   - memory consumption (where available)", 
  82   "sets       - grammar sets: firsts, nullable etc.", 
  83   "tools      - m4 invocation and preserve the temporary file", 
  84   "skeleton   - skeleton postprocessing", 
  85   "time       - time consumption", 
  86   "all        - all of the above", 
  90 static const int trace_types
[] = 
 108 trace_argmatch (char *args
) 
 110   verify (trace_constraint
, ARGMATCH_CONSTRAINT (trace_args
, trace_types
)); 
 113       args 
= strtok (args
, ","); 
 116           int trace 
= XARGMATCH ("--trace", args
, 
 117                                  trace_args
, trace_types
); 
 118           if (trace 
== trace_none
) 
 119             trace_flag 
= trace_none
; 
 123       while ((args 
= strtok (NULL
, ","))); 
 126     trace_flag 
= trace_all
; 
 130 /*----------------------. 
 131 | --report's handling.  | 
 132 `----------------------*/ 
 134 static const char * const report_args
[] = 
 136   /* In a series of synonyms, present the most meaningful first, so 
 137      that argmatch_valid be more readable.  */ 
 140   "itemset", "itemsets", 
 141   "lookahead", "lookaheads", 
 147 static const int report_types
[] = 
 150   report_states
, report_states
, 
 151   report_states 
| report_itemsets
, report_states 
| report_itemsets
, 
 152   report_states 
| report_lookaheads
, report_states 
| report_lookaheads
, 
 153   report_states 
| report_solved_conflicts
, 
 159 report_argmatch (char *args
) 
 161   verify (report_constraint
, ARGMATCH_CONSTRAINT (report_args
, report_types
)); 
 162   args 
= strtok (args
, ","); 
 165       int report 
= XARGMATCH ("--report", args
, 
 166                               report_args
, report_types
); 
 167       if (report 
== report_none
) 
 168         report_flag 
= report_none
; 
 170         report_flag 
|= report
; 
 172   while ((args 
= strtok (NULL
, ","))); 
 176 /*-------------------------------------------. 
 177 | Display the help message and exit STATUS.  | 
 178 `-------------------------------------------*/ 
 180 static void usage (int) ATTRIBUTE_NORETURN
; 
 186     fprintf (stderr
, _("Try `%s --help' for more information.\n"), 
 190       /* Some efforts were made to ease the translators' task, please 
 193 GNU bison generates parsers for LALR(1) grammars.\n"), stdout
); 
 196       fprintf (stdout
, _("\ 
 197 Usage: %s [OPTION]... FILE\n"), program_name
); 
 201 If a long option shows an argument as mandatory, then it is mandatory\n\ 
 202 for the equivalent short option also.  Similarly for optional arguments.\n"), 
 208   -h, --help      display this help and exit\n\ 
 209   -V, --version   output version information and exit\n\ 
 210   -y, --yacc      emulate POSIX yacc\n"), stdout
); 
 215   -S, --skeleton=FILE        specify the skeleton to use\n\ 
 216   -t, --debug                instrument the parser for debugging\n\ 
 217       --locations            enable locations computation\n\ 
 218   -p, --name-prefix=PREFIX   prepend PREFIX to the external symbols\n\ 
 219   -l, --no-lines             don't generate `#line' directives\n\ 
 220   -n, --no-parser            generate the tables only\n\ 
 221   -k, --token-table          include a table of token names\n\ 
 227   -d, --defines              also produce a header file\n\ 
 228   -r, --report=THINGS        also produce details on the automaton\n\ 
 229   -v, --verbose              same as `--report=state'\n\ 
 230   -b, --file-prefix=PREFIX   specify a PREFIX for output files\n\ 
 231   -o, --output=FILE          leave output to FILE\n\ 
 232   -g, --graph                also produce a VCG description of the automaton\n\ 
 237 THINGS is a list of comma separated words that can include:\n\ 
 238   `state'        describe the states\n\ 
 239   `itemset'      complete the core item sets with their closure\n\ 
 240   `lookahead'    explicitly associate lookaheads to items\n\ 
 241   `solved'       describe shift/reduce conflicts solving\n\ 
 242   `all'          include all the above information\n\ 
 243   `none'         disable the report\n\ 
 248 Report bugs to <bug-bison@gnu.org>.\n"), stdout
); 
 255 /*------------------------------. 
 256 | Display the version message.  | 
 257 `------------------------------*/ 
 262   /* Some efforts were made to ease the translators' task, please 
 264   printf (_("bison (GNU Bison) %s"), VERSION
); 
 266   fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout
); 
 270            _("Copyright (C) %d Free Software Foundation, Inc.\n"), 2003); 
 273 This is free software; see the source for copying conditions.  There is NO\n\ 
 274 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 
 280 /*----------------------. 
 281 | Process the options.  | 
 282 `----------------------*/ 
 284 /* Shorts options.  */ 
 285 const char *short_options 
= "yvegdhr:ltknVo:b:p:S:T::"; 
 287 /* Values for long options that do not have single-letter equivalents.  */ 
 290   LOCATIONS_OPTION 
= CHAR_MAX 
+ 1 
 293 static struct option 
const long_options
[] = 
 295   /* Operation modes. */ 
 296   { "help",          no_argument
,               0,   'h' }, 
 297   { "version",       no_argument
,               0,   'V' }, 
 300   { "name-prefix",   required_argument
,   0,   'p' }, 
 301   { "include",       required_argument
,   0,   'I' }, 
 304   { "file-prefix", required_argument
,   0,   'b' }, 
 305   { "output",      required_argument
,   0,   'o' }, 
 306   { "output-file", required_argument
,   0,   'o' }, 
 307   { "graph",       optional_argument
,   0,   'g' }, 
 308   { "report",      required_argument
,   0,   'r' }, 
 309   { "verbose",     no_argument
,         0,   'v' }, 
 312   { "trace",         optional_argument
,   0,     'T' }, 
 315   { "defines",     optional_argument
,   0,   'd' }, 
 317   /* Operation modes.  */ 
 318   { "fixed-output-files", no_argument
,  0,   'y' }, 
 319   { "yacc",               no_argument
,  0,   'y' }, 
 322   { "debug",          no_argument
,               0,   't' }, 
 323   { "locations",      no_argument
,               0, LOCATIONS_OPTION 
}, 
 324   { "no-lines",       no_argument
,               0,   'l' }, 
 325   { "no-parser",      no_argument
,               0,   'n' }, 
 326   { "raw",            no_argument
,               0,     0 }, 
 327   { "skeleton",       required_argument
,         0,   'S' }, 
 328   { "token-table",    no_argument
,               0,   'k' }, 
 333 /* Under DOS, there is no difference on the case.  This can be 
 334    troublesome when looking for `.tab' etc.  */ 
 336 # define AS_FILE_NAME(File) (strlwr (File), (File)) 
 338 # define AS_FILE_NAME(File) (File) 
 342 getargs (int argc
, char *argv
[]) 
 346   while ((c 
= getopt_long (argc
, argv
, short_options
, long_options
, NULL
)) 
 351         /* Certain long options cause getopt_long to return 0.  */ 
 359         usage (EXIT_SUCCESS
); 
 366         /* Here, the -g and --graph=FILE options are differentiated.  */ 
 369           spec_graph_file 
= AS_FILE_NAME (optarg
); 
 373         report_flag 
|= report_states
; 
 377         skeleton 
= AS_FILE_NAME (optarg
); 
 381         include 
= AS_FILE_NAME (optarg
); 
 385         /* Here, the -d and --defines options are differentiated.  */ 
 388           spec_defines_file 
= AS_FILE_NAME (optarg
); 
 392         no_lines_flag 
= true; 
 395       case LOCATIONS_OPTION
: 
 396         locations_flag 
= true; 
 400         token_table_flag 
= true; 
 404         no_parser_flag 
= true; 
 412         spec_outfile 
= AS_FILE_NAME (optarg
); 
 416         spec_file_prefix 
= AS_FILE_NAME (optarg
); 
 420         spec_name_prefix 
= optarg
; 
 424         report_argmatch (optarg
); 
 428         trace_argmatch (optarg
); 
 432         usage (EXIT_FAILURE
); 
 435   if (argc 
- optind 
!= 1) 
 437       if (argc 
- optind 
< 1) 
 438         error (0, 0, _("missing operand after `%s'"), argv
[argc 
- 1]); 
 440         error (0, 0, _("extra operand `%s'"), argv
[optind 
+ 1]); 
 441       usage (EXIT_FAILURE
); 
 444   current_file 
= grammar_file 
= uniqstr_new (argv
[optind
]);