Mercurial > hg > Applications > Grep
view regexParser/generateSequentialSearch.cc @ 241:87ad91af8a15
turn initialization in charclasswalk
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Jan 2016 20:28:40 +0900 |
parents | 2081b9d6a179 |
children | 6aebc4d7dd75 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "generateSequentialSearch.h" #include "subsetConstruction.h" void exportState(TransitionGeneratorPtr tg) { StatePtr state = tg->stateList; FILE *fp = fopen("state.cc","w"); if (fp==NULL) { perror(""); fprintf(stderr,"cannot write state.cc\n"); exit(1); } for (;state;state = state->next) { fprintf(fp,"void state%lx(Buffer buff);\n",state->bitState.bitContainer); } fputs("\n",fp); for (state = tg->stateList;state;state = state->next) { fprintf(fp,"void state%lx(Buffer buff) {\n",state->bitState.bitContainer); if (state->bitState.bitContainer == 2) { // Accept fputs(" stateMatch(buff);\n",fp); } else { // not Accept fputs(" if (buff.buffptr >= buff.buffend) return;\n",fp); fputs(" unsigned char c = *buff.buffptr++;\n",fp); CharClassWalkerPtr ccw = createCharClassWalker(state->cc); bool flag = true; while (hasNext(ccw)) { CharClassPtr cc = getNext(ccw); unsigned long begin = cc->cond.range.begin; unsigned long end = cc->cond.range.end; BitVector bi = cc->nextState; if (flag) { flag = false; fputs(" ",fp); } else { fputs(" else ",fp); } if (begin == end) { fprintf(fp,"if (c=='%c') state%lx(buff);\n",(unsigned char)begin, bi.bitContainer); } else { fprintf(fp,"if (c<'%c') stateSkip(buff);\n",(unsigned char)begin); fprintf(fp," else if (c<='%c') state%lx(buff);\n",(unsigned char)end, bi.bitContainer); } } free(ccw); if (state->bitState.bitContainer & 2) { fprintf(fp," else stateMatch(buff);\n"); } else { fprintf(fp," else stateSkip(buff);\n"); } } fputs("}\n\n",fp); } fclose(fp); }