annotate example/word_count/spe/Exec.cc @ 1130:5addc6c1d5c4 draft

fix.
author root@dolphins.cr.ie.u-ryukyu.ac.jp
date Sun, 13 Feb 2011 22:34:44 +0900
parents 47ca99c5cf84
children 3a57dd6e4cb5
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: 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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
17 int word_num = 0;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
47ca99c5cf84 use MailManager
yutaka@localhost.localdomain
parents: 946
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
31 word_num += word_flag;
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
32 word_flag = 0;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
33 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
34 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
35
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
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
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
40
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
41 o_data[0] = (unsigned long long)word_num;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
42 o_data[1] = (unsigned long long)line_num;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
43
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
44 return 0;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
45 }