Mercurial > hg > Applications > Grep
diff regexParser/threadedSearch.cc @ 292:868f01f1ba8e
maximum match
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 01 Feb 2016 21:52:57 +0900 |
parents | f2491681914e |
children | 948428caf616 |
line wrap: on
line diff
--- a/regexParser/threadedSearch.cc Mon Feb 01 12:20:16 2016 +0900 +++ b/regexParser/threadedSearch.cc Mon Feb 01 21:52:57 2016 +0900 @@ -13,16 +13,17 @@ static TSValue stateSkip(TSValue tsv) { tsv.current = tsv.tg->stateStart->tState; - tsv.buff.matchBegin = tsv.buff.buffptr; + if (tsv.matchEnd) { + fwrite(tsv.matchBegin,tsv.matchEnd-tsv.matchBegin,1,stdout); + puts(""); + tsv.matchEnd = NULL; + } return tsv; } static TSValue stateMatch(TSValue tsv) { - fwrite(tsv.buff.matchBegin,tsv.buff.buffptr-tsv.buff.matchBegin-1,1,stdout); - puts(""); - tsv.buff.buffptr--; - tsv = stateSkip(tsv); + tsv.matchEnd = tsv.buff.buffptr; // next char of the match return tsv; } @@ -36,12 +37,12 @@ ccvSize++; } tState->ccvSize = ccvSize; - if (state->accept && state != tg->stateList ) { - tState->stateSkip = tg->stateMatch; - tState->stateContinue = tg->stateNothing; + if (state->accept) { + tState->stateSkip = tg->stateSkip; + tState->stateMatch = tg->stateMatch; } else { tState->stateSkip = tg->stateSkip; - tState->stateContinue = tg->stateNothing; + tState->stateMatch = tg->stateNothing; } if (ccvSize == 0) { tState->ccv = NULL; @@ -90,6 +91,7 @@ CCVPtr ccv = &tsv.current->ccv[i]; if (c<ccv->begin) { tsv = tsv.current->stateSkip(tsv); + tsv.matchBegin = tsv.buff.buffptr; goto next; } else if (c<=ccv->end) { // range matched. @@ -103,11 +105,12 @@ tsv.current = nextTState(ccv->state,tsv.tg); ccv->tState = tsv.current; } - // tsv = tsv.current->stateContinue(tsv); + tsv = tsv.current->stateMatch(tsv); goto next; } } tsv = tsv.current->stateSkip(tsv); + tsv.matchBegin = tsv.buff.buffptr; } *tsvp = tsv; return *tsvp; @@ -117,10 +120,11 @@ TSValue tsv; tsv.buff = buff; tsv.tg = tg; - tsv.result = NULL; + tsv.blk = NULL; tsv.tg->stateSkip = stateSkip; tsv.tg->stateMatch = stateMatch; tsv.tg->stateNothing = stateNothing; + tsv.matchBegin = tsv.matchEnd = NULL; tsv.current = generateTState(tg->stateList,tg); tg->stateStart = NEW(State); *tg->stateStart = *tg->stateList;