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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
1 #include <stdio.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
2 #include <string.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
3 #include "Exec.h"
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
4 #include "Func.h"
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
5
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
6 /* これは必須 */
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
7 SchedDefineTask(Exec);
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 664
diff changeset
15 long word_flag = 1-(long)s->get_param(1);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
16 int word_num = 0;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
17 int line_num = 0;
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 664
diff changeset
18 int i ;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
19
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 664
diff changeset
20 word_num -= word_flag;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
21
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 664
diff changeset
22 for (i=0; i < length; i++) {
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
25
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
28 word_num += word_flag;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
29 word_flag = 0;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
30 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
31
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
32 if (i_data[i] == 0x20) {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
33 //printf("スペース\n");
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
34 word_flag = 1;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
35 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
36
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
37 if (i_data[i] == 0x0A) {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
38 //printf("改行\n");
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
39 line_num += 1;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
40 word_flag = 1;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
41 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
42
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
43 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
44
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
45 word_num += word_flag;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
46
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
47 // printf("PPE word %d line %d\n",word_num,line_num);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
48
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
49 o_data[0] = (unsigned long long)word_num;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
50 o_data[1] = (unsigned long long)line_num;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
51
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
52 return 0;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
53 }