comparison regen/src/regen.c @ 11:1e0cd7fade8b

add regen
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 19 Jun 2011 16:36:05 +0900
parents
children
comparison
equal deleted inserted replaced
10:41634f26cd6f 11:1e0cd7fade8b
1 #include "re.h"
2 #include "util.h"
3 #include "codegen.h"
4 #include "generator.h"
5 #include <unistd.h>
6 #include <getopt.h>
7
8 void initialize(REGEX *, CODEGEN*, int, char *[]);
9 extern void parse(REGEX *, CODEGEN*);
10 void compile(REGEX *, CODEGEN*);
11 extern void codegen(REGEX *, CODEGEN*);
12 void finalize(REGEX *, CODEGEN*);
13
14 int
15 main(int argc, char *argv[])
16 {
17 REGEX* r = (REGEX *)xcalloc(sizeof(REGEX), 1, "regex");
18 CODEGEN* g = (CODEGEN *)xcalloc(sizeof(CODEGEN), 1, "codegen");
19 initialize(r, g, argc, argv);
20 parse(r, g);
21 codegen(r, g);
22 compile(r, g);
23 finalize(r, g);
24 return 0;
25 }
26
27 void
28 initialize(REGEX *r, CODEGEN *g, int argc, char *argv[])
29 {
30 int opt, len;
31 FILE *fp;
32
33 static char buf[1024];
34 g->output = stdout;
35 g->enable_filter = TRUE;
36 g->enable_predict = TRUE;
37 g->gen_table_lookup = TRUE;
38 set_gen_function(r, g);
39
40 g->genroot = getenv("REGENROOT");
41 if (g->genroot == NULL) {
42 exitmsg("$REGENROOT not defined.");
43 }
44
45 while ((opt=getopt(argc, argv, "dlbglso:f:")) != -1) {
46 switch (opt) {
47 case 'f':
48 {
49 fp = xfopen(optarg, "r");
50 fgets(buf, sizeof(buf), fp);
51 r->regex = buf;
52 if (buf[strlen(buf)-1] == '\n') {
53 buf[strlen(buf)-1] = '\0';
54 }
55 fclose(fp);
56 }
57 break;
58 case 'o':
59 fp = xfopen(optarg, "w+");
60 g->output = fp;
61 break;
62 case 's':
63 g->gen_table_lookup = FALSE;
64 break;
65 case 'l':
66 set_gen_label(r, g);
67 break;
68 case 'b':
69 set_gen_cbc(r, g);
70 break;
71 case 'd':
72 set_gen_dot(r, g);
73 break;
74 case 'g':
75 r->debug = TRUE;
76 break;
77 default:
78 exit(1);
79 }
80 }
81
82 if (r->regex == NULL) {
83 if (optind >= argc) {
84 exitmsg("USAGE: regen [options] regexp\n");
85 }
86 r->regex = argv[optind];
87 }
88
89 len = strlen(r->regex);
90 r->regex_end = r->regex+len;
91 r->escaped_regex = escape(r->regex);
92 r->maxid = 1;
93 r->lit_expr = (EXPR **)xmalloc(len*sizeof(EXPR *), "regexp base set");
94 r->involve = (UCHARP)xcalloc(sizeof(UCHAR), NCHAR, "involve");
95 }
96
97 void
98 compile(REGEX *r, CODEGEN *g)
99 {
100 }
101
102 void
103 finalize(REGEX *r, CODEGEN *g)
104 {
105 //FIXME: this code make corrupted double-linked list. (why?)
106 //fclose(g->output);
107 }