summaryrefslogtreecommitdiff
path: root/yacc.c
blob: 75f1fc182447789c74f66d965716861731808e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define C_ID_FIRSTCHAR "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

int main(int argc, char *argv[])
{
	char *fileprefix = "y";
	char *symbolprefix = "yy";
	int header = 0;
	int lines = 1;
	int debug = 0;
	int verbose = 0;
	int c;

	while ((c = getopt(argc, argv, "bdlptv")) != -1) {
		switch (c) {
		case 'b':
			/* Change file prefix */
			fileprefix = optarg;
			break;

		case 'd':
			/* Write a header file */
			header = 1;
			break;

		case 'l':
			/* Omit #line directives */
			lines = 0;
			break;

		case 'p':
			/* Change symbol prefix */
			symbolprefix = optarg;
			if (!strchr(C_ID_FIRSTCHAR, *symbolprefix)) {
				printf("'%s' is not a valid prefix\n", optarg);
				return 1;
			}
			break;

		case 't':
			/* Include debugging code */
			debug = 1;
			break;

		case 'v':
			/* Output a description file */
			verbose = 1;
			break;
			
		default:
			return 1;
		}
	}

	if (optind != argc - 1) {
		fprintf(stderr, "Must specify exactly one grammar file\n");
		return 1;
	}

	return 0;
}