Mercurial > hg > Applications > Grep
comparison regexParser/threadedSearch.cc @ 292:868f01f1ba8e
maximum match
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 01 Feb 2016 21:52:57 +0900 |
parents | f2491681914e |
children | 948428caf616 |
comparison
equal
deleted
inserted
replaced
291:1b75546ff65f | 292:868f01f1ba8e |
---|---|
11 } | 11 } |
12 | 12 |
13 static | 13 static |
14 TSValue stateSkip(TSValue tsv) { | 14 TSValue stateSkip(TSValue tsv) { |
15 tsv.current = tsv.tg->stateStart->tState; | 15 tsv.current = tsv.tg->stateStart->tState; |
16 tsv.buff.matchBegin = tsv.buff.buffptr; | 16 if (tsv.matchEnd) { |
17 fwrite(tsv.matchBegin,tsv.matchEnd-tsv.matchBegin,1,stdout); | |
18 puts(""); | |
19 tsv.matchEnd = NULL; | |
20 } | |
17 return tsv; | 21 return tsv; |
18 } | 22 } |
19 | 23 |
20 static | 24 static |
21 TSValue stateMatch(TSValue tsv) { | 25 TSValue stateMatch(TSValue tsv) { |
22 fwrite(tsv.buff.matchBegin,tsv.buff.buffptr-tsv.buff.matchBegin-1,1,stdout); | 26 tsv.matchEnd = tsv.buff.buffptr; // next char of the match |
23 puts(""); | |
24 tsv.buff.buffptr--; | |
25 tsv = stateSkip(tsv); | |
26 return tsv; | 27 return tsv; |
27 } | 28 } |
28 | 29 |
29 TStatePtr generateTState(StatePtr state, TransitionGeneratorPtr tg) { | 30 TStatePtr generateTState(StatePtr state, TransitionGeneratorPtr tg) { |
30 TStatePtr tState = NEW(TState); | 31 TStatePtr tState = NEW(TState); |
34 while (hasNext(ccw)) { | 35 while (hasNext(ccw)) { |
35 getNext(ccw); | 36 getNext(ccw); |
36 ccvSize++; | 37 ccvSize++; |
37 } | 38 } |
38 tState->ccvSize = ccvSize; | 39 tState->ccvSize = ccvSize; |
39 if (state->accept && state != tg->stateList ) { | 40 if (state->accept) { |
40 tState->stateSkip = tg->stateMatch; | 41 tState->stateSkip = tg->stateSkip; |
41 tState->stateContinue = tg->stateNothing; | 42 tState->stateMatch = tg->stateMatch; |
42 } else { | 43 } else { |
43 tState->stateSkip = tg->stateSkip; | 44 tState->stateSkip = tg->stateSkip; |
44 tState->stateContinue = tg->stateNothing; | 45 tState->stateMatch = tg->stateNothing; |
45 } | 46 } |
46 if (ccvSize == 0) { | 47 if (ccvSize == 0) { |
47 tState->ccv = NULL; | 48 tState->ccv = NULL; |
48 state->tState = tState; | 49 state->tState = tState; |
49 return tState; | 50 return tState; |
88 // printState(tsv.current->state); | 89 // printState(tsv.current->state); |
89 for (int i = 0; i < tsv.current->ccvSize; i++) { | 90 for (int i = 0; i < tsv.current->ccvSize; i++) { |
90 CCVPtr ccv = &tsv.current->ccv[i]; | 91 CCVPtr ccv = &tsv.current->ccv[i]; |
91 if (c<ccv->begin) { | 92 if (c<ccv->begin) { |
92 tsv = tsv.current->stateSkip(tsv); | 93 tsv = tsv.current->stateSkip(tsv); |
94 tsv.matchBegin = tsv.buff.buffptr; | |
93 goto next; | 95 goto next; |
94 } else if (c<=ccv->end) { | 96 } else if (c<=ccv->end) { |
95 // range matched. | 97 // range matched. |
96 if (ccv->w.word) { | 98 if (ccv->w.word) { |
97 // match the word. | 99 // match the word. |
101 tsv.current = ccv->tState; | 103 tsv.current = ccv->tState; |
102 } else { | 104 } else { |
103 tsv.current = nextTState(ccv->state,tsv.tg); | 105 tsv.current = nextTState(ccv->state,tsv.tg); |
104 ccv->tState = tsv.current; | 106 ccv->tState = tsv.current; |
105 } | 107 } |
106 // tsv = tsv.current->stateContinue(tsv); | 108 tsv = tsv.current->stateMatch(tsv); |
107 goto next; | 109 goto next; |
108 } | 110 } |
109 } | 111 } |
110 tsv = tsv.current->stateSkip(tsv); | 112 tsv = tsv.current->stateSkip(tsv); |
113 tsv.matchBegin = tsv.buff.buffptr; | |
111 } | 114 } |
112 *tsvp = tsv; | 115 *tsvp = tsv; |
113 return *tsvp; | 116 return *tsvp; |
114 } | 117 } |
115 | 118 |
116 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { | 119 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { |
117 TSValue tsv; | 120 TSValue tsv; |
118 tsv.buff = buff; | 121 tsv.buff = buff; |
119 tsv.tg = tg; | 122 tsv.tg = tg; |
120 tsv.result = NULL; | 123 tsv.blk = NULL; |
121 tsv.tg->stateSkip = stateSkip; | 124 tsv.tg->stateSkip = stateSkip; |
122 tsv.tg->stateMatch = stateMatch; | 125 tsv.tg->stateMatch = stateMatch; |
123 tsv.tg->stateNothing = stateNothing; | 126 tsv.tg->stateNothing = stateNothing; |
127 tsv.matchBegin = tsv.matchEnd = NULL; | |
124 tsv.current = generateTState(tg->stateList,tg); | 128 tsv.current = generateTState(tg->stateList,tg); |
125 tg->stateStart = NEW(State); | 129 tg->stateStart = NEW(State); |
126 *tg->stateStart = *tg->stateList; | 130 *tg->stateStart = *tg->stateList; |
127 tg->stateStart->accept = false; // Start state never accept | 131 tg->stateStart->accept = false; // Start state never accept |
128 generateTState(tg->stateStart,tg); | 132 generateTState(tg->stateStart,tg); |