pike.git / src / modules / Regexp / pike_regexp.c

version» Context lines:

pike.git/src/modules/Regexp/pike_regexp.c:218:   static char regdummy;      /*    * Forward declarations for regcomp()'s friends.    */   static char *reg(int, int *);   static char *regbranch(int *);   static char *regpiece(int *);   static char *regatom(int *);   static char *regnode(char); - static char *regnext(register char *); + static char *regnext(char *);   static void regc(char b);   static void reginsert(char, char *);   static void regtail(char *, char *);   static void regoptail(char *, char *);      /*    - regcomp - compile a regular expression into internal code    *    * We can't allocate space until we know how big the compiled form will be,    * but we can't compile it (and thus know how big it is) until we've got a
pike.git/src/modules/Regexp/pike_regexp.c:241:    * This also means that we don't allocate space until we are sure that the    * thing really will compile successfully, and we never have to move the    * code and thus invalidate pointers into it. (Note that it has to be in    * one piece because free() must be able to free it all.)    *    * Beware that the optimization-preparation code in here knows about some    * of the structure of the compiled regexp.    */   regexp *pike_regcomp(char *exp)   { -  register regexp *r = NULL; -  register char *scan; -  int flags; -  short *exp2,*dest,c; +  regexp *r = NULL; +  char *scan; +  int flags; +  short *exp2,*dest,c;       if (exp == NULL)    FAIL("NULL argument");       exp2=xcalloc( (strlen(exp)+1), sizeof(short) );    for ( scan=exp,dest=exp2;( c= UCHARAT(scan++)); ) {    switch (c) {    case '(':    case ')':    case '.':
pike.git/src/modules/Regexp/pike_regexp.c:376:    - reg - regular expression, i.e. main body or parenthesized thing    *    * Caller must absorb opening parenthesis.    *    * Combining parenthesis handling with the base level of regular expression    * is a trifle forced, but the need to tie the tails of the branches to what    * follows makes it hard to avoid.    */   static char *reg(int paren,int *flagp)   { -  register char *ret; -  register char *br; -  register char *ender; -  register int parno=0; /* make gcc happy */ -  int flags; +  char *ret; +  char *br; +  char *ender; +  int parno=0; /* make gcc happy */ +  int flags;       *flagp = HASWIDTH; /* Tentatively. */       /* Make an OPEN node, if parenthesized. */    if (paren) {    if (regnpar >= NSUBEXP)    FAIL("too many ()");    parno = regnpar;    regnpar++;    ret = regnode((char)(OPEN + parno));
pike.git/src/modules/Regexp/pike_regexp.c:444:    return (ret);   }      /*    - regbranch - one alternative of an | operator    *    * Implements the concatenation operator.    */   static char *regbranch(int *flagp)   { -  register char *ret; -  register char *chain; -  register char *latest; -  int flags; +  char *ret; +  char *chain; +  char *latest; +  int flags;       *flagp = WORST; /* Tentatively. */ -  +     ret = regnode(BRANCH);    chain = NULL; -  +     while (*regparse != '\0' && *regparse != OR_OP && *regparse != RBRAC) {    latest = regpiece(&flags);    if (latest == NULL)    return (NULL);    *flagp |= flags & HASWIDTH;    if (chain == NULL) /* First piece. */    *flagp |= flags & SPSTART;    else    regtail(chain, latest);    chain = latest;
pike.git/src/modules/Regexp/pike_regexp.c:480:   /*    - regpiece - something followed by possible [*] or [+]    *    * Note that the branching code sequence used for * is somewhat optimized:    * they use the same NOTHING node as both the endmarker for their branch    * list and the body of the last branch. It might seem that this node could    * be dispensed with entirely, but the endmarker role is not redundant.    */   static char *regpiece(int *flagp)   { -  register char *ret; -  register short op; -  /* register char *next; */ -  int flags; +  char *ret; +  short op; +  int flags;       ret = regatom(&flags);    if (ret == NULL)    return (NULL);       op = *regparse;    if (!ISMULT(op)) {    *flagp = flags;    return (ret);    }
pike.git/src/modules/Regexp/pike_regexp.c:555:      /*    - regatom - the lowest level    *    * Optimization: gobbles an entire sequence of ordinary characters so that    * it can turn them into a single node, which is smaller to store and    * faster to run.    */   static char *regatom(int *flagp)   { -  register char *ret; -  int flags; +  char *ret; +  int flags;       *flagp = WORST; /* Tentatively. */       switch (*regparse++) {    case CARET:    ret = regnode(BOL);    break;    case DOLLAR:    ret = regnode(EOL);    break;
pike.git/src/modules/Regexp/pike_regexp.c:578:    ret = regnode(ANY);    *flagp |= HASWIDTH | SIMPLE;    break;    case LSHBRAC:    ret = regnode(WORDSTART);    break;    case RSHBRAC:    ret = regnode(WORDEND);    break;    case LSQBRAC:{ -  register int range; -  register int rangeend; +  int range; +  int rangeend;       if (*regparse == CARET) { /* Complement of range. */    ret = regnode(ANYBUT);    regparse++;    } else    ret = regnode(ANYOF);    if (*regparse == RSQBRAC || *regparse == '-')    regc((char)(*regparse++));    while (*regparse != '\0' && *regparse != RSQBRAC) {    if (*regparse == '-') {
pike.git/src/modules/Regexp/pike_regexp.c:627:    break;    case '\0':    case OR_OP:    case RBRAC:    FAIL("internal urp"); /* Supposed to be caught earlier. */       case ASTERIX:    FAIL("* follows nothing\n");       default:{ -  register int len; -  register short ender; +  int len; +  short ender;       regparse--;    for (len=0; regparse[len] &&    !(regparse[len]&SPECIAL) && regparse[len] != RSQBRAC; len++) ;    if (len <= 0)    {    FAIL("internal disaster");    }    ender = *(regparse + len);    if (len > 1 && ISMULT(ender))
pike.git/src/modules/Regexp/pike_regexp.c:661:    }       return (ret);   }      /*    - regnode - emit a node    */   static char *regnode(char op)   { -  register char *ret; -  register char *ptr; +  char *ret; +  char *ptr;       ret = regcode;    if (ret == &regdummy) {    regsize += 3;    return (ret);    }    ptr = ret;    *ptr++ = op;    *ptr++ = '\0'; /* Null "next" pointer. */    *ptr++ = '\0';
pike.git/src/modules/Regexp/pike_regexp.c:696:    regsize++;   }      /*    - reginsert - insert an operator in front of already-emitted operand    *    * Means relocating the operand.    */   static void reginsert(char op, char *opnd)   { -  register char *place; +  char *place;       if (regcode == &regdummy) {    regsize += 3;    return;    }       memmove(opnd+3, opnd, (size_t)(regcode - opnd));    regcode += 3;       place = opnd; /* Op node, where operand used to be. */    *place++ = op;    *place++ = '\0';    *place++ = '\0';   }      /*    - regtail - set the next-pointer at the end of a node chain    */   static void regtail(char *p, char *val)   { -  register char *scan; -  register char *temp; -  register ptrdiff_t offset; +  char *scan; +  char *temp; +  ptrdiff_t offset;       if (p == &regdummy)    return;       /* Find last node. */    scan = p;    for (;;) {    temp = regnext(scan);    if (temp == NULL)    break;
pike.git/src/modules/Regexp/pike_regexp.c:769:   static char *reginput; /* String-input pointer. */   static char *regbol; /* Beginning of input, for ^ check. */   static char **regstartp; /* Pointer to startp array. */   static char **regendp; /* Ditto for endp. */      /*    * Forwards.    */   static int regtry(regexp *, char *);   static int regmatch(char *); - static size_t regrepeat(char *); + static size_t regrepeat(const char *);      #ifdef PIKE_DEBUG   int regnarrate = 0;   void regdump(regexp *);   static char *regprop(char *op);   #endif      /*    - regexec - match a regexp against a string    */   int pike_regexec(regexp *prog, char *string)   { -  register char *s; +  char *s;       /* Be paranoid... */    if (prog == NULL || string == NULL) {    regerror("NULL parameter");    return (0);    }       /* If there is a "must appear" string, look for it. */    if (prog->regmust != NULL && strstr(string, prog->regmust) == NULL)    return(0);
pike.git/src/modules/Regexp/pike_regexp.c:826:       /* Failure. */    return (0);   }      /*    - regtry - try match at specific point    */   static int regtry(regexp *prog, char *string)   { -  register int i; -  register char **stp; -  register char **enp; +  int i; +  char **stp; +  char **enp;       reginput = string;    regstartp = prog->startp;    regendp = prog->endp;       stp = prog->startp;    enp = prog->endp;    for (i = NSUBEXP; i > 0; i--) {    *stp++ = NULL;    *enp++ = NULL;
pike.git/src/modules/Regexp/pike_regexp.c:860:    *    * Conceptually the strategy is simple: check to see whether the current    * node matches, call self recursively to see whether the rest matches,    * and then act accordingly. In practice we make some effort to avoid    * recursion, in particular by going through "ordinary" nodes (that don't    * need to know whether the rest of the match failed) by a loop instead of    * by recursion.    */   static int regmatch(char *prog)   { -  register char *scan; /* Current node. */ -  char *next; /* next node. */ +  char *scan; /* Current node. */ +  char *next; /* next node. */       check_c_stack (4 * sizeof (void *));       scan = prog;   #ifdef PIKE_DEBUG    if (scan != NULL && regnarrate)    fprintf(stderr, "%s(\n", regprop(scan));   #endif    while (scan != NULL) {   #ifdef PIKE_DEBUG
pike.git/src/modules/Regexp/pike_regexp.c:908:    break;    case WORDEND:    if (*reginput == '\0')    break;    if ( reginput == regbol ||    !ISWORDPART( *((unsigned char *)reginput-1) ) ||    ISWORDPART( *((unsigned char *)reginput) ) )    return (0);    break;    case EXACTLY:{ -  register ptrdiff_t len; -  register char *opnd; +  ptrdiff_t len; +  char *opnd;       opnd = OPERAND(scan);    /* Inline the first character, for speed. */    if (*opnd != *reginput)    return (0);    len = strlen(opnd);    if (len > 1 && strncmp(opnd, reginput, len) != 0)    return (0);    reginput += len;    }
pike.git/src/modules/Regexp/pike_regexp.c:939:    strchr(OPERAND(scan), *reginput) != NULL)    return (0);    reginput++;    break;    case NOTHING:    break;    case BACK:    break;       case BRANCH:{ -  register char *save; +  char *save;       if (OP(next) != BRANCH) /* No choice. */    next = OPERAND(scan); /* Avoid recursion. */    else {    do {    save = reginput;    if (regmatch(OPERAND(scan)))    return (1);    reginput = save;    scan = regnext(scan);    } while (scan != NULL && OP(scan) == BRANCH);    return (0);    /* NOTREACHED */    }    }    break;    case KPLUS:    case STAR:{ -  register char nextch = +  char nextch =    (OP(next) == EXACTLY) ? *OPERAND(next) : '\0'; -  register size_t no; -  register char *save = reginput; -  register size_t minimum = (OP(scan) == STAR) ? 0 : 1; +  size_t no; +  char *save = reginput; +  size_t minimum = (OP(scan) == STAR) ? 0 : 1;       for(no = regrepeat(OPERAND(scan)) + 1; no > minimum; no--) {    reginput = save + no -1;    /* If it could work, try it. */    if (nextch == '\0' || *reginput == nextch)    if (regmatch(next))    return (1);    }    return (0);    }       case END:    return (1); /* Success! */       default:    if(OP(scan) >= OPEN && OP(scan)<OPEN+NSUBEXP)    { -  register int no; -  register char *input; +  int no; +  char *input;       no = OP(scan) - OPEN;    input = reginput;       if (regmatch(next)) {    /*    * Don't set startp if some later invocation of the same    * parentheses already has.    */    if (regstartp[no] == NULL)    regstartp[no] = input;    return (1);    } else    return (0);    }       if(OP(scan) >= CLOSE && OP(scan)<CLOSE+NSUBEXP)    { -  register int no; -  register char *input; +  int no; +  char *input;       no = OP(scan) - CLOSE;    input = reginput;       if (regmatch(next)) {    /*    * Don't set endp if some later invocation of the same    * parentheses already has.    */    if (regendp[no] == NULL)
pike.git/src/modules/Regexp/pike_regexp.c:1036:    * We get here only if there's trouble -- normally "case END" is the    * terminating point.    */    regerror("corrupted pointers");    return (0);   }      /*    - regrepeat - repeatedly match something simple, report how many    */ - static size_t regrepeat(char *node) + static size_t regrepeat(const char *node)   { -  register size_t count = 0; -  register char *scan; -  register char ch; +  size_t count = 0; +  char *scan; +  char ch;       switch (OP(node)) {    case ANY:    return(strlen(reginput));    break;    case EXACTLY:    ch = *OPERAND(node);    count = 0;    for (scan = reginput; *scan == ch; scan++)    count++;
pike.git/src/modules/Regexp/pike_regexp.c:1071:    return(0); /* Best compromise. */    break;    }    /* NOREACHED */   }         /*    - regnext - dig the "next" pointer out of a node    */ - static char *regnext(register char *p) + static char *regnext(char *p)   { -  register int offset; +  int offset;       if (p == &regdummy)    return (NULL);       offset = NEXT(p);    if (offset == 0)    return (NULL);       if (OP(p) == BACK)    return (p - offset);
pike.git/src/modules/Regexp/pike_regexp.c:1097: Inside #if defined(PIKE_DEBUG)
     #ifdef PIKE_DEBUG      static char *regprop(char *);      /*    - regdump - dump a regexp onto stdout in vaguely comprehensible form    */   void regdump(regexp *r)   { -  register char *s; -  register char op = EXACTLY; /* Arbitrary non-END op. */ -  register char *next; +  char *s; +  char op = EXACTLY; /* Arbitrary non-END op. */ +  char *next;       s = r->program;    while (op != END) { /* While that wasn't END last time... */    op = OP(s);    printf("%2ld%s", /* Where, what. */    DO_NOT_WARN((long)(s - r->program)),    regprop(s));    next = regnext(s);    if (next == NULL) /* next ptr. */    printf("(0)");
pike.git/src/modules/Regexp/pike_regexp.c:1140: Inside #if defined(PIKE_DEBUG)
   if (r->regmust != NULL)    printf("must have \"%s\"", r->regmust);    printf("\n");   }      /*    - regprop - printable representation of opcode    */   static char *regprop(char *op)   { -  register char *p; +  char *p;    static char buf[50];       strcpy(buf, ":");       switch (OP(op)) {    case BOL:    p = "BOL";    break;    case EOL:    p = "EOL";