]> git.saurik.com Git - bison.git/blame - src/getargs.c
Have configure build version string instead of relying on ANSI string
[bison.git] / src / getargs.c
CommitLineData
3d8fc6ca 1/* Parse command line arguments for bison,
6dd6d212 2 Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
3d8fc6ca
RS
3
4This file is part of Bison, the GNU Compiler Compiler.
5
6Bison is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Bison is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Bison; see the file COPYING. If not, write to
c49a8e71
JT
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
3d8fc6ca
RS
20
21
22#include <stdio.h>
23#include "getopt.h"
24#include "system.h"
25#include "files.h"
26
27int verboseflag;
28int definesflag;
29int debugflag;
30int nolinesflag;
6dd6d212
RS
31int noparserflag = 0;
32int toknumflag = 0;
33int rawtoknumflag = 0;
3d8fc6ca
RS
34char *spec_name_prefix; /* for -p. */
35char *spec_file_prefix; /* for -b. */
36extern int fixed_outfiles;/* for -y */
6dd6d212 37
d2729d44
JT
38void usage PARAMS((FILE *));
39void getargs PARAMS((int, char *[]));
40
cbd8ffc5 41extern char *program_name;
cbd8ffc5 42
d2729d44 43extern void warns PARAMS((char *, char *)); /* main.c */
3d8fc6ca
RS
44
45struct option longopts[] =
46{
47 {"debug", 0, &debugflag, 1},
48 {"defines", 0, &definesflag, 1},
49 {"file-prefix", 1, 0, 'b'},
50 {"fixed-output-files", 0, &fixed_outfiles, 1},
cbd8ffc5 51 {"help", 0, 0, 'h'},
6dd6d212 52 {"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
3d8fc6ca 53 {"no-lines", 0, &nolinesflag, 1},
6dd6d212 54 {"no-parser", 0, &noparserflag, 1},
3d8fc6ca
RS
55 {"output", 1, 0, 'o'},
56 {"output-file", 1, 0, 'o'},
6dd6d212
RS
57 {"raw", 0, &rawtoknumflag, 1},
58 {"token-table", 0, &toknumflag, 1},
3d8fc6ca
RS
59 {"verbose", 0, &verboseflag, 1},
60 {"version", 0, 0, 'V'},
61 {"yacc", 0, &fixed_outfiles, 1},
62 {0, 0, 0, 0}
63};
64
cbd8ffc5 65void
d2729d44 66usage (FILE *stream)
cbd8ffc5 67{
a083fbbf 68 fprintf (stream, _("\
6dd6d212 69Usage: %s [-dhklntvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
cbd8ffc5
DM
70 [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
71 [--verbose] [--version] [--help] [--yacc]\n\
6dd6d212 72 [--no-parser] [--token-table]\n\
cbd8ffc5 73 [--file-prefix=prefix] [--name-prefix=prefix]\n\
5c9ba631
JT
74 [--output=outfile] grammar-file\n\n\
75Report bugs to bug-bison@gnu.org\n"),
cbd8ffc5
DM
76 program_name);
77}
78
3d8fc6ca 79void
d2729d44 80getargs (int argc, char *argv[])
3d8fc6ca
RS
81{
82 register int c;
3d8fc6ca
RS
83
84 verboseflag = 0;
85 definesflag = 0;
86 debugflag = 0;
6dd6d212
RS
87 noparserflag = 0;
88 rawtoknumflag = 0;
89 toknumflag = 0;
3d8fc6ca
RS
90 fixed_outfiles = 0;
91
6dd6d212 92 while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
3d8fc6ca
RS
93 != EOF)
94 {
3d8fc6ca
RS
95 switch (c)
96 {
97 case 0:
98 /* Certain long options cause getopt_long to return 0. */
99 break;
100
101 case 'y':
102 fixed_outfiles = 1;
103 break;
104
cbd8ffc5
DM
105 case 'h':
106 usage (stdout);
107 exit (0);
108
3d8fc6ca 109 case 'V':
6ed61226 110 printf ("%s\n", VERSION_STRING);
cbd8ffc5 111 exit (0);
3d8fc6ca
RS
112
113 case 'v':
114 verboseflag = 1;
115 break;
116
117 case 'd':
118 definesflag = 1;
119 break;
120
121 case 'l':
122 nolinesflag = 1;
123 break;
124
6dd6d212
RS
125 case 'k':
126 toknumflag = 1;
127 break;
128
129 case 'r':
130 rawtoknumflag = 1;
131 break;
132
133 case 'n':
134 noparserflag = 1;
135 break;
136
3d8fc6ca
RS
137 case 't':
138 debugflag = 1;
139 break;
140
141 case 'o':
142 spec_outfile = optarg;
143 break;
144
145 case 'b':
146 spec_file_prefix = optarg;
147 break;
148
149 case 'p':
150 spec_name_prefix = optarg;
151 break;
152
153 default:
cbd8ffc5 154 usage (stderr);
3d8fc6ca
RS
155 exit (1);
156 }
157 }
158
159 if (optind == argc)
160 {
a083fbbf 161 fprintf(stderr, _("%s: no grammar file given\n"), program_name);
3d8fc6ca
RS
162 exit(1);
163 }
164 if (optind < argc - 1)
a083fbbf 165 fprintf(stderr, _("%s: extra arguments ignored after '%s'\n"),
6dd6d212 166 program_name, argv[optind]);
3d8fc6ca
RS
167
168 infile = argv[optind];
169}