view example/word_count/ppe/Exec.cc @ 444:afbc6ec42c7f draft

test_render is not working...
author game@henri.cr.ie.u-ryukyu.ac.jp
date Fri, 25 Sep 2009 05:54:33 +0900
parents cb06748ba6cf
children 839e34d0cc3c
line wrap: on
line source

#include <stdio.h>
#include <string.h>
#include "Exec.h"
#include "Func.h"

/* これは必須 */
SchedDefineTask(Exec);

int
Exec::run(void *rbuf, void *wbuf)
{
    char *i_data = (char*)get_input(rbuf, 0);
    unsigned long long *o_data = (unsigned long long*)get_output(wbuf, 0);
    int length = get_param(0);
    int word_flag = get_param(1);
    int word_num = 0;
    int line_num = 0;
    int i;

    /*先頭の文字まで、飛ぶルーチン*/
    for(i = 0; i < length; i++) {
	if ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) {
	    //printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]);
	    break;
	}
	//printf("[SPE%d]%c",id,i_data[start_num]);
	word_num += word_flag;
	word_flag = 0;
	line_num += (i_data[i] == 0x0A);
    }

    word_flag = 0;

	for (; i < length; i++) {

	    //printf("[SPE%d]%c",id,i_data[i]);

	if((i_data[i] != 0x20) && (i_data[i] != 0x0A)) {
	    //printf("文字 数 = %d\n", word_num + word_flag);
	    word_num += word_flag;
	    word_flag = 0;
	}

	if (i_data[i] == 0x20) {
	    //printf("スペース\n");
	    word_flag = 1;
	}

	if (i_data[i] == 0x0A) {
	    //printf("改行\n");
	    line_num += 1;
	    word_flag = 1;
	}

    }

    word_num += word_flag;

    //printf("%d %d\n",word_num,line_num);

    o_data[0] = (unsigned long long)word_num;
    o_data[1] = (unsigned long long)line_num;

    return 0;
}