]>
Commit | Line | Data |
---|---|---|
82b6d266 PB |
1 | /* Concentrate all options use in bison, |
2 | Copyright 2001 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 | ||
82b6d266 PB |
21 | #include "system.h" |
22 | #include "getopt.h" | |
951366c1 | 23 | #include "files.h" |
82b6d266 | 24 | #include "getargs.h" |
c0629aa1 | 25 | #include "symtab.h" |
82b6d266 | 26 | #include "lex.h" |
c7925b99 | 27 | #include "output.h" |
82b6d266 PB |
28 | #include "options.h" |
29 | ||
30 | /* Shorts options. */ | |
eeeb962b | 31 | const char *shortopts = "yvegdhrltknVo:b:p:S:"; |
82b6d266 PB |
32 | |
33 | /* Long options. */ | |
34 | struct option *longopts = NULL; | |
35 | ||
36 | struct percent_table_struct *percent_table = NULL; | |
37 | ||
0edad749 AD |
38 | /* A CLI option only. |
39 | Arguments is the policy: `no', `optional', `required'. | |
40 | OptionChar is the value given to the Var if the latter is specified. */ | |
41 | #undef OPTN | |
42 | #define OPTN(OptionString, Arguments, Var, Token, OptionChar) \ | |
43 | { opt_cmd_line, \ | |
44 | (OptionString), (Arguments##_argument), (Var), (Token), (OptionChar) }, | |
45 | ||
46 | /* A directive only. */ | |
47 | #undef DRTV | |
48 | #define DRTV(DirectiveString, Arguments, Var, Token) \ | |
49 | { opt_percent, \ | |
50 | (DirectiveString), (Arguments##_argument), (Var), (Token), (0) }, | |
51 | ||
52 | /* An option activated both by a directive and an CLI option. */ | |
53 | #undef BOTH | |
54 | #define BOTH(String, Arguments, Var, Token, OptionChar) \ | |
55 | { opt_both, \ | |
56 | (String), (Arguments##_argument), (Var), (Token), (OptionChar) }, | |
57 | ||
58 | ||
82b6d266 PB |
59 | const struct option_table_struct option_table[] = |
60 | { | |
61 | /* | |
62 | * Command line. | |
63 | */ | |
64 | ||
65 | /* Operation modes. */ | |
0edad749 AD |
66 | OPTN ("help", no, 0, 0, 'h') |
67 | OPTN ("version", no, 0, 0, 'V') | |
342b8b6e | 68 | |
82b6d266 | 69 | /* Parser. */ |
0edad749 AD |
70 | OPTN ("name-prefix", required, 0, 0, 'p') |
71 | OPTN ("include", required, 0, 0, 'I') | |
82b6d266 PB |
72 | |
73 | /* Output. */ | |
0edad749 AD |
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') | |
82b6d266 PB |
78 | |
79 | /* Hidden. */ | |
0edad749 | 80 | OPTN ("trace", no, &trace_flag, 0, 1) |
82b6d266 PB |
81 | |
82 | /* | |
83 | * Percent declarations. | |
84 | */ | |
85 | ||
0edad749 AD |
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) | |
951366c1 AD |
101 | |
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 ? | |
105 | */ | |
0edad749 AD |
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') | |
951366c1 | 109 | |
0edad749 AD |
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) | |
82b6d266 PB |
113 | |
114 | /* | |
115 | * Percent and command line declarations. | |
116 | */ | |
117 | ||
82b6d266 | 118 | /* Output. */ |
0edad749 AD |
119 | BOTH ("defines", optional, &defines_flag, tok_intopt, 'd') |
120 | BOTH ("verbose", no, &verbose_flag, tok_intopt, 'v') | |
82b6d266 PB |
121 | |
122 | /* Operation modes. */ | |
0edad749 AD |
123 | BOTH ("fixed-output-files", no, &yacc_flag, tok_intopt, 'y') |
124 | BOTH ("yacc", no, &yacc_flag, tok_intopt, 'y') | |
82b6d266 PB |
125 | |
126 | /* Parser. */ | |
0edad749 AD |
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') | |
82b6d266 PB |
134 | |
135 | {0, 0, 0, 0, 0, 0} | |
136 | }; | |
137 | ||
138 | /*--------------------------------------------------------. | |
139 | | Create the longoptions structure from the option_table, | | |
140 | | for the getopt file. | | |
141 | `--------------------------------------------------------*/ | |
142 | void | |
143 | create_long_option_table () | |
144 | { | |
145 | int i = 0; | |
146 | int j = 0; | |
147 | int number_options; | |
148 | ||
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) | |
152 | ++number_options; | |
153 | ||
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) | |
158 | { | |
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; | |
5d52e7d0 | 162 | /* When an options is declared having 'optional_argument' and |
951366c1 | 163 | a flag is specified to be set, the option is skipped on |
5d52e7d0 MA |
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; | |
168 | else | |
169 | longopts[j].flag = option_table[i].set_flag; | |
82b6d266 PB |
170 | longopts[j++].val = option_table[i].val; |
171 | } | |
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; | |
176 | } |