annotate example/regex/ppe/Exec.cc @ 1204:ffef576db4b3 draft

modify example/regex/
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sat, 16 Jul 2011 17:25:40 +0900
parents 7b866a392adc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1198
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <string.h>
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "Exec.h"
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "Func.h"
1200
7b866a392adc mege 1179
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 1199 1198
diff changeset
5 #include "grep.h"
1198
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 /* これは必須 */
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 SchedDefineTask(Exec);
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
1199
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 typedef unsigned char UCHAR;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 typedef unsigned char* UCHARP;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 #define __REGEX__ "h.s"
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 UCHARP get_line_beg(UCHARP p, UCHARP beg) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 while(p > beg) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if ((*--p) == '\n') return p+1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 return beg;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 UCHARP get_word_beg(UCHARP p, UCHARP beg) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 while(p > beg) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 if ((*--p) == ' ') return p+1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 return beg;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 void print_line(UCHARP beg, UCHARP end) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 fwrite(beg, sizeof(char), (end - beg + 1), stdout);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 void stdingrep(ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 char buf_[BUFSIZ];
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 UCHARP buf, beg, end;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 buf = beg = (UCHARP) buf_;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 while (fgets(buf_, BUFSIZ, stdin) != NULL) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 env->count = 0;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 end = buf + strlen(buf_) - 1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 s0(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 return filter(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 static const UCHARP key = (UCHARP)"h";
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 int i, len = 1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 loop:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 while ((buf = (UCHARP)memchr(buf, key[0], end-buf))) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 for(i = 1; i < len; i++) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 if (buf[i] != key[i]) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 buf++;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 goto loop;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 goto next;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 return reject(beg, end, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 next:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 return s1(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 UCHARP c = buf++;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 if (buf > end) return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 switch(*c) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 case 10:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 case 104:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 return s2(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 default:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 return s1(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 UCHARP c = buf++;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if (buf > end) return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 switch(*c) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 case 10:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 case 104:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 return s4(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 default:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 return s3(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 UCHARP c = buf++;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 if (buf > end) return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 switch(*c) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 case 10:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 case 104:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 return s2(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 case 115:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 return s5(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 default:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 return s1(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 UCHARP c = buf++;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 if (buf > end) return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 switch(*c) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 case 10:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 return reject(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 case 104:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 return s2(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 case 115:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 return s5(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 default:
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 return s3(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 break;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 return accept(beg, buf - 1, end, env);}
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 return accept(beg, buf - 1, end, env);}
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 void
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 if (buf < beg) buf = beg;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 // UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, ' ', (end - buf)) : NULL;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 if (env->print_count) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 env->count++;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 if (ret == NULL) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 if (env->print_filename) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 printf("%s:", env->filename);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 printf("%d\n", env->count);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 return;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 beg = buf = ret + 1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 } else {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 // beg = get_line_beg(buf, beg);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 beg = get_word_beg(buf, beg);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 if (env->print_filename) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 printf("%s:", env->filename);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 if (ret == NULL) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 print_line(beg, end);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 return;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 print_line(beg, ret);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 beg = buf = ret + 1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 return s0(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 void
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 UCHARP ret;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 if (buf >= end) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 ret = NULL;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 } else {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 if (*(buf-1) == '\n') {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 ret = buf-1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 } else {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 // ret = (UCHARP)memchr(buf, '\n', (end - buf));
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 ret = (UCHARP)memchr(buf, ' ', (end - buf));
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 if (ret == NULL) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 if (env->print_count) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 if (env->print_filename) {
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 printf("%s:", env->filename);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 printf("%d\n", env->count);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 return;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 beg = buf = ret + 1;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 return s0(beg, buf, end, env);
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 }
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
1198
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 static int
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 run(SchedTask *s, void *rbuf, void *wbuf)
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 {
1199
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 // char *i_data = (char *)rbuf;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 char *i_data = (char *)s->get_input(rbuf, 0);
1198
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 int length = (int)s->get_inputSize(0);
1204
ffef576db4b3 modify example/regex/
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 1200
diff changeset
219 ENV *env = (ENV*)s->get_input(rbuf, 1);
1199
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 UCHARP beg, buf, end;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 beg = buf = (UCHARP)i_data;
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 end = beg + length - 1;
1198
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
1199
e55b9d2cb33e add regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 s0(beg, buf, end, (ENVP)env);
1198
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 return 0;
2abd68a1ac2a add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 }