Mercurial > hg > Applications > Grep
annotate regexParser/grepWalk.cc @ 272:5aa9d01926f1
Cerium version no compile errors
author | kono |
---|---|
date | Fri, 29 Jan 2016 20:38:18 +0900 (2016-01-29) |
parents | e51cac73e42a |
children | 948428caf616 |
rev | line source |
---|---|
231 | 1 #include <stdio.h> |
2 | |
3 #include "grepWalk.h" | |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
4 #include "subsetConstruction.h" |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
5 |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
6 void grepMatch(TransitionGeneratorPtr tg,Buffer buff); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
7 void grep(TransitionGeneratorPtr tg,Buffer buff); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
8 void grepSkip(TransitionGeneratorPtr tg,Buffer buff); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
9 |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
10 void grepMatch(TransitionGeneratorPtr tg,Buffer buff) { |
266 | 11 fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin-1,1,stdout); |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
12 puts("\n"); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
13 grepSkip(tg,buff); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
14 } |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
15 |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
16 void grep(TransitionGeneratorPtr tg,Buffer buff,unsigned long d) { |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
17 unsigned char c = *buff.buffptr++; |
235
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
18 if (c=='\0') return; |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
19 StatePtr state = tg->stateList; |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
20 |
237 | 21 while (state->bitState.bitContainer != d) state = state->next; // 配列へのアクセスへ変更 |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
22 CharClassWalkerPtr ccw = createCharClassWalker(state->cc); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
23 CharClassPtr cc = NULL; |
237 | 24 bool found = false; |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
25 while (hasNext(ccw)) { |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
26 cc = getNext(ccw); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
27 unsigned long begin = cc->cond.range.begin; |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
28 unsigned long end = cc->cond.range.end; |
235
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
29 if (begin == end) { |
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
30 if (c == begin) found = true; |
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
31 else found = false; |
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
32 } else { |
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
33 if (c < begin) found = false; |
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
34 else if (c < end) found = true; |
4aab1e93a971
fix condition grepWalk.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
234
diff
changeset
|
35 } |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
36 if (found == true) break; |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
37 } |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
38 |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
39 if (found == false) { |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
40 grepSkip(tg,buff); |
242
6aebc4d7dd75
fix condition generateSequentialSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
237
diff
changeset
|
41 } else if (found == true && (cc->nextState.bitContainer | 2)) { // Accept |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
42 grepMatch(tg,buff); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
43 } else { |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
44 grep(tg,buff,cc->nextState.bitContainer); |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
45 } |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
46 } |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
47 |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
48 void grepSkip(TransitionGeneratorPtr tg,Buffer buff) { |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
49 buff.matchBegin = buff.buffptr; |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
50 grep(tg,buff,1); // 1 is initState |
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
51 } |
231 | 52 |
232
1a34e702776a
add fileread.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
231
diff
changeset
|
53 void grepWalk(TransitionGeneratorPtr tg, Buffer buff) { |
234
df4d04b3c34a
implement grepWalk (not confirm correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
232
diff
changeset
|
54 grepSkip(tg,buff); |
231 | 55 } |