view regexParser/cerium/ppe/Print.cc @ 266:e51cac73e42a

CeriumGrep start
author masa
date Thu, 28 Jan 2016 21:14:34 +0900
parents
children 5aa9d01926f1
line wrap: on
line source

#include <stdio.h>
#include <string.h>
#include "Print.h"
#include "Func.h"
#include "FileMapReduce.h"

#define STATUS_NUM 2
/* これは必須 */
SchedDefineTask1(Print,run_print);

static int
run_print(SchedTask *s, void *rbuf, void *wbuf)
{
    MapReduce *w = (MapReduce*)s->get_input(0);
    
    unsigned char* buff = (unsigned char*)w->i_data;
    int out_size = w->division_out_size / sizeof(unsigned long long);
    ResultPtr prev = NULL;
    for (int i = 0; i < out_task_num ; i++) {
        ResultPtr *idata = (ResultPtr*)w->o_data[i*3+0];
        StatePtr *blockEnd = (StatePtr)w->o_data[i*3+2];
        StatePtr *blockBegin = (StatePtr)w->o_data[i*3+4]; // next Block's blockBegin.
        ResultPtr r = idata[i*out_size];
        if (prev && i != out_task_num-1) {
            // 最後のブロックでなく、前の blockEnd が state 1 でない場合)
            if (blockBegin->bi.bitContainer & blockEnd->bi.bitContainer) {
                // 前のブロックの matchBegin から最初 result の end までがマッチ
                fwrite(prev->result,r->end - prev->begin,1,stdout);
            }
            r = r->next;
        }
        for (;r;r = r->next) {
            if (r->end == NULL) {
                prev = r;
                break;
            }
            fwrite(r->begin,r->end - r->begin,1,stdout);
            puts("\n");
        }
    }
    return 0;
}