Annotation of researchv10no/cmd/cfront/libstring/Regexp.c, revision 1.1

1.1     ! root        1: #include "Regexp.h"
        !             2: 
        !             3: Regexp::Regexp(const char *p)
        !             4: {
        !             5:        prog = regcomp(p);
        !             6:        for (int i=0; i<NSUBEXP; i++) offset[i] = len[i] = -1;
        !             7: }
        !             8: 
        !             9: Regexp::Regexp(const String& s1)
        !            10: {
        !            11:        const String    x1 = s1 + (char)0;
        !            12:        prog = regcomp(x1.d->start);
        !            13:        for (int i=0; i<NSUBEXP; i++) offset[i] = len[i] = -1;
        !            14: }
        !            15: 
        !            16: int
        !            17: Regexp::exec(const String& s1)
        !            18: {
        !            19:        subject = s1;
        !            20:        const String    x1 = s1 + (char)0;
        !            21:        register char*  p = x1.d->start;
        !            22:        if (!prog) return 0;
        !            23:        int     ans = regexec(prog, p);
        !            24:        for (int i=0; i<NSUBEXP; i++)
        !            25:                if (prog->startp[i]) {
        !            26:                        offset[i] = prog->startp[i] - p;
        !            27:                        len[i] = prog->endp[i] - prog->startp[i];
        !            28:                } else offset[i] = len[i] = -1;
        !            29:        return ans;
        !            30: }
        !            31: 
        !            32: int
        !            33: Regexp::result(unsigned& start, unsigned& length, unsigned i)
        !            34: {
        !            35:        if (i>=NSUBEXP || offset[i] == -1) return 0;
        !            36:        start = offset[i];
        !            37:        length = len[i];
        !            38:        return 1;
        !            39: }
        !            40: 
        !            41: extern void free(char *);      // since prog is allocated by malloc()
        !            42: 
        !            43: Regexp::~Regexp()
        !            44: {
        !            45:        free((char *)prog);
        !            46: }

unix.superglobalmegacorp.com

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