]> git.saurik.com Git - bison.git/blame - src/getargs.c
[_MSC_VER] (XPFILE, XPFILE1): Define, if not already defined.
[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
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21#include <stdio.h>
22#include "getopt.h"
23#include "system.h"
24#include "files.h"
25
26int verboseflag;
27int definesflag;
28int debugflag;
29int nolinesflag;
6dd6d212
RS
30int noparserflag = 0;
31int toknumflag = 0;
32int rawtoknumflag = 0;
3d8fc6ca
RS
33char *spec_name_prefix; /* for -p. */
34char *spec_file_prefix; /* for -b. */
35extern int fixed_outfiles;/* for -y */
6dd6d212 36
cbd8ffc5
DM
37extern char *program_name;
38extern char *version_string;
39
6dd6d212 40extern void warns(); /* main.c */
3d8fc6ca
RS
41
42struct option longopts[] =
43{
44 {"debug", 0, &debugflag, 1},
45 {"defines", 0, &definesflag, 1},
46 {"file-prefix", 1, 0, 'b'},
47 {"fixed-output-files", 0, &fixed_outfiles, 1},
cbd8ffc5 48 {"help", 0, 0, 'h'},
6dd6d212 49 {"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
3d8fc6ca 50 {"no-lines", 0, &nolinesflag, 1},
6dd6d212 51 {"no-parser", 0, &noparserflag, 1},
3d8fc6ca
RS
52 {"output", 1, 0, 'o'},
53 {"output-file", 1, 0, 'o'},
6dd6d212
RS
54 {"raw", 0, &rawtoknumflag, 1},
55 {"token-table", 0, &toknumflag, 1},
3d8fc6ca
RS
56 {"verbose", 0, &verboseflag, 1},
57 {"version", 0, 0, 'V'},
58 {"yacc", 0, &fixed_outfiles, 1},
59 {0, 0, 0, 0}
60};
61
cbd8ffc5
DM
62void
63usage (stream)
64 FILE *stream;
65{
a083fbbf 66 fprintf (stream, _("\
6dd6d212 67Usage: %s [-dhklntvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
cbd8ffc5
DM
68 [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
69 [--verbose] [--version] [--help] [--yacc]\n\
6dd6d212 70 [--no-parser] [--token-table]\n\
cbd8ffc5 71 [--file-prefix=prefix] [--name-prefix=prefix]\n\
a083fbbf 72 [--output=outfile] grammar-file\n"),
cbd8ffc5
DM
73 program_name);
74}
75
3d8fc6ca
RS
76void
77getargs(argc, argv)
78 int argc;
79 char *argv[];
80{
81 register int c;
3d8fc6ca
RS
82
83 verboseflag = 0;
84 definesflag = 0;
85 debugflag = 0;
6dd6d212
RS
86 noparserflag = 0;
87 rawtoknumflag = 0;
88 toknumflag = 0;
3d8fc6ca
RS
89 fixed_outfiles = 0;
90
6dd6d212 91 while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
3d8fc6ca
RS
92 != EOF)
93 {
3d8fc6ca
RS
94 switch (c)
95 {
96 case 0:
97 /* Certain long options cause getopt_long to return 0. */
98 break;
99
100 case 'y':
101 fixed_outfiles = 1;
102 break;
103
cbd8ffc5
DM
104 case 'h':
105 usage (stdout);
106 exit (0);
107
3d8fc6ca 108 case 'V':
cbd8ffc5
DM
109 printf ("%s", version_string);
110 exit (0);
3d8fc6ca
RS
111
112 case 'v':
113 verboseflag = 1;
114 break;
115
116 case 'd':
117 definesflag = 1;
118 break;
119
120 case 'l':
121 nolinesflag = 1;
122 break;
123
6dd6d212
RS
124 case 'k':
125 toknumflag = 1;
126 break;
127
128 case 'r':
129 rawtoknumflag = 1;
130 break;
131
132 case 'n':
133 noparserflag = 1;
134 break;
135
3d8fc6ca
RS
136 case 't':
137 debugflag = 1;
138 break;
139
140 case 'o':
141 spec_outfile = optarg;
142 break;
143
144 case 'b':
145 spec_file_prefix = optarg;
146 break;
147
148 case 'p':
149 spec_name_prefix = optarg;
150 break;
151
152 default:
cbd8ffc5 153 usage (stderr);
3d8fc6ca
RS
154 exit (1);
155 }
156 }
157
158 if (optind == argc)
159 {
a083fbbf 160 fprintf(stderr, _("%s: no grammar file given\n"), program_name);
3d8fc6ca
RS
161 exit(1);
162 }
163 if (optind < argc - 1)
a083fbbf 164 fprintf(stderr, _("%s: extra arguments ignored after '%s'\n"),
6dd6d212 165 program_name, argv[optind]);
3d8fc6ca
RS
166
167 infile = argv[optind];
168}