Annotation of 43BSDReno/contrib/mh/zotnet/tws/lexstring.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <ctype.h>
                      3: 
                      4: #define YYLERR yysvec
                      5: #define YYTYPE int
                      6: #define YYLMAX 256
                      7: 
                      8: struct yysvf { 
                      9:        struct yywork *yystoff;
                     10:        struct yysvf *yyother;
                     11:        int *yystops;
                     12: };
                     13: 
                     14: struct yywork { 
                     15:        YYTYPE  verify;
                     16:        YYTYPE  advance; 
                     17: }; 
                     18: 
                     19: extern int yyvstop[];
                     20: extern struct yywork yycrank[];
                     21: extern struct yysvf yysvec[];
                     22: extern char yymatch[];
                     23: extern char yyextra[];
                     24: 
                     25: #ifdef LEXDEBUG
                     26: static int debug = 0;
                     27: #endif LEXDEBUG
                     28: 
                     29: #ifdef ONECASE
                     30: static char case_map[] = {
                     31:      0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
                     32:     10,  11,  12,  13,  14,  15,  16,  17,  18,  19,
                     33:     20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
                     34:     30,  31,  32,  33,  34,  35,  36,  37,  38,  39,
                     35:     40,  41,  42,  43,  44,  45,  46,  47,  48,  49,
                     36:     50,  51,  52,  53,  54,  55,  56,  57,  58,  59,
                     37:     60,  61,  62,  63,  64,  97,  98,  99, 100, 101,
                     38:    102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
                     39:    112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
                     40:    122,  91,  92,  93,  94,  95,  96,  97,  98,  99,
                     41:    100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
                     42:    110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
                     43:    120, 121, 122, 123, 124, 125, 126, 127,
                     44:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     45:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     46:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     47:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     48:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     49:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     50:    0, 0, 0, 0, 0, 0, 0, 0
                     51: };
                     52: #endif ONECASE
                     53: 
                     54: lex_string( strptr, start_cond)
                     55:        char    **strptr;
                     56:        int     start_cond;
                     57: {
                     58:        register struct yysvf *state, **lsp;
                     59:        register struct yywork *tran;
                     60:        register int statenum;
                     61:        register int ch;
                     62:        register char   *cp = *strptr;
                     63:        register int    *found;
                     64:        struct  yysvf *yylstate[YYLMAX];
                     65: 
                     66:        /* start off machines */
                     67:        lsp = yylstate;
                     68:        statenum = 1 + start_cond;
                     69:        state = yysvec + statenum;
                     70:        for (;;){
                     71: # ifdef LEXDEBUG
                     72:                if (debug) {
                     73:                        fprintf(stderr,"%d ",statenum - 1);
                     74:                }
                     75: # endif
                     76:                tran = state->yystoff;
                     77:                if(tran == yycrank)
                     78:                        /* may not be any transitions */
                     79:                        if (state->yyother == 0 ||
                     80:                            state->yyother->yystoff == yycrank)
                     81:                                break;
                     82: 
                     83: #ifdef ONECASE
                     84:                ch = case_map[*cp++];
                     85: #else  not ONECASE
                     86:                ch = *cp++;
                     87: #endif ONECASE
                     88: # ifdef LEXDEBUG
                     89:                if (debug) {
                     90:                        fprintf(stderr,"(");
                     91:                        allprint(ch);
                     92:                        fprintf(stderr, ")");
                     93:                }
                     94: # endif
                     95: tryagain:
                     96:                if ( tran > yycrank){
                     97:                        tran += ch;
                     98:                        if (tran->verify == statenum){
                     99:                                if ((statenum = tran->advance) == 0){
                    100:                                        /* error transitions */
                    101:                                        --cp;
                    102:                                        break;
                    103:                                }
                    104:                                state = statenum + yysvec;
                    105:                                *lsp++ = state;
                    106:                                goto contin;
                    107:                        }
                    108: 
                    109:                } else if(tran < yycrank) {
                    110:                        tran = yycrank+(yycrank-tran) + ch;
                    111: # ifdef LEXDEBUG
                    112:                        if (debug) {
                    113:                                fprintf(stderr," compressed");
                    114:                        }
                    115: # endif
                    116:                        if (tran->verify == statenum){
                    117:                                if ((statenum = tran->advance) == 0)
                    118:                                        /* error transitions */
                    119:                                        break;
                    120: 
                    121:                                state = statenum + yysvec;
                    122:                                *lsp++ = state;
                    123:                                goto contin;
                    124:                        }
                    125:                        tran += (yymatch[ch] - ch);
                    126: # ifdef LEXDEBUG
                    127:                        if (debug) {
                    128:                                fprintf(stderr,"(fb ");
                    129:                                allprint(yymatch[ch]);
                    130:                                fprintf(stderr,")");
                    131:                        }
                    132: # endif
                    133:                        if (tran->verify == statenum){
                    134:                                if((statenum = tran->advance) == 0)
                    135:                                        /* error transition */
                    136:                                        break;
                    137: 
                    138:                                state = statenum + yysvec;
                    139:                                *lsp++ = state;
                    140:                                goto contin;
                    141:                        }
                    142:                }
                    143:                if ((state = state->yyother) &&
                    144:                    (tran = state->yystoff) != yycrank){
                    145:                        statenum = state - yysvec;
                    146: # ifdef LEXDEBUG
                    147:                        if (debug) {
                    148:                                fprintf(stderr,"fb %d", statenum - 1);
                    149:                        }
                    150: # endif
                    151:                        goto tryagain;
                    152:                } else
                    153:                        break;
                    154: 
                    155: contin:
                    156: # ifdef LEXDEBUG
                    157:                if (debug) {
                    158:                        fprintf(stderr,">");
                    159:                }
                    160: # endif
                    161:                ;
                    162:        }
                    163: # ifdef LEXDEBUG
                    164:        if (debug) {
                    165:                fprintf(stderr,"\nStopped in state %d (",*(lsp-1)-yysvec-1);
                    166:                allprint(ch);
                    167:                fprintf(stderr, ") ");
                    168:        }
                    169: # endif
                    170:        while (lsp-- > yylstate){
                    171:                if (*lsp != 0 && (found= (*lsp)->yystops) && *found > 0){
                    172:                        if(yyextra[*found]){
                    173:                                /* must backup */
                    174:                                ch = -*found;
                    175:                                do {
                    176:                                        while (*found && *found++ != ch)
                    177:                                                ;
                    178:                                 } while (lsp > yylstate &&
                    179:                                          (found = (*--lsp)->yystops));
                    180:                        }
                    181: # ifdef LEXDEBUG
                    182:                        if (debug) {
                    183:                                fprintf(stderr," Match \"");
                    184:                                for ( cp = *strptr;
                    185:                                      cp <= ((*strptr)+(lsp-yylstate));
                    186:                                      cp++)
                    187:                                        allprint( *cp );
                    188:                                fprintf(stderr,"\" action %d\n",*found);
                    189:                        }
                    190: # endif
                    191:                        *strptr += (lsp - yylstate + 1);
                    192:                        return(*found);
                    193:                }
                    194:        }
                    195:        /* the string didn't match anything - if we're looking at
                    196:         * eos, just return 0.  Otherwise, bump the string pointer
                    197:         * and return -1.
                    198:         */
                    199: # ifdef LEXDEBUG
                    200:        if (debug) {
                    201:                fprintf(stderr," No match\n");
                    202:        }
                    203: #endif LEXDEBUG
                    204:        if ( **strptr ) {
                    205:                (*strptr)++;
                    206:                return (-1);
                    207:        }
                    208:        return (0);
                    209: }
                    210: 
                    211: #ifdef LEXDEBUG
                    212: allprint(c)
                    213:        char c;
                    214: {
                    215:        if ( c < 32 ) {
                    216:            putc( '^', stderr );
                    217:            c += 32;
                    218:        } else if ( c == 127 ) {
                    219:            putc( '^', stderr );
                    220:            c = '?';
                    221:        }
                    222:        putc( c, stderr );
                    223: }
                    224: #endif LEXDEBUG

unix.superglobalmegacorp.com

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