]> git.saurik.com Git - bison.git/blob - src/options.c
More.
[bison.git] / src / options.c
1 /* Concentrate all options use in bison,
2 Copyright 2001, 2002 Free Software Foundation, Inc.
3
4 This file is part of Bison, the GNU Compiler Compiler.
5
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)
9 any later version.
10
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.
15
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. */
20
21 #include "system.h"
22 #include "getopt.h"
23 #include "files.h"
24 #include "getargs.h"
25 #include "symtab.h"
26 #include "gram.h"
27 #include "lex.h"
28 #include "output.h"
29 #include "options.h"
30
31 /* Shorts options. */
32 const char *shortopts = "yvegdhrltknVo:b:p:S:";
33
34 /* A CLI option only.
35 Arguments is the policy: `no', `optional', `required'.
36 OptionChar is the value given to the Var if the latter is specified. */
37 #undef OPTN
38 #define OPTN(OptionString, Arguments, Var, Token, OptionChar) \
39 { opt_cmd_line, \
40 (OptionString), (Arguments##_argument), (Var), (Token), (OptionChar) },
41
42 /* A directive only. */
43 #undef DRTV
44 #define DRTV(DirectiveString, Arguments, Var, Token) \
45 { opt_percent, \
46 (DirectiveString), (Arguments##_argument), (Var), (Token), (0) },
47
48 /* An option activated both by a directive and an CLI option. */
49 #undef BOTH
50 #define BOTH(String, Arguments, Var, Token, OptionChar) \
51 { opt_both, \
52 (String), (Arguments##_argument), (Var), (Token), (OptionChar) },
53
54
55 const struct option_table_struct option_table[] =
56 {
57 /*
58 * Command line.
59 */
60
61 /* Operation modes. */
62 OPTN ("help", no, 0, 0, 'h')
63 OPTN ("version", no, 0, 0, 'V')
64
65 /* Parser. */
66 OPTN ("name-prefix", required, 0, 0, 'p')
67 OPTN ("include", required, 0, 0, 'I')
68
69 /* Output. */
70 OPTN ("file-prefix", required, 0, 0, 'b')
71 OPTN ("output", required, 0, 0, 'o')
72 OPTN ("output-file", required, 0, 0, 'o')
73 OPTN ("graph", optional, 0, 0, 'g')
74
75 /* Hidden. */
76 OPTN ("trace", no, &trace_flag, 0, 1)
77
78 /*
79 * Percent declarations.
80 */
81
82 DRTV ("token", no, NULL, tok_token)
83 DRTV ("term", no, NULL, tok_token)
84 DRTV ("nterm", no, NULL, tok_nterm)
85 DRTV ("type", no, NULL, tok_type)
86 DRTV ("guard", no, NULL, tok_guard)
87 DRTV ("union", no, NULL, tok_union)
88 DRTV ("expect", no, NULL, tok_expect)
89 DRTV ("thong", no, NULL, tok_thong)
90 DRTV ("start", no, NULL, tok_start)
91 DRTV ("left", no, NULL, tok_left)
92 DRTV ("right", no, NULL, tok_right)
93 DRTV ("nonassoc", no, NULL, tok_nonassoc)
94 DRTV ("binary", no, NULL, tok_nonassoc)
95 DRTV ("prec", no, NULL, tok_prec)
96 DRTV ("error-verbose",no, &error_verbose, tok_intopt)
97
98 /* FIXME: semantic parsers will output an `include' of an
99 output file: be sure that the naem included is indeed the name of
100 the output file. */ /* FIXME Should we activate this options ?
101 */
102 BOTH ("output", required, &spec_outfile, tok_stropt, 'o')
103 BOTH ("file-prefix", required, &spec_file_prefix, tok_stropt, 'b')
104 BOTH ("name-prefix", required, &spec_name_prefix, tok_stropt, 'p')
105
106 DRTV ("define", no, NULL, tok_define)
107 DRTV ("semantic-parser",no, &semantic_parser, tok_intopt)
108 DRTV ("pure-parser", no, &pure_parser, tok_intopt)
109
110 /*
111 * Percent and command line declarations.
112 */
113
114 /* Output. */
115 BOTH ("defines", optional, &defines_flag, tok_intopt, 'd')
116 BOTH ("verbose", no, &verbose_flag, tok_intopt, 'v')
117
118 /* Operation modes. */
119 BOTH ("fixed-output-files", no, &yacc_flag, tok_intopt, 'y')
120 BOTH ("yacc", no, &yacc_flag, tok_intopt, 'y')
121
122 /* Parser. */
123 BOTH ("debug", no, &debug_flag, tok_intopt, 't')
124 BOTH ("locations", no, &locations_flag, tok_intopt, 1)
125 BOTH ("no-lines", no, &no_lines_flag, tok_intopt, 'l')
126 BOTH ("no-parser", no, &no_parser_flag, tok_intopt, 'n')
127 BOTH ("raw", no, 0, tok_obsolete, 'r')
128 BOTH ("skeleton", required, 0, tok_skel, 'S')
129 BOTH ("token-table", no, &token_table_flag, tok_intopt, 'k')
130
131 {0, 0, 0, 0, 0, 0}
132 };
133
134
135 /*--------------------------------------------------------.
136 | Create the longoptions structure from the option_table, |
137 | for the getopt file. |
138 `--------------------------------------------------------*/
139
140 struct option *
141 long_option_table_new ()
142 {
143 struct option *res = NULL;
144 int i = 0;
145 int j = 0;
146 int number_options;
147
148 for (number_options = 0; option_table[i].name; i++)
149 if (option_table[i].access == opt_cmd_line
150 || option_table[i].access == opt_both)
151 ++number_options;
152
153 res = XMALLOC (struct option, number_options + 1);
154 for (i = 0; option_table[i].name; i++)
155 if (option_table[i].access == opt_cmd_line
156 || option_table[i].access == opt_both)
157 {
158 /* Copy the struct information in the longoptions. */
159 res[j].name = option_table[i].name;
160 res[j].has_arg = option_table[i].has_arg;
161 /* When an options is declared having 'optional_argument' and
162 a flag is specified to be set, the option is skipped on
163 command line. So we never use a flag when a command line
164 option is declared 'optional_argument. */
165 if (res[j].has_arg == optional_argument)
166 res[j].flag = NULL;
167 else
168 res[j].flag = option_table[i].set_flag;
169 res[j++].val = option_table[i].val;
170 }
171 res[number_options].name = NULL;
172 res[number_options].has_arg = 0;
173 res[number_options].flag = NULL;
174 res[number_options].val = 0;
175
176 return res;
177 }