Mercurial > hg > Game > Cerium
annotate example/word_count/spe/Exec.cc @ 1021:47ca99c5cf84 draft
use MailManager
author | yutaka@localhost.localdomain |
---|---|
date | Sun, 07 Nov 2010 22:10:29 +0900 |
parents | 852ed17d8af1 |
children | 3a57dd6e4cb5 |
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:
394
diff
changeset
|
9 static int |
839e34d0cc3c
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 { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
12 char *i_data = (char *)rbuf; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
13 unsigned long long *o_data = (unsigned long long*)wbuf; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
14 unsigned long long *head_tail_flag = o_data +2; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
15 int length = (int)s->get_inputSize(0); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
16 int word_flag = 0; |
393 | 17 int word_num = 0; |
18 int line_num = 0; | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
19 int i = 0; |
1021 | 20 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
21 head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
22 word_num -= 1-head_tail_flag[0]; |
393 | 23 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
24 for (; i < length; i++) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
25 if (i_data[i] == 0x20) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
26 word_flag = 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
27 } else if (i_data[i] == 0x0A) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
28 line_num += 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
29 word_flag = 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
30 } else { |
666 | 31 word_num += word_flag; |
32 word_flag = 0; | |
393 | 33 } |
34 } | |
35 | |
36 word_num += word_flag; | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
37 head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A); |
393 | 38 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
803
diff
changeset
|
39 // s->printf("SPE word %d line %d\n",word_num,line_num); |
393 | 40 |
41 o_data[0] = (unsigned long long)word_num; | |
42 o_data[1] = (unsigned long long)line_num; | |
43 | |
44 return 0; | |
45 } |