Annotation of researchv10no/cmd/gre/egstate.c, revision 1.1

1.1     ! root        1: #include       "re.h"
        !             2: #include       "lre.h"
        !             3: #include       "hdr.h"
        !             4: 
        !             5: #ifndef        MINSTATE
        !             6: #define        MINSTATE        32
        !             7: #endif
        !             8: 
        !             9: void
        !            10: eg_stateinit(re_re *r)
        !            11: {
        !            12:        r->statelim = MINSTATE;
        !            13:        r->states = 0;
        !            14:        r->threshhold = 2;
        !            15: }
        !            16: 
        !            17: void
        !            18: eg_clrstates(re_re *r)
        !            19: {
        !            20:        r->nstates = 0;
        !            21:        if(r->states == 0){
        !            22:                r->states = (State *)egmalloc(r->statelim*sizeof(State), "states");
        !            23:                if (!r->states)
        !            24:                        return;
        !            25:        }
        !            26: }
        !            27: 
        !            28: void
        !            29: eg_savestate(re_re *r, State *s)
        !            30: {
        !            31:        r->initialstate = s-r->states;
        !            32:        r->istate = r->states[r->initialstate]; /* save for reset */
        !            33:        r->istate.init = 1;
        !            34:        r->flushed = 0;
        !            35: }
        !            36: 
        !            37: State *
        !            38: eg_startstate(re_re *r)
        !            39: {
        !            40:        register i;
        !            41: 
        !            42:        if(r->flushed > r->threshhold){
        !            43:                int slim = r->statelim*2;
        !            44:                if(slim > 512)
        !            45:                        slim = 512;
        !            46:                if(slim > r->statelim){
        !            47:                        for(i = 0; i < r->statelim; i++)
        !            48:                                memset((char *)r->states[i].tab, 0, sizeof r->states[i].tab);
        !            49:                        r->states = (State *)egrealloc((char *)r->states,
        !            50:                                (r->statelim = slim)*sizeof(State), "states");
        !            51:                        if (!r->states)
        !            52:                                return 0;
        !            53:                }
        !            54:                r->flushed = 0;
        !            55:                r->threshhold++;
        !            56:                r->states[r->initialstate] = r->istate;
        !            57:                r->nstates = r->initialstate+1;
        !            58:        }
        !            59:        return(r->states+r->initialstate);
        !            60: }
        !            61: 
        !            62: eg_getstate(register re_re *r)
        !            63: {
        !            64:        if(r->nstates >= r->statelim){
        !            65:                r->nstates = r->initialstate+1;
        !            66:                r->states[r->initialstate] = r->istate;
        !            67:                (void)eg_posalloc(r, -1);
        !            68:                r->flushed++;
        !            69:        }
        !            70:        r->states[r->nstates].init = 0;
        !            71:        return(r->nstates++);
        !            72: }
        !            73: 
        !            74: State *
        !            75: eg_stateof(re_re *r, register Positionset *ps)
        !            76: {
        !            77:        register State *s;
        !            78:        register i;
        !            79:        register *p, *e;
        !            80: 
        !            81:        for(i = 0, s = r->states; i < r->nstates; i++, s++){
        !            82:                if(s->npos == ps->count){
        !            83:                        for(p = s->pos+r->posbase, e = p+s->npos; p < e;)
        !            84:                                if(ps->base[*p++] == 0){
        !            85:                                        goto next;
        !            86:                                }
        !            87:                        return(s);
        !            88:                }
        !            89:        next:;
        !            90:        }
        !            91:        return(0);
        !            92: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.