]>
Commit | Line | Data |
---|---|---|
82b6d266 | 1 | /* Concentrate all options use in bison, |
bba97eb2 | 2 | Copyright 2001, 2002 Free Software Foundation, Inc. |
82b6d266 PB |
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" |
bba97eb2 | 26 | #include "gram.h" |
c7925b99 | 27 | #include "output.h" |
82b6d266 PB |
28 | #include "options.h" |
29 | ||
30 | /* Shorts options. */ | |
ec3bc396 | 31 | const char *shortopts = "yvegdhr:ltknVo:b:p:S:"; |
82b6d266 | 32 | |
0edad749 AD |
33 | /* A CLI option only. |
34 | Arguments is the policy: `no', `optional', `required'. | |
35 | OptionChar is the value given to the Var if the latter is specified. */ | |
36 | #undef OPTN | |
37 | #define OPTN(OptionString, Arguments, Var, Token, OptionChar) \ | |
38 | { opt_cmd_line, \ | |
39 | (OptionString), (Arguments##_argument), (Var), (Token), (OptionChar) }, | |
40 | ||
41 | /* A directive only. */ | |
42 | #undef DRTV | |
43 | #define DRTV(DirectiveString, Arguments, Var, Token) \ | |
44 | { opt_percent, \ | |
45 | (DirectiveString), (Arguments##_argument), (Var), (Token), (0) }, | |
46 | ||
47 | /* An option activated both by a directive and an CLI option. */ | |
48 | #undef BOTH | |
49 | #define BOTH(String, Arguments, Var, Token, OptionChar) \ | |
50 | { opt_both, \ | |
51 | (String), (Arguments##_argument), (Var), (Token), (OptionChar) }, | |
52 | ||
53 | ||
ec3bc396 | 54 | const struct option_table_s option_table[] = |
82b6d266 PB |
55 | { |
56 | /* | |
57 | * Command line. | |
58 | */ | |
59 | ||
60 | /* Operation modes. */ | |
0edad749 AD |
61 | OPTN ("help", no, 0, 0, 'h') |
62 | OPTN ("version", no, 0, 0, 'V') | |
342b8b6e | 63 | |
82b6d266 | 64 | /* Parser. */ |
0edad749 AD |
65 | OPTN ("name-prefix", required, 0, 0, 'p') |
66 | OPTN ("include", required, 0, 0, 'I') | |
82b6d266 PB |
67 | |
68 | /* Output. */ | |
0edad749 AD |
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') | |
ec3bc396 AD |
73 | OPTN ("report", required, 0, 0, 'r') |
74 | OPTN ("verbose", no, 0, 0, 'v') | |
82b6d266 PB |
75 | |
76 | /* Hidden. */ | |
0edad749 | 77 | OPTN ("trace", no, &trace_flag, 0, 1) |
82b6d266 | 78 | |
951366c1 AD |
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 ? | |
82 | */ | |
e9955c83 AD |
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') | |
82b6d266 PB |
86 | |
87 | /* | |
88 | * Percent and command line declarations. | |
89 | */ | |
90 | ||
82b6d266 | 91 | /* Output. */ |
e9955c83 | 92 | OPTN ("defines", optional, &defines_flag, 0, 'd') |
82b6d266 PB |
93 | |
94 | /* Operation modes. */ | |
e9955c83 AD |
95 | OPTN ("fixed-output-files", no, &yacc_flag, 0, 'y') |
96 | OPTN ("yacc", no, &yacc_flag, 0, 'y') | |
82b6d266 PB |
97 | |
98 | /* Parser. */ | |
e9955c83 AD |
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') | |
82b6d266 PB |
106 | |
107 | {0, 0, 0, 0, 0, 0} | |
108 | }; | |
109 | ||
f51cb8ff | 110 | |
82b6d266 PB |
111 | /*--------------------------------------------------------. |
112 | | Create the longoptions structure from the option_table, | | |
113 | | for the getopt file. | | |
114 | `--------------------------------------------------------*/ | |
f51cb8ff AD |
115 | |
116 | struct option * | |
117 | long_option_table_new () | |
82b6d266 | 118 | { |
f51cb8ff | 119 | struct option *res = NULL; |
82b6d266 PB |
120 | int i = 0; |
121 | int j = 0; | |
122 | int number_options; | |
123 | ||
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) | |
127 | ++number_options; | |
128 | ||
f51cb8ff | 129 | res = XMALLOC (struct option, number_options + 1); |
82b6d266 PB |
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) | |
133 | { | |
f51cb8ff AD |
134 | res[j].name = option_table[i].name; |
135 | res[j].has_arg = option_table[i].has_arg; | |
ec3bc396 AD |
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. */ | |
f51cb8ff AD |
140 | if (res[j].has_arg == optional_argument) |
141 | res[j].flag = NULL; | |
5d52e7d0 | 142 | else |
ec3bc396 | 143 | res[j].flag = option_table[i].flag; |
f51cb8ff | 144 | res[j++].val = option_table[i].val; |
82b6d266 | 145 | } |
f51cb8ff AD |
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; | |
150 | ||
151 | return res; | |
82b6d266 | 152 | } |