-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.c
73 lines (66 loc) · 1.21 KB
/
main.c
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
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <unistd.h>
#include <lib.h>
static char *script = NULL;
static char *lexpart = NULL;
static char *codefile = NULL;
void version(void)
{
fprintf(stderr, "tinylex (TINYLEX) 0.0.0 20110607\n\n");
exit(0);
}
void usage(void)
{
fprintf(stderr,
"USAGE: tinylex script [OPTIONS]\n"
"OPTIONS:\n"
" -o file output code file\n"
" -p file use file instead default lex.yy.part.c\n"
" -h help information\n"
" -v vertion information\n"
"e.g:\n"
" tinylex test/colour.l -o colour.c\n"
"\n"
);
exit(EXIT_FAILURE);
}
void parse_args(int argc, char **argv)
{
int i;
char opt;
if (argc < 2)
usage();
opterr = 0;
while ((opt = getopt(argc, argv, "o:p:hv")) != -1) {
switch (opt) {
case 'o':
if (codefile)
usage();
codefile = optarg;
break;
case 'h':
usage();
break;
case 'v':
version();
break;
case 'p':
lexpart = optarg;
break;
default:
usage();
break;
}
}
if (optind >= argc)
errexit("no script file");
script = argv[optind];
}
int main(int argc, char **argv)
{
parse_args(argc, argv);
open_script(script);
code_open(codefile, lexpart);
parse_script();
return 0;
}