Mercurial > hg > Members > e085722 > Cerium
comparison example/grep/spe/Exec.cc @ 0:04e28d8d3c6f
first commit
author | Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Nov 2010 01:23:25 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:04e28d8d3c6f |
---|---|
1 #include <stdio.h> | |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
5 #include "WordGrep.h" | |
6 | |
7 /* これは必須 */ | |
8 SchedDefineTask(Exec); | |
9 int str_search(char *r_data,char *sstr,int point); | |
10 | |
11 //実際のタスク内での処理 | |
12 static int run(SchedTask *s, void *rbuf, void *wbuf){ | |
13 Grep *r_buf = *(Grep**)rbuf; | |
14 int *o_data = (int*)wbuf; | |
15 *o_data = 0; | |
16 char *r_data = r_buf->read_buf; | |
17 char *sstr = r_buf->read_sstr; | |
18 int len_r_data = (int)strlen(r_data); | |
19 int len_sstr = (int)strlen(sstr); | |
20 printf("%s : %s\n",sstr,r_data); | |
21 int search = 0; | |
22 int s_next = 0; | |
23 int hits = 0; | |
24 | |
25 while(search+len_sstr <= len_r_data){ | |
26 s_next = len_sstr; | |
27 for(int i = 0;i<len_sstr;i++){ | |
28 if(sstr[len_sstr-i-1] == r_data[len_sstr+search-1]){ | |
29 if(i == 0){ | |
30 s_next = len_sstr; | |
31 if(strncmp(r_data+search,sstr,len_sstr) == 0){ | |
32 printf(" hit!->"); | |
33 for(int j = 0;j < 10;j++){ | |
34 if(r_data[search+j] == 0){ | |
35 break; | |
36 }else if(r_data[search+j] == '\n') { | |
37 s->printf(" "); | |
38 }else{ | |
39 s->printf("%c",r_data[search+j]); | |
40 } | |
41 } | |
42 printf("\n"); | |
43 hits++; | |
44 break; | |
45 } | |
46 }else{ | |
47 s_next = i; | |
48 } | |
49 } | |
50 } | |
51 search += s_next; | |
52 } | |
53 o_data[0] = hits; | |
54 return 0; | |
55 } |