Mercurial > hg > Applications > Grep
comparison regexParser/grepWalk.cc @ 234:df4d04b3c34a
implement grepWalk (not confirm correct working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 19 Jan 2016 14:52:33 +0900 |
parents | 1a34e702776a |
children | 4aab1e93a971 |
comparison
equal
deleted
inserted
replaced
233:6d0a0126ddda | 234:df4d04b3c34a |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 | 2 |
3 #include "grepWalk.h" | 3 #include "grepWalk.h" |
4 #include "subsetConstruction.h" | |
5 | |
6 void grepMatch(TransitionGeneratorPtr tg,Buffer buff); | |
7 void grep(TransitionGeneratorPtr tg,Buffer buff); | |
8 void grepSkip(TransitionGeneratorPtr tg,Buffer buff); | |
9 | |
10 void grepMatch(TransitionGeneratorPtr tg,Buffer buff) { | |
11 fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin,1,stdout); | |
12 puts("\n"); | |
13 grepSkip(tg,buff); | |
14 } | |
15 | |
16 void grep(TransitionGeneratorPtr tg,Buffer buff,unsigned long d) { | |
17 unsigned char c = *buff.buffptr++; | |
18 StatePtr state = tg->stateList; | |
19 bool found = false; | |
20 | |
21 while (state->bitState.bitContainer != d) state = state->next; | |
22 CharClassWalkerPtr ccw = createCharClassWalker(state->cc); | |
23 CharClassPtr cc = NULL; | |
24 while (hasNext(ccw)) { | |
25 cc = getNext(ccw); | |
26 unsigned long begin = cc->cond.range.begin; | |
27 unsigned long end = cc->cond.range.end; | |
28 if (c < begin) found = false; | |
29 else if (c < end) found = true; | |
30 if (found == true) break; | |
31 } | |
32 | |
33 if (found == false) { | |
34 grepSkip(tg,buff); | |
35 } else if (found == true && (cc->nextState.bitContainer == 2)) { // Accept | |
36 grepMatch(tg,buff); | |
37 } else { | |
38 grep(tg,buff,cc->nextState.bitContainer); | |
39 } | |
40 } | |
41 | |
42 void grepSkip(TransitionGeneratorPtr tg,Buffer buff) { | |
43 buff.matchBegin = buff.buffptr; | |
44 grep(tg,buff,1); // 1 is initState | |
45 } | |
4 | 46 |
5 void grepWalk(TransitionGeneratorPtr tg, Buffer buff) { | 47 void grepWalk(TransitionGeneratorPtr tg, Buffer buff) { |
6 | 48 grepSkip(tg,buff); |
7 } | 49 } |