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

version» Context lines:

pike.git/src/modules/Regexp/pike_regexp.c:1:   /* -  * $Id: pike_regexp.c,v 1.14 2000/07/28 07:14:40 hubbe Exp $ +  * $Id: pike_regexp.c,v 1.15 2000/08/11 13:04:22 grubba Exp $    *    * regexp.c - regular expression matching    *    * DESCRIPTION    *    * Underneath the reformatting and comment blocks which were added to    * make it consistent with the rest of the code, you will find a    * modified version of Henry Specer's regular expression library.    * Henry's functions were modified to provide the minimal regular    * expression matching, as required by P1003. Henry's code was
pike.git/src/modules/Regexp/pike_regexp.c:247:    * 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,int excompat)   {    register regexp *r;    register char *scan;    register char *longest; -  register int len; +  register size_t len;    int flags;    short *exp2,*dest,c;       if (exp == (char *)NULL)    FAIL("NULL argument");       exp2=(short*)xalloc( (strlen(exp)+1) * (sizeof(short[8])/sizeof(char[8])) );    for ( scan=exp,dest=exp2;( c= UCHARAT(scan++)); ) {    switch (c) {    case '(':
pike.git/src/modules/Regexp/pike_regexp.c:350:    * ties in favor of later strings, since the regstart check works    * with the beginning of the r.e. and avoiding duplication    * strengthens checking. Not a strong reason, but sufficient in the    * absence of others.    */    if (flags & SPSTART) {    longest = NULL;    len = 0;    for (; scan != NULL; scan = regnext(scan))    if (OP(scan) == EXACTLY && -  (int)strlen(OPERAND(scan)) >= len) { +  strlen(OPERAND(scan)) >= len) {    longest = OPERAND(scan);    len = strlen(OPERAND(scan));    }    r->regmust = longest;    r->regmlen = len;    }    }    free((char*)exp2);    return (r);   }
pike.git/src/modules/Regexp/pike_regexp.c:706:    *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 int offset; +  register char *scan; +  register char *temp; +  register ptrdiff_t offset;       if (p == &regdummy)    return;       /* Find last node. */    scan = p;    for (;;) {    temp = regnext(scan);    if (temp == (char *)NULL)    break;    scan = temp;    }       if (OP(scan) == BACK)    offset = scan - val;    else    offset = val - scan; -  *(scan + 1) = (offset >> 8) & 0377; -  *(scan + 2) = offset & 0377; +  *(scan + 1) = DO_NOT_WARN((offset >> 8) & 0377); +  *(scan + 2) = DO_NOT_WARN(offset & 0377);   }      /*    - regoptail - regtail on operand of first argument; nop if operandless    */   static void regoptail(char *p, char *val)   {    /* "Operandless" and "op != BRANCH" are synonymous in practice. */    if (p == (char *)NULL || p == &regdummy || OP(p) != BRANCH)    return;
pike.git/src/modules/Regexp/pike_regexp.c:758:   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 int regrepeat(char *); + STATIC size_t regrepeat(char *);      #ifdef PIKE_DEBUG   int regnarrate = 0;   void regdump(regexp *);   STATIC char *regprop(char *op);   #endif      /*    - regexec - match a regexp against a string    */
pike.git/src/modules/Regexp/pike_regexp.c:925:    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 int len; +  register size_t len;    register 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:975:    reginput = save;    scan = regnext(scan);    } while (scan != (char *)NULL && OP(scan) == BRANCH);    return (0);    /* NOTREACHED */    }    }    break;    case STAR:{    register char nextch; -  register int no; +  register size_t no;    register char *save;    register int minimum;       /*    * Lookahead to avoid useless match attempts when we know    * what character comes next.    */    nextch = '\0';    if (OP(nxt) == EXACTLY)    nextch = *OPERAND(nxt);    minimum = (OP(scan) == STAR) ? 0 : 1;    save = reginput; -  no = regrepeat(OPERAND(scan)); -  while (no >= minimum) { +  no = regrepeat(OPERAND(scan)) + (minimum == 0); +  while (no) {    /* If it could work, try it. */    if (nextch == '\0' || *reginput == nextch)    if (regmatch(nxt))    return (1);    /* Couldn't or didn't -- back up. */    no--;    reginput = save + no;    }    return (0);    }
pike.git/src/modules/Regexp/pike_regexp.c:1065:    */    regerror("corrupted pointers");    return (0);   }      /*    - regrepeat - repeatedly match something simple, report how many    */   #ifdef __STDC__    - static int regrepeat(char *p) + static size_t regrepeat(char *p)      #else    - static int regrepeat(p) + static size_t regrepeat(p)   char *p;      #endif   { -  register int count = 0; +  register size_t count = 0;    register char *scan;    register char *opnd;       scan = reginput;    opnd = OPERAND(p);    switch (OP(p)) {    case ANY:    count = strlen(scan);    scan += count;    break;
pike.git/src/modules/Regexp/pike_regexp.c:1168:      #endif   {    register char *s;    register char op = EXACTLY; /* Arbitrary non-END op. */    register char *nxt;       s = r->program + 1;    while (op != END) { /* While that wasn't END last time... */    op = OP(s); -  printf("%2ld%s", (long)(s - r->program), regprop(s)); /* Where, what. */ +  printf("%2ld%s", /* Where, what. */ +  DO_NOT_WARN((long)(s - r->program)), +  regprop(s));    nxt = regnext(s);    if (nxt == (char *)NULL) /* nxt ptr. */    printf("(0)");    else -  printf("(%ld)", (long)( (s - r->program) + (nxt - s))); +  printf("(%ld)", +  DO_NOT_WARN((long)( (s - r->program) + (nxt - s))));    s += 3;    if (op == ANYOF || op == ANYBUT || op == EXACTLY) {    /* Literal string, where present. */    while (*s != '\0') {    putchar(*s);    s++;    }    s++;    }    putchar('\n');
pike.git/src/modules/Regexp/pike_regexp.c:1284:   /*    - regsub - perform substitutions after a regexp match    */      char *pike_regsub(regexp *prog, char *source, char *dest, int n)   {    register char *src;    register char *dst;    register char c;    register int no; -  register int len; +  register ptrdiff_t len;       if (prog == (regexp *)NULL ||    source == (char *)NULL || dest == (char *)NULL) {    regerror("NULL parm to regsub");    return NULL;    }    if (UCHARAT(prog->program) != MAGIC) {    regerror("damaged regexp fed to regsub");    return NULL;    }