Mercurial > hg > Game > Cerium
annotate example/word_count/ppe/Exec.cc @ 666:f02b3338b91b draft
simplify word_count
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 02:11:31 +0900 |
parents | beb0f17c19f9 |
children | 043c98537bc5 |
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
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
9 static int |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
10 run(SchedTask *s, void *rbuf, void *wbuf) |
393 | 11 { |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
12 char *i_data = (char*)s->get_input(rbuf, 0); |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
13 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
14 long length = (long)s->get_param(0); |
666 | 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
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
24 //s->printf("[SPE%d]%c",id,i_data[i]); |
393 | 25 |
26 if((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { | |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
27 //s->printf("文字 数 = %d\n", word_num + word_flag); |
393 | 28 word_num += word_flag; |
29 word_flag = 0; | |
30 } | |
31 | |
32 if (i_data[i] == 0x20) { | |
33 //printf("スペース\n"); | |
34 word_flag = 1; | |
35 } | |
36 | |
37 if (i_data[i] == 0x0A) { | |
38 //printf("改行\n"); | |
39 line_num += 1; | |
40 word_flag = 1; | |
41 } | |
42 | |
43 } | |
44 | |
45 word_num += word_flag; | |
46 | |
664 | 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 } |