view regexParser/cerium/ppe/Print.cc @ 297:c5a7caa37f61

fix cerium first match
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 02 Feb 2016 11:58:59 +0900
parents 948428caf616
children 27414e6fb33c
line wrap: on
line source

#include <stdio.h>
#include <string.h>
#include "Print.h"
#include "Func.h"
#include "FileMapReduce.h"
#include "regexParser.h"
#include "CeriumMain.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);
    
    int out_size = w->division_out_size / sizeof(unsigned long long);
    int out_task_num = w->task_num;
    ResultPtr prev = NULL;
    for (int i = 0; i < out_task_num ; i++) {
        ResultPtr r = (ResultPtr)w->o_data[i*out_size+0];
        if (r == NULL) {
            prev = NULL;
            continue;
        }
        StatePtr blockBegin = (StatePtr)w->o_data[i*out_size+1];
        if (prev) {
            if (i >= out_task_num) break; 
            // 最後のブロックでなく、前の prevBlockEnd が state 1 でない場合)
            StatePtr prevBlockEnd = (StatePtr)w->o_data[i*out_size-1];
#if 0
printf("task %d prev begin : %p r->begin : %p r->end : %p\n", i,prev->begin,r->begin,r->end);
printf("nextblockBegin : %lx prevBlockEnd : %lx : string ",blockBegin->bitState.bitContainer,prevBlockEnd->bitState.bitContainer);
fwrite(r->begin,r->end - r->begin-1,1,stdout);
printf(" match %d\n", ((prevBlockEnd->bitState.bitContainer & ~blockBegin->bitState.bitContainer)==0)? 1 : 0  );
#endif
            if ((prevBlockEnd->bitState.bitContainer & ~blockBegin->bitState.bitContainer)==0) {
                // 前のブロックの matchBegin から最初 result の end までがマッチ
                fwrite(prev->begin,r->end - prev->begin,1,stdout);
// printf("####");
                if (!r->continued) puts("");
            }
            r = r->next;
// printf("%p\n",r);
        } else {
            if ((blockBegin->bitState.bitContainer & 1)!=1) r = r->next;
        }
        prev = resultPrint(r,"Print");
    }
    return 0;
}