1 /* Concentrate all options use in bison,
2 Copyright 2001, 2002 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
= "yvegdhr:ltknVo: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_s 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')
73 OPTN ("report", required
, 0, 0, 'r')
74 OPTN ("verbose", no
, 0, 0, 'v')
77 OPTN ("trace", no
, &trace_flag
, 0, 1)
79 /* FIXME: semantic parsers will output an `include' of an
80 output file: be sure that the naem included is indeed the name of
81 the output file. */ /* FIXME Should we activate this options ?
83 OPTN ("output", required
, &spec_outfile
, 0, 'o')
84 OPTN ("file-prefix", required
, &spec_file_prefix
, 0, 'b')
85 OPTN ("name-prefix", required
, &spec_name_prefix
, 0, 'p')
88 * Percent and command line declarations.
92 OPTN ("defines", optional
, &defines_flag
, 0, 'd')
94 /* Operation modes. */
95 OPTN ("fixed-output-files", no
, &yacc_flag
, 0, 'y')
96 OPTN ("yacc", no
, &yacc_flag
, 0, 'y')
99 OPTN ("debug", no
, &debug_flag
, 0, 't')
100 OPTN ("locations", no
, &locations_flag
, 0, 1)
101 OPTN ("no-lines", no
, &no_lines_flag
, 0, 'l')
102 OPTN ("no-parser", no
, &no_parser_flag
, 0, 'n')
103 OPTN ("raw", no
, 0, 0, 0)
104 OPTN ("skeleton", required
, 0, 0, 'S')
105 OPTN ("token-table", no
, &token_table_flag
, 0, 'k')
111 /*--------------------------------------------------------.
112 | Create the longoptions structure from the option_table, |
113 | for the getopt file. |
114 `--------------------------------------------------------*/
117 long_option_table_new ()
119 struct option
*res
= NULL
;
124 for (number_options
= 0; option_table
[i
].name
; i
++)
125 if (option_table
[i
].access
== opt_cmd_line
126 || option_table
[i
].access
== opt_both
)
129 res
= XMALLOC (struct option
, number_options
+ 1);
130 for (i
= 0; option_table
[i
].name
; i
++)
131 if (option_table
[i
].access
== opt_cmd_line
132 || option_table
[i
].access
== opt_both
)
134 res
[j
].name
= option_table
[i
].name
;
135 res
[j
].has_arg
= option_table
[i
].has_arg
;
136 /* When a getopt_long option has an associated variable
137 (member FLAG), then it is set of the VAL member value. In
138 other words, we cannot expect getopt_long to store the
139 argument if we also want a short option. */
140 if (res
[j
].has_arg
== optional_argument
)
143 res
[j
].flag
= option_table
[i
].flag
;
144 res
[j
++].val
= option_table
[i
].val
;
146 res
[number_options
].name
= NULL
;
147 res
[number_options
].has_arg
= 0;
148 res
[number_options
].flag
= NULL
;
149 res
[number_options
].val
= 0;