annotate example/word_count/spe/Exec.cc @ 1021:f8e9c985e2a8

use MailManager
author yutaka@localhost.localdomain
date Sun, 07 Nov 2010 22:10:29 +0900
parents a8b6ee80c108
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
393
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
1 #include <stdio.h>
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
2 #include <string.h>
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
3 #include "Exec.h"
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
4 #include "Func.h"
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
5
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
6 /* これは必須 */
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
7 SchedDefineTask(Exec);
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
11 {
946
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
12 char *i_data = (char *)rbuf;
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
13 unsigned long long *o_data = (unsigned long long*)wbuf;
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
14 unsigned long long *head_tail_flag = o_data +2;
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
15 int length = (int)s->get_inputSize(0);
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
16 int word_flag = 0;
393
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
17 int word_num = 0;
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
18 int line_num = 0;
946
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
19 int i = 0;
1021
f8e9c985e2a8 use MailManager
yutaka@localhost.localdomain
parents: 946
diff changeset
20
946
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
21 head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A);
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
22 word_num -= 1-head_tail_flag[0];
393
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
23
946
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
24 for (; i < length; i++) {
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
25 if (i_data[i] == 0x20) {
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
26 word_flag = 1;
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
27 } else if (i_data[i] == 0x0A) {
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
28 line_num += 1;
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
29 word_flag = 1;
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
30 } else {
666
4615489c5faa simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
31 word_num += word_flag;
4615489c5faa simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
32 word_flag = 0;
393
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
33 }
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
34 }
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
35
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
36 word_num += word_flag;
946
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
37 head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A);
393
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
38
946
a8b6ee80c108 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 804
diff changeset
39 // s->printf("SPE word %d line %d\n",word_num,line_num);
393
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
40
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
41 o_data[0] = (unsigned long long)word_num;
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
42 o_data[1] = (unsigned long long)line_num;
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
43
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
44 return 0;
72b73beb3325 add word_count
e065725@localhost.localdomain
parents:
diff changeset
45 }