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 Arguments is the policy: `no', `optional', `required'.
35 OptionChar is the value given to the Var if the latter is specified. */
37 #define OPTN(OptionString, Arguments, Var, Token, OptionChar) \
39 (OptionString), (Arguments##_argument), (Var), (Token), (OptionChar) },
41 /* A directive only. */
43 #define DRTV(DirectiveString, Arguments, Var, Token) \
45 (DirectiveString), (Arguments##_argument), (Var), (Token), (0) },
47 /* An option activated both by a directive and an CLI option. */
49 #define BOTH(String, Arguments, Var, Token, OptionChar) \
51 (String), (Arguments##_argument), (Var), (Token), (OptionChar) },
54 const struct option_table_struct option_table
[] =
60 /* Operation modes. */
61 OPTN ("help", no
, 0, 0, 'h')
62 OPTN ("version", no
, 0, 0, 'V')
65 OPTN ("name-prefix", required
, 0, 0, 'p')
66 OPTN ("include", required
, 0, 0, 'I')
69 OPTN ("file-prefix", required
, 0, 0, 'b')
70 OPTN ("output", required
, 0, 0, 'o')
71 OPTN ("output-file", required
, 0, 0, 'o')
72 OPTN ("graph", optional
, 0, 0, 'g')
75 OPTN ("trace", no
, &trace_flag
, 0, 1)
78 * Percent declarations.
81 DRTV ("token", no
, NULL
, tok_token
)
82 DRTV ("term", no
, NULL
, tok_token
)
83 DRTV ("nterm", no
, NULL
, tok_nterm
)
84 DRTV ("type", no
, NULL
, tok_type
)
85 DRTV ("guard", no
, NULL
, tok_guard
)
86 DRTV ("union", no
, NULL
, tok_union
)
87 DRTV ("expect", no
, NULL
, tok_expect
)
88 DRTV ("thong", no
, NULL
, tok_thong
)
89 DRTV ("start", no
, NULL
, tok_start
)
90 DRTV ("left", no
, NULL
, tok_left
)
91 DRTV ("right", no
, NULL
, tok_right
)
92 DRTV ("nonassoc", no
, NULL
, tok_nonassoc
)
93 DRTV ("binary", no
, NULL
, tok_nonassoc
)
94 DRTV ("prec", no
, NULL
, tok_prec
)
95 DRTV ("error-verbose",no
, &error_verbose
, tok_intopt
)
97 /* FIXME: semantic parsers will output an `include' of an
98 output file: be sure that the naem included is indeed the name of
99 the output file. */ /* FIXME Should we activate this options ?
101 BOTH ("output", required
, &spec_outfile
, tok_stropt
, 'o')
102 BOTH ("file-prefix", required
, &spec_file_prefix
, tok_stropt
, 'b')
103 BOTH ("name-prefix", required
, &spec_name_prefix
, tok_stropt
, 'p')
105 DRTV ("define", no
, NULL
, tok_define
)
106 DRTV ("semantic-parser",no
, &semantic_parser
, tok_intopt
)
107 DRTV ("pure-parser", no
, &pure_parser
, tok_intopt
)
110 * Percent and command line declarations.
114 BOTH ("defines", optional
, &defines_flag
, tok_intopt
, 'd')
115 BOTH ("verbose", no
, &verbose_flag
, tok_intopt
, 'v')
117 /* Operation modes. */
118 BOTH ("fixed-output-files", no
, &yacc_flag
, tok_intopt
, 'y')
119 BOTH ("yacc", no
, &yacc_flag
, tok_intopt
, 'y')
122 BOTH ("debug", no
, &debug_flag
, tok_intopt
, 't')
123 BOTH ("locations", no
, &locations_flag
, tok_intopt
, 1)
124 BOTH ("no-lines", no
, &no_lines_flag
, tok_intopt
, 'l')
125 BOTH ("no-parser", no
, &no_parser_flag
, tok_intopt
, 'n')
126 BOTH ("raw", no
, 0, tok_obsolete
, 'r')
127 BOTH ("skeleton", required
, 0, tok_skel
, 'S')
128 BOTH ("token-table", no
, &token_table_flag
, tok_intopt
, 'k')
134 /*--------------------------------------------------------.
135 | Create the longoptions structure from the option_table, |
136 | for the getopt file. |
137 `--------------------------------------------------------*/
140 long_option_table_new ()
142 struct option
*res
= NULL
;
147 for (number_options
= 0; option_table
[i
].name
; i
++)
148 if (option_table
[i
].access
== opt_cmd_line
149 || option_table
[i
].access
== opt_both
)
152 res
= XMALLOC (struct option
, number_options
+ 1);
153 for (i
= 0; option_table
[i
].name
; i
++)
154 if (option_table
[i
].access
== opt_cmd_line
155 || option_table
[i
].access
== opt_both
)
157 /* Copy the struct information in the longoptions. */
158 res
[j
].name
= option_table
[i
].name
;
159 res
[j
].has_arg
= option_table
[i
].has_arg
;
160 /* When an options is declared having 'optional_argument' and
161 a flag is specified to be set, the option is skipped on
162 command line. So we never use a flag when a command line
163 option is declared 'optional_argument. */
164 if (res
[j
].has_arg
== optional_argument
)
167 res
[j
].flag
= option_table
[i
].set_flag
;
168 res
[j
++].val
= option_table
[i
].val
;
170 res
[number_options
].name
= NULL
;
171 res
[number_options
].has_arg
= 0;
172 res
[number_options
].flag
= NULL
;
173 res
[number_options
].val
= 0;