]>
Commit | Line | Data |
---|---|---|
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 "output.h" | |
28 | #include "options.h" | |
29 | ||
30 | /* Shorts options. */ | |
31 | const char *shortopts = "yvegdhr:ltknVo:b:p:S:"; | |
32 | ||
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 | ||
54 | const struct option_table_s option_table[] = | |
55 | { | |
56 | /* | |
57 | * Command line. | |
58 | */ | |
59 | ||
60 | /* Operation modes. */ | |
61 | OPTN ("help", no, 0, 0, 'h') | |
62 | OPTN ("version", no, 0, 0, 'V') | |
63 | ||
64 | /* Parser. */ | |
65 | OPTN ("name-prefix", required, 0, 0, 'p') | |
66 | OPTN ("include", required, 0, 0, 'I') | |
67 | ||
68 | /* Output. */ | |
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') | |
75 | ||
76 | /* Hidden. */ | |
77 | OPTN ("trace", no, &trace_flag, 0, 1) | |
78 | ||
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 | */ | |
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') | |
86 | ||
87 | /* | |
88 | * Percent and command line declarations. | |
89 | */ | |
90 | ||
91 | /* Output. */ | |
92 | OPTN ("defines", optional, &defines_flag, 0, 'd') | |
93 | ||
94 | /* Operation modes. */ | |
95 | OPTN ("fixed-output-files", no, &yacc_flag, 0, 'y') | |
96 | OPTN ("yacc", no, &yacc_flag, 0, 'y') | |
97 | ||
98 | /* Parser. */ | |
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') | |
106 | ||
107 | {0, 0, 0, 0, 0, 0} | |
108 | }; | |
109 | ||
110 | ||
111 | /*--------------------------------------------------------. | |
112 | | Create the longoptions structure from the option_table, | | |
113 | | for the getopt file. | | |
114 | `--------------------------------------------------------*/ | |
115 | ||
116 | struct option * | |
117 | long_option_table_new () | |
118 | { | |
119 | struct option *res = NULL; | |
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 | ||
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) | |
133 | { | |
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) | |
141 | res[j].flag = NULL; | |
142 | else | |
143 | res[j].flag = option_table[i].flag; | |
144 | res[j++].val = option_table[i].val; | |
145 | } | |
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; | |
152 | } |