Mercurial > hg > Applications > Grep
view regexParser/threadedSearch.cc @ 247:96c2507fd22d
fix
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 22 Jan 2016 18:37:04 +0900 |
parents | 58de1744d7a9 |
children | 2b1fbfb92d54 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "regexParser.h" #include "subsetConstruction.h" struct tsValue; typedef struct ccv { unsigned long begin; unsigned long end; BitVector state; struct tState *tState; } *CCV; void stateSkip(TSValue tsv); typedef struct tState { State *state; void stateSkip(tsValue); int ccvSize; CCV ccv; } TState, *TStatePtr; typedef struct result { unsigned char begin; unsigned char end; struct result *next; } Result, *ResultPtr; typedef struct tsValue { Buffer buff; ResultPtr result; State *stateArray; TState *current; TState *blockBegin; TState *blockEnd; } TSValue, *TSValuePtr; void stateSkip(TSValue tsv) { tsv.buff.matchBegin = tsv.buff.buffptr; tsv.current->stateSkip(tsv); } TStatePtr generateTState(State 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; } 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++) { if (c<tsv.current->ccv[i].begin) tsv.current->stateSkip(tsv); else if (c<=tsv.current->ccv[i].end) { TStatePtr current = tsv.current->ccv[i].tState; if (current == NULL) { current = generateTState(tsv.stateArray[tsv.current->ccv[i].state.bitContainer]); tsv.current->ccv[i].tState = current; } tsv.current = tsv.current->ccv[i].tState; goto next; } } tsv.current->stateSkip(tsv); } }