Mercurial > hg > Members > masakoha > testcode
view regexParser/threadedSearch.cc @ 252:2b276fdd99bd
remove error (not working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jan 2016 11:48:06 +0900 |
parents | e22e3475f664 |
children | 21b9ba76f91b |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "regexParser.h" #include "subsetConstruction.h" void stateSkip(TSValue tsv) { tsv.buff.matchBegin = tsv.buff.buffptr; tsv.current->stateSkip(tsv); } TStatePtr generateTState(StatePtr state) { TStatePtr tState = NEW(TState); int ccvSize = 0; CharClassWalkerPtr ccw = createCharClassWalker(state->cc); while (hasNext(ccw)) { CharClassPtr cc = getNext(ccw); ccvSize++; } if (ccvSize == 0) return tState; else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize); ccw = createCharClassWalker(state->cc); int i = 0; while (hasNext(ccw)) { CharClassPtr cc = getNext(ccw); unsigned long begin = cc->cond.range.begin; unsigned long end = cc->cond.range.end; struct ccv *ccv = &tState->ccv[i++]; ccv->begin = begin; ccv->end = end; ccv->tState = NULL; ccv->state = cc->nextState; ccv->w = cc->cond.w; } free(ccw); return tState; } void tSearch(TSValue tsv) { next: while (tsv.buff.buffptr < tsv.buff.buffend) { unsigned char c = *tsv.buff.buffptr++; for (int i = 0; i < tsv.current->ccvSize; i++) { CCVPtr ccv = &tsv.current->ccv[i]; if (c<ccv->begin) tsv.current->stateSkip(tsv); else if (c<=ccv->end) { // range matched. if (ccv->w.word) { // match the word. // if (not match) continue; } TStatePtr current = ccv->tState; if (current == NULL) { // create tSearch in next state. StatePtr state = tsv.tg->stateArray[ccv->state.bitContainer]; if (state == NULL) { // on the fly subset construction. state = createState(tsv.tg,state->bitState); tsv.tg->stateArray[state->bitState.bitContainer] = state; determinize(state,tsv.tg); } if (state->tState == NULL) { current = generateTState(state); ccv->tState = current; } else { ccv->tState = state->tState; } } tsv.current = ccv->tState; goto next; } } tsv.current->stateSkip(tsv); } }