661
|
1 #include <stdio.h>
|
|
2 #include <string.h>
|
|
3 #include "Exec.h"
|
|
4 #include "Func.h"
|
|
5
|
|
6 /* これは必須 */
|
|
7 SchedDefineTask(Exec);
|
|
8
|
|
9 static int
|
|
10 run(SchedTask *s, void *rbuf, void *wbuf)
|
|
11 {
|
|
12 char *i_data = (char*)s->get_input(rbuf, 0);
|
|
13 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
|
|
14 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/
|
|
15 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1);
|
|
16 int length = (long)s->get_param(0);
|
|
17 int word_flag = 0;
|
|
18 int word_num = 0;
|
|
19 int line_num = 0;
|
665
|
20 int i = 0;
|
661
|
21
|
|
22 /*文字なら1,スペースか改行なら0*/
|
|
23 head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A);
|
665
|
24 word_num -= 1- head_tail_flag[0];
|
661
|
25
|
|
26 for (; i < length; i++) {
|
|
27
|
|
28 //s->printf("[SPE%d]%c",id,i_data[i]);
|
|
29
|
|
30
|
|
31 if (i_data[i] == 0x20) {
|
|
32 //s->printf("スペース\n");
|
|
33 word_flag = 1;
|
|
34 }
|
|
35
|
|
36 else if (i_data[i] == 0x0A) {
|
|
37 //s->printf("改行\n");
|
|
38 line_num += 1;
|
|
39 word_flag = 1;
|
|
40 }
|
|
41
|
|
42 else {
|
|
43 word_num += word_flag;
|
|
44 word_flag = 0;
|
|
45 }
|
|
46
|
|
47 }
|
|
48
|
|
49 word_num += word_flag;
|
|
50 /*文字なら1,スペースか改行なら0*/
|
|
51 //printf("last word %c",i_data[i-1]);
|
|
52 head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A);
|
|
53
|
664
|
54 // s->printf("PPE word %d line %d\n",word_num,line_num);
|
661
|
55
|
|
56 o_data[0] = (unsigned long long)word_num;
|
|
57 o_data[1] = (unsigned long long)line_num;
|
|
58
|
|
59 return 0;
|
|
60 }
|