Mercurial > hg > Applications > Grep
comparison regexParser/grepWalk.cc @ 293:948428caf616
NFA maximum match worked
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 02 Feb 2016 10:38:45 +0900 |
parents | e51cac73e42a |
children | bdfe0a32c48f |
comparison
equal
deleted
inserted
replaced
292:868f01f1ba8e | 293:948428caf616 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 | 2 |
3 #include "grepWalk.h" | 3 #include "grepWalk.h" |
4 #include "subsetConstruction.h" | 4 #include "subsetConstruction.h" |
5 | 5 |
6 void grepMatch(TransitionGeneratorPtr tg,Buffer buff); | 6 void grep(TransitionGeneratorPtr tg,unsigned char *matchBegin,Buffer buff,unsigned long d) ; |
7 void grep(TransitionGeneratorPtr tg,Buffer buff); | |
8 void grepSkip(TransitionGeneratorPtr tg,Buffer buff); | |
9 | 7 |
10 void grepMatch(TransitionGeneratorPtr tg,Buffer buff) { | 8 void grepSkip(TransitionGeneratorPtr tg,unsigned char *matchBegin, Buffer buff) { |
11 fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin-1,1,stdout); | 9 matchBegin = buff.buffptr; |
12 puts("\n"); | 10 grep(tg,matchBegin,buff,1); // 1 is initState |
13 grepSkip(tg,buff); | |
14 } | 11 } |
15 | 12 |
16 void grep(TransitionGeneratorPtr tg,Buffer buff,unsigned long d) { | 13 void grepWalk(TransitionGeneratorPtr tg, unsigned char *matchBegin, Buffer buff) { |
14 grepSkip(tg,matchBegin,buff); | |
15 } | |
16 | |
17 void grepMatch(TransitionGeneratorPtr tg,unsigned char *matchBegin, Buffer buff) { | |
18 fwrite(matchBegin,buff.buffptr-matchBegin,1,stdout); | |
19 puts("\n"); | |
20 grepSkip(tg,matchBegin,buff); | |
21 } | |
22 | |
23 void grep(TransitionGeneratorPtr tg,unsigned char *matchBegin,Buffer buff,unsigned long d) { | |
17 unsigned char c = *buff.buffptr++; | 24 unsigned char c = *buff.buffptr++; |
18 if (c=='\0') return; | 25 if (c=='\0') return; |
19 StatePtr state = tg->stateList; | 26 StatePtr state = tg->stateList; |
20 | 27 |
21 while (state->bitState.bitContainer != d) state = state->next; // 配列へのアクセスへ変更 | 28 while (state->bitState.bitContainer != d) state = state->next; // 配列へのアクセスへ変更 |
35 } | 42 } |
36 if (found == true) break; | 43 if (found == true) break; |
37 } | 44 } |
38 | 45 |
39 if (found == false) { | 46 if (found == false) { |
40 grepSkip(tg,buff); | 47 grepSkip(tg,matchBegin,buff); |
41 } else if (found == true && (cc->nextState.bitContainer | 2)) { // Accept | 48 } else if (found == true && (cc->nextState.bitContainer | 2)) { // Accept |
42 grepMatch(tg,buff); | 49 grepMatch(tg,matchBegin,buff); |
43 } else { | 50 } else { |
44 grep(tg,buff,cc->nextState.bitContainer); | 51 grep(tg,matchBegin,buff,cc->nextState.bitContainer); |
45 } | 52 } |
46 } | 53 } |
47 | 54 |
48 void grepSkip(TransitionGeneratorPtr tg,Buffer buff) { | |
49 buff.matchBegin = buff.buffptr; | |
50 grep(tg,buff,1); // 1 is initState | |
51 } | |
52 | |
53 void grepWalk(TransitionGeneratorPtr tg, Buffer buff) { | |
54 grepSkip(tg,buff); | |
55 } |