annotate example/word_count3/spe/Exec.cc @ 508:217d7c53442b draft

add word_count3
author yutaka@henri.cr.ie.u-ryukyu.ac.jp
date Tue, 20 Oct 2009 16:28:16 +0900
parents
children 0e91ddaad798
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
508
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include <stdio.h>
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 #include <string.h>
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 #include "Exec.h"
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 #include "Func.h"
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 /* これは必須 */
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 SchedDefineTask(Exec);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 static int
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 run(SchedTask *s, void *rbuf, void *wbuf)
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12 char *i_data = (char*)s->get_input(rbuf, 0);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
14 int length = s->get_param(0);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 int word_flag = s->get_param(1);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 int word_num = 0;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
17 int line_num = 0;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 int i;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 /*先頭の文字まで、飛ぶルーチン*/
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 for(i = 0; i < length; i++) {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
22 if ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
23 //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
24 break;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
25 }
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
26 //s->printf("[SPE%d]%c",id,i_data[start_num]);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
27 word_num += word_flag;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
28 word_flag = 0;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
29 line_num += (i_data[i] == 0x0A);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
30 }
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
31
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
32 word_flag = 0;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
33
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 for (; i < length; i++) {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 //s->printf("[SPE%d]%c",id,i_data[i]);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 if (i_data[i] == 0x20) {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 //s->printf("スペース\n");
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41 word_flag = 1;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
42 }
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 else if (i_data[i] == 0x0A) {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 //s->printf("改行\n");
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 line_num += 1;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 word_flag = 1;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 }
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 else {
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 word_num += word_flag;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 word_flag = 0;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 }
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 }
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 word_num += word_flag;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 //s->printf("%d %d\n",word_num,line_num);
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 o_data[0] = (unsigned long long)word_num;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 o_data[1] = (unsigned long long)line_num;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 return 0;
217d7c53442b add word_count3
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 }