view example/regex_masa/ppe/Exec.cc @ 1576:33731c160268 draft

ppe/Exec.cc L29 || から && に訂正
author Masa <e085726@ie.u-ryukyu.ac.jp>
date Fri, 22 Mar 2013 21:26:00 +0900
parents fcb6ce3ba110
children be59aef19a22
line wrap: on
line source

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

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

static int
run(SchedTask *s, void *rbuf, void *wbuf)
{
    char *i_data = (char *)rbuf;
    unsigned long long *o_data = (unsigned long long*)wbuf;
    unsigned long long *head_tail_flag = o_data +2;
    int length = (int)s->get_inputSize(0);
    int word_flag = 0;
    int word_num = 0;
    int line_flag = 0;
    int line_num = 0;
    int i = 0;
    //b以外が先頭の時、word_num - 1
    head_tail_flag[0] = (i_data[0] != 0x62);
    //head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A);
    word_num -= 1-head_tail_flag[0];

    //i_data[length - 1] = 0x61;  //分割されたファイルのラストがaのときに固まってしまう

    for (; i < length; i++) {
        if (i_data[i] == 0x61 && i_data[i+1] == 0x62) { //abと文字列が並んでいるとき
            word_flag = 1;
            line_flag = 1;
        
        } else if (i_data[i] == 0x20) { //空白 
            word_num += word_flag;
            word_flag = 0;
        } else if (i_data[i] == 0x0A) { // 改行
            line_num += line_flag;
            word_num += word_flag;
            line_flag = 0;
            word_flag = 0;
        }
    }

    //head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A);
    head_tail_flag[1] = (i_data[i-1] != 0x61);

    s->printf("SPE include 'ab' %d lines. %d words. \n",line_num,word_num);

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

    return 0;
}