]> git.saurik.com Git - bison.git/blame - src/options.c
* src/scan-skel.l: Correct off-by-one error in handling of __oline__.
[bison.git] / src / options.c
CommitLineData
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"
82b6d266 27#include "lex.h"
c7925b99 28#include "output.h"
82b6d266
PB
29#include "options.h"
30
31/* Shorts options. */
eeeb962b 32const char *shortopts = "yvegdhrltknVo:b:p:S:";
82b6d266 33
0edad749
AD
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
82b6d266
PB
55const struct option_table_struct option_table[] =
56{
57 /*
58 * Command line.
59 */
60
61 /* Operation modes. */
0edad749
AD
62 OPTN ("help", no, 0, 0, 'h')
63 OPTN ("version", no, 0, 0, 'V')
342b8b6e 64
82b6d266 65 /* Parser. */
0edad749
AD
66 OPTN ("name-prefix", required, 0, 0, 'p')
67 OPTN ("include", required, 0, 0, 'I')
82b6d266
PB
68
69 /* Output. */
0edad749
AD
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')
82b6d266
PB
74
75 /* Hidden. */
0edad749 76 OPTN ("trace", no, &trace_flag, 0, 1)
82b6d266
PB
77
78 /*
79 * Percent declarations.
80 */
81
0edad749
AD
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)
0edad749
AD
86 DRTV ("union", no, NULL, tok_union)
87 DRTV ("expect", no, NULL, tok_expect)
88 DRTV ("thong", no, NULL, tok_thong)
89 DRTV ("start", no, NULL, tok_start)
90 DRTV ("left", no, NULL, tok_left)
91 DRTV ("right", no, NULL, tok_right)
92 DRTV ("nonassoc", no, NULL, tok_nonassoc)
93 DRTV ("binary", no, NULL, tok_nonassoc)
94 DRTV ("prec", no, NULL, tok_prec)
95 DRTV ("error-verbose",no, &error_verbose, tok_intopt)
951366c1
AD
96
97 /* FIXME: semantic parsers will output an `include' of an
98 output file: be sure that the naem included is indeed the name of
99 the output file. */ /* FIXME Should we activate this options ?
100 */
0edad749
AD
101 BOTH ("output", required, &spec_outfile, tok_stropt, 'o')
102 BOTH ("file-prefix", required, &spec_file_prefix, tok_stropt, 'b')
103 BOTH ("name-prefix", required, &spec_name_prefix, tok_stropt, 'p')
951366c1 104
0edad749 105 DRTV ("define", no, NULL, tok_define)
0edad749 106 DRTV ("pure-parser", no, &pure_parser, tok_intopt)
82b6d266
PB
107
108 /*
109 * Percent and command line declarations.
110 */
111
82b6d266 112 /* Output. */
0edad749
AD
113 BOTH ("defines", optional, &defines_flag, tok_intopt, 'd')
114 BOTH ("verbose", no, &verbose_flag, tok_intopt, 'v')
82b6d266
PB
115
116 /* Operation modes. */
0edad749
AD
117 BOTH ("fixed-output-files", no, &yacc_flag, tok_intopt, 'y')
118 BOTH ("yacc", no, &yacc_flag, tok_intopt, 'y')
82b6d266
PB
119
120 /* Parser. */
0edad749
AD
121 BOTH ("debug", no, &debug_flag, tok_intopt, 't')
122 BOTH ("locations", no, &locations_flag, tok_intopt, 1)
123 BOTH ("no-lines", no, &no_lines_flag, tok_intopt, 'l')
124 BOTH ("no-parser", no, &no_parser_flag, tok_intopt, 'n')
125 BOTH ("raw", no, 0, tok_obsolete, 'r')
126 BOTH ("skeleton", required, 0, tok_skel, 'S')
127 BOTH ("token-table", no, &token_table_flag, tok_intopt, 'k')
82b6d266
PB
128
129 {0, 0, 0, 0, 0, 0}
130};
131
f51cb8ff 132
82b6d266
PB
133/*--------------------------------------------------------.
134| Create the longoptions structure from the option_table, |
135| for the getopt file. |
136`--------------------------------------------------------*/
f51cb8ff
AD
137
138struct option *
139long_option_table_new ()
82b6d266 140{
f51cb8ff 141 struct option *res = NULL;
82b6d266
PB
142 int i = 0;
143 int j = 0;
144 int number_options;
145
146 for (number_options = 0; option_table[i].name; i++)
147 if (option_table[i].access == opt_cmd_line
148 || option_table[i].access == opt_both)
149 ++number_options;
150
f51cb8ff 151 res = XMALLOC (struct option, number_options + 1);
82b6d266
PB
152 for (i = 0; option_table[i].name; i++)
153 if (option_table[i].access == opt_cmd_line
154 || option_table[i].access == opt_both)
155 {
156 /* Copy the struct information in the longoptions. */
f51cb8ff
AD
157 res[j].name = option_table[i].name;
158 res[j].has_arg = option_table[i].has_arg;
5d52e7d0 159 /* When an options is declared having 'optional_argument' and
951366c1 160 a flag is specified to be set, the option is skipped on
5d52e7d0
MA
161 command line. So we never use a flag when a command line
162 option is declared 'optional_argument. */
f51cb8ff
AD
163 if (res[j].has_arg == optional_argument)
164 res[j].flag = NULL;
5d52e7d0 165 else
f51cb8ff
AD
166 res[j].flag = option_table[i].set_flag;
167 res[j++].val = option_table[i].val;
82b6d266 168 }
f51cb8ff
AD
169 res[number_options].name = NULL;
170 res[number_options].has_arg = 0;
171 res[number_options].flag = NULL;
172 res[number_options].val = 0;
173
174 return res;
82b6d266 175}