Mercurial > hg > Game > Cerium
annotate example/word_count_test/spe/Exec.cc @ 665:77d9e3bc25b2 draft
word_count_test
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 01:16:34 +0900 |
parents | beb0f17c19f9 |
children | ae1d1eebf9ff |
rev | line source |
---|---|
658 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
5 | |
6 /* これは必須 */ | |
7 SchedDefineTask(Exec); | |
8 | |
9 static int | |
10 run(SchedTask *s, void *rbuf, void *wbuf) | |
11 { | |
665 | 12 char *i_data = (char*)s->get_input(rbuf, 0); |
658 | 13 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
14 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ | |
15 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); | |
16 int length = (long)s->get_param(0); | |
17 int word_flag = 0; | |
18 int word_num = 0; | |
19 int line_num = 0; | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
20 int i = 0; |
658 | 21 |
22 /*文字なら1,スペースか改行なら0*/ | |
665 | 23 head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); |
24 word_num -= 1-head_tail_flag[0]; | |
658 | 25 |
26 for (; i < length; i++) { | |
27 | |
28 //s->printf("[SPE%d]%c",id,i_data[i]); | |
29 | |
30 | |
665 | 31 if (i_data[i] == 0x20) { |
658 | 32 //s->printf("スペース\n"); |
33 word_flag = 1; | |
34 } | |
35 | |
665 | 36 else if (i_data[i] == 0x0A) { |
658 | 37 //s->printf("改行\n"); |
38 line_num += 1; | |
39 word_flag = 1; | |
40 } | |
41 | |
42 else { | |
43 word_num += word_flag; | |
44 word_flag = 0; | |
45 } | |
46 | |
47 } | |
48 | |
49 word_num += word_flag; | |
50 /*文字なら1,スペースか改行なら0*/ | |
51 //printf("last word %c",i_data[i-1]); | |
665 | 52 head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A); |
658 | 53 |
665 | 54 // s->printf("PPE word %d line %d\n",word_num,line_num); |
658 | 55 |
56 o_data[0] = (unsigned long long)word_num; | |
57 o_data[1] = (unsigned long long)line_num; | |
58 | |
59 return 0; | |
60 } |