1 /* Concentrate all options use in bison,
2 Copyright 2001 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
31 const char *shortopts
= "yvegdhrltknVo:b:p:S:";
34 struct option
*longopts
= NULL
;
36 struct percent_table_struct
*percent_table
= NULL
;
39 Arguments is the policy: `no', `optional', `required'.
40 OptionChar is the value given to the Var if the latter is specified. */
42 #define OPTN(OptionString, Arguments, Var, Token, OptionChar) \
44 (OptionString), (Arguments##_argument), (Var), (Token), (OptionChar) },
46 /* A directive only. */
48 #define DRTV(DirectiveString, Arguments, Var, Token) \
50 (DirectiveString), (Arguments##_argument), (Var), (Token), (0) },
52 /* An option activated both by a directive and an CLI option. */
54 #define BOTH(String, Arguments, Var, Token, OptionChar) \
56 (String), (Arguments##_argument), (Var), (Token), (OptionChar) },
59 const struct option_table_struct option_table
[] =
65 /* Operation modes. */
66 OPTN ("help", no
, 0, 0, 'h')
67 OPTN ("version", no
, 0, 0, 'V')
70 OPTN ("name-prefix", required
, 0, 0, 'p')
71 OPTN ("include", required
, 0, 0, 'I')
74 OPTN ("file-prefix", required
, 0, 0, 'b')
75 OPTN ("output", required
, 0, 0, 'o')
76 OPTN ("output-file", required
, 0, 0, 'o')
77 OPTN ("graph", optional
, 0, 0, 'g')
80 OPTN ("trace", no
, &trace_flag
, 0, 1)
83 * Percent declarations.
86 DRTV ("token", no
, NULL
, tok_token
)
87 DRTV ("term", no
, NULL
, tok_token
)
88 DRTV ("nterm", no
, NULL
, tok_nterm
)
89 DRTV ("type", no
, NULL
, tok_type
)
90 DRTV ("guard", no
, NULL
, tok_guard
)
91 DRTV ("union", no
, NULL
, tok_union
)
92 DRTV ("expect", no
, NULL
, tok_expect
)
93 DRTV ("thong", no
, NULL
, tok_thong
)
94 DRTV ("start", no
, NULL
, tok_start
)
95 DRTV ("left", no
, NULL
, tok_left
)
96 DRTV ("right", no
, NULL
, tok_right
)
97 DRTV ("nonassoc", no
, NULL
, tok_nonassoc
)
98 DRTV ("binary", no
, NULL
, tok_nonassoc
)
99 DRTV ("prec", no
, NULL
, tok_prec
)
100 DRTV ("error-verbose",no
, &error_verbose
, tok_intopt
)
102 /* FIXME: semantic parsers will output an `include' of an
103 output file: be sure that the naem included is indeed the name of
104 the output file. */ /* FIXME Should we activate this options ?
106 BOTH ("output", required
, &spec_outfile
, tok_stropt
, 'o')
107 BOTH ("file-prefix", required
, &spec_file_prefix
, tok_stropt
, 'b')
108 BOTH ("name-prefix", required
, &spec_name_prefix
, tok_stropt
, 'p')
110 DRTV ("define", no
, NULL
, tok_define
)
111 DRTV ("semantic-parser",no
, &semantic_parser
, tok_intopt
)
112 DRTV ("pure-parser", no
, &pure_parser
, tok_intopt
)
115 * Percent and command line declarations.
119 BOTH ("defines", optional
, &defines_flag
, tok_intopt
, 'd')
120 BOTH ("verbose", no
, &verbose_flag
, tok_intopt
, 'v')
122 /* Operation modes. */
123 BOTH ("fixed-output-files", no
, &yacc_flag
, tok_intopt
, 'y')
124 BOTH ("yacc", no
, &yacc_flag
, tok_intopt
, 'y')
127 BOTH ("debug", no
, &debug_flag
, tok_intopt
, 't')
128 BOTH ("locations", no
, &locations_flag
, tok_intopt
, 1)
129 BOTH ("no-lines", no
, &no_lines_flag
, tok_intopt
, 'l')
130 BOTH ("no-parser", no
, &no_parser_flag
, tok_intopt
, 'n')
131 BOTH ("raw", no
, 0, tok_obsolete
, 'r')
132 BOTH ("skeleton", required
, 0, tok_skel
, 'S')
133 BOTH ("token-table", no
, &token_table_flag
, tok_intopt
, 'k')
138 /*--------------------------------------------------------.
139 | Create the longoptions structure from the option_table, |
140 | for the getopt file. |
141 `--------------------------------------------------------*/
143 create_long_option_table ()
149 for (number_options
= 0; option_table
[i
].name
; i
++)
150 if (option_table
[i
].access
== opt_cmd_line
151 || option_table
[i
].access
== opt_both
)
154 longopts
= XMALLOC (struct option
, number_options
+ 1);
155 for (i
= 0; option_table
[i
].name
; i
++)
156 if (option_table
[i
].access
== opt_cmd_line
157 || option_table
[i
].access
== opt_both
)
159 /* Copy the struct information in the longoptions. */
160 longopts
[j
].name
= option_table
[i
].name
;
161 longopts
[j
].has_arg
= option_table
[i
].has_arg
;
162 /* When an options is declared having 'optional_argument' and
163 a flag is specified to be set, the option is skipped on
164 command line. So we never use a flag when a command line
165 option is declared 'optional_argument. */
166 if (longopts
[j
].has_arg
== optional_argument
)
167 longopts
[j
].flag
= NULL
;
169 longopts
[j
].flag
= option_table
[i
].set_flag
;
170 longopts
[j
++].val
= option_table
[i
].val
;
172 longopts
[number_options
].name
= NULL
;
173 longopts
[number_options
].has_arg
= 0;
174 longopts
[number_options
].flag
= NULL
;
175 longopts
[number_options
].val
= 0;