Annotation of researchv9/cmd/egrep/anal.c, revision 1.1

1.1     ! root        1: #include       "hdr.h"
        !             2: #include       "y.tab.h"
        !             3: 
        !             4: #define        NLIT    256
        !             5: #define        LSTART  litp = litb
        !             6: #define        LEND    {*litp = 0; if(strlen(litb) > strlen(blit))strcpy(blit,litb);}
        !             7: 
        !             8: static char *litp, litb[NLIT], *blit;
        !             9: 
        !            10: 
        !            11: /*
        !            12:        islit has to return 1 if we are to use boyer-moore.
        !            13:        in this case, set buf to the literal string and
        !            14:        set bmegrep to 1 if there is a regular expression
        !            15:        beside the literal (literal can be anywhere).
        !            16: */
        !            17: islit(buf)
        !            18:        char *buf;
        !            19: {
        !            20:        bmegrep = 0;
        !            21:        blit = buf;
        !            22:        *blit = 0;
        !            23:        LSTART;
        !            24: 
        !            25: /* pr(line-2, ""); */
        !            26: 
        !            27:        lit(line-2);
        !            28:        LEND;
        !            29:        if(strlen(blit) > 1){
        !            30:                /* bmegrep set by lit */
        !            31:                return(1);
        !            32:        }
        !            33:        return(0);
        !            34: }
        !            35: 
        !            36: /*
        !            37:        lit builds literal strings in litb. we ensure these are compulsory
        !            38:        literal string by only descending the right nodes.
        !            39: */
        !            40: lit(n)
        !            41: {
        !            42:        if(name[n] == CAT){
        !            43:                lit(left[n]);
        !            44:                lit(right[n]);
        !            45:        } else if(name[n] == PLUS){
        !            46:                lit(left[n]);
        !            47:                LEND;           /* can't go on past a + */
        !            48:                LSTART;
        !            49:                bmegrep = 1;
        !            50:                lit(left[n]);   /* but we can start with one! */
        !            51:        } else if((name[n] == CCL) && (chars[right[n]] == 1)){
        !            52:                *litp++ = chars[right[n]+1];
        !            53:                if(litp == &litb[NLIT])
        !            54:                        litp--;
        !            55:        } else if(left[n] == 0 && name[n] < 256
        !            56:                        && name[n] != LEFT && name[n] != RIGHT){
        !            57:                *litp++ = name[n];
        !            58:                if(litp == &litb[NLIT])
        !            59:                        litp--;
        !            60:        } else {
        !            61:                LEND;
        !            62:                LSTART;
        !            63:                bmegrep = 1;
        !            64:        }
        !            65: }
        !            66: 
        !            67: /*#ifdef       DEBUG*/
        !            68: 
        !            69: pr(n, s)
        !            70:        char *s;
        !            71: {
        !            72:        char buf[256];
        !            73:        int i, cnt;
        !            74: 
        !            75:        print("%s", s);
        !            76:        sprint(buf, "%s   ", s);
        !            77:        switch(name[n])
        !            78:        {
        !            79:        case FINAL:     print("expr=\n"); pr(left[n], buf); break;
        !            80:        case DOT:       print("%d: .\n",n); break;
        !            81:        case STAR:      print("%d: *\n",n); pr(left[n], buf); break;
        !            82:        case PLUS:      print("%d: +\n",n); pr(left[n], buf); break;
        !            83:        case QUEST:     print("%d: ?\n",n); pr(left[n], buf); break;
        !            84:        case CAT:       print("%d: cat\n", n); pr(left[n], buf); pr(right[n], buf); break;
        !            85:        case OR:        print("%d: or\n", n); pr(left[n], buf); pr(right[n], buf); break;
        !            86:        case NCCL:
        !            87:        case CCL:       print("%d: [%s", n, name[n]==NCCL? "^":"");
        !            88:                        for(i = right[n], cnt = chars[i++]; cnt > 0; cnt--)
        !            89:                                print("%c", chars[i++]);
        !            90:                        print("]\n");
        !            91:                        break;
        !            92:        default:
        !            93:                        if(name[n] < 256)
        !            94:                                print("%d: '%c'\n", n, name[n]);
        !            95:                        else
        !            96:                                print("URK %d\n", name[n]);
        !            97:                        break;
        !            98:        }
        !            99: }
        !           100: /*#endif*/

unix.superglobalmegacorp.com

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