Mercurial > hg > Members > kono > Cerium
annotate example/word_count/spe/Exec.cc @ 666:4615489c5faa
simplify word_count
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 02:11:31 +0900 |
parents | 8a807e2f64f8 |
children | ccf78a465459 |
rev | line source |
---|---|
393 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
5 | |
6 /* これは必須 */ | |
7 SchedDefineTask(Exec); | |
8 | |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
9 static int |
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
10 run(SchedTask *s, void *rbuf, void *wbuf) |
393 | 11 { |
666 | 12 char *i_data = (char*)s->get_input(rbuf, 0); |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
13 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
666 | 14 long length = (long)s->get_param(0); |
15 long word_flag = 1-(long)s->get_param(1); | |
393 | 16 int word_num = 0; |
17 int line_num = 0; | |
666 | 18 int i ; |
393 | 19 |
666 | 20 word_num -= word_flag; |
393 | 21 |
666 | 22 for (i=0; i < length; i++) { |
393 | 23 |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
24 //s->printf("[SPE%d]%c",id,i_data[i]); |
393 | 25 |
666 | 26 if((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { |
27 //s->printf("文字 数 = %d\n", word_num + word_flag); | |
28 word_num += word_flag; | |
29 word_flag = 0; | |
30 } | |
393 | 31 |
666 | 32 if (i_data[i] == 0x20) { |
33 //printf("スペース\n"); | |
393 | 34 word_flag = 1; |
35 } | |
36 | |
666 | 37 if (i_data[i] == 0x0A) { |
38 //printf("改行\n"); | |
393 | 39 line_num += 1; |
40 word_flag = 1; | |
41 } | |
42 | |
43 } | |
44 | |
45 word_num += word_flag; | |
46 | |
666 | 47 // printf("PPE word %d line %d\n",word_num,line_num); |
393 | 48 |
49 o_data[0] = (unsigned long long)word_num; | |
50 o_data[1] = (unsigned long long)line_num; | |
51 | |
52 return 0; | |
53 } |