]> git.saurik.com Git - bison.git/blame - src/getargs.c
Initial revision
[bison.git] / src / getargs.c
CommitLineData
3d8fc6ca
RS
1/* Parse command line arguments for bison,
2 Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
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;
30char *spec_name_prefix; /* for -p. */
31char *spec_file_prefix; /* for -b. */
32extern int fixed_outfiles;/* for -y */
33
34extern void fatal();
35
36struct option longopts[] =
37{
38 {"debug", 0, &debugflag, 1},
39 {"defines", 0, &definesflag, 1},
40 {"file-prefix", 1, 0, 'b'},
41 {"fixed-output-files", 0, &fixed_outfiles, 1},
42 {"name-prefix", 1, 0, 'a'},
43 {"no-lines", 0, &nolinesflag, 1},
44 {"output", 1, 0, 'o'},
45 {"output-file", 1, 0, 'o'},
46 {"verbose", 0, &verboseflag, 1},
47 {"version", 0, 0, 'V'},
48 {"yacc", 0, &fixed_outfiles, 1},
49 {0, 0, 0, 0}
50};
51
52void
53getargs(argc, argv)
54 int argc;
55 char *argv[];
56{
57 register int c;
58 int longind;
59 extern char *program_name;
60 extern char *version_string;
61
62 verboseflag = 0;
63 definesflag = 0;
64 debugflag = 0;
65 fixed_outfiles = 0;
66
67 while ((c = getopt_long (argc, argv, "yvdltVo:b:p:", longopts, &longind))
68 != EOF)
69 {
70 if (c == 0 && longopts[longind].flag == 0)
71 c = longopts[longind].val;
72 switch (c)
73 {
74 case 0:
75 /* Certain long options cause getopt_long to return 0. */
76 break;
77
78 case 'y':
79 fixed_outfiles = 1;
80 break;
81
82 case 'V':
83 printf("%s", version_string);
84 break;
85
86 case 'v':
87 verboseflag = 1;
88 break;
89
90 case 'd':
91 definesflag = 1;
92 break;
93
94 case 'l':
95 nolinesflag = 1;
96 break;
97
98 case 't':
99 debugflag = 1;
100 break;
101
102 case 'o':
103 spec_outfile = optarg;
104 break;
105
106 case 'b':
107 spec_file_prefix = optarg;
108 break;
109
110 case 'p':
111 spec_name_prefix = optarg;
112 break;
113
114 default:
115 fprintf (stderr, "\
116Usage: %s [-dltvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
117 [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
118 [--verbose] [--version] [--yacc]\n\
119 [--file-prefix=prefix] [--name-prefix=prefix]\n\
120 [--output=outfile] grammar-file\n",
121 program_name);
122 exit (1);
123 }
124 }
125
126 if (optind == argc)
127 {
128 fprintf(stderr, "%s: no grammar file given\n", program_name);
129 exit(1);
130 }
131 if (optind < argc - 1)
132 fprintf(stderr, "%s: warning: extra arguments ignored\n", program_name);
133
134 infile = argv[optind];
135}