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

version» Context lines:

pike.git/src/modules/Regexp/pike_regexp.c:705:   static void reginsert(char op, char *opnd)   {    register char *src;    register char *dst;    register char *place;       if (regcode == &regdummy) {    regsize += 3;    return;    } -  src = regcode; +  +  memmove(opnd+3, opnd, (size_t)(regcode - opnd));    regcode += 3; -  dst = regcode; -  while (src > opnd) -  *--dst = *--src; +        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    */
pike.git/src/modules/Regexp/pike_regexp.c:774:   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 ptrdiff_t 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:796:   {    register 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) { -  s = string; -  while ((s = strchr(s, prog->regmust[0])) != NULL) { -  if (strncmp(s, prog->regmust, prog->regmlen) == 0) -  break; /* Found it. */ -  s++; -  } -  if (s == NULL) /* Not present. */ -  return (0); -  } +  if (prog->regmust != NULL && strstr(string, prog->regmust) == NULL) +  return(0); +     /* Mark beginning of line for ^ . */    regbol = string;       /* Simplest case: anchored match need be tried only once. */    if (prog->reganch)    return (regtry(prog, string));       /* Messy cases: unanchored match. */    s = string;    if (prog->regstart != '\0')
pike.git/src/modules/Regexp/pike_regexp.c:970:    reginput = save;    scan = regnext(scan);    } while (scan != NULL && OP(scan) == BRANCH);    return (0);    /* NOTREACHED */    }    }    break;    case KPLUS:    case STAR:{ -  register char nextch; -  register ptrdiff_t no; -  register char *save; -  register ptrdiff_t minimum; +  register char nextch = +  (OP(nxt) == EXACTLY) ? *OPERAND(nxt) : '\0'; +  register size_t no; +  register char *save = reginput; +  register size_t minimum = (OP(scan) == STAR) ? 0 : 1;    -  /* -  * 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) { +  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(nxt))    return (1); -  /* Couldn't or didn't -- back up. */ -  no--; -  reginput = save + no; +     }    return (0);    }       case END:    return (1); /* Success! */       default:    if(OP(scan) >= OPEN && OP(scan)<OPEN+NSUBEXP)    {
pike.git/src/modules/Regexp/pike_regexp.c:1059:    * 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 ptrdiff_t regrepeat(char *p) + static size_t regrepeat(char *node)   { -  register ptrdiff_t count = 0; +  register size_t count = 0;    register char *scan; -  register char *opnd; +  register char ch;    -  scan = reginput; -  opnd = OPERAND(p); -  switch (OP(p)) { +  switch (OP(node)) {    case ANY: -  count = strlen(scan); -  scan += count; +  return(strlen(reginput));    break;    case EXACTLY: -  while (*opnd == *scan) { +  ch = *OPERAND(node); +  count = 0; +  for (scan = reginput; *scan == ch; scan++)    count++; -  scan++; -  } +  return(count);    break;    case ANYOF: -  while (*scan != '\0' && strchr(opnd, *scan) != NULL) { -  count++; -  scan++; -  } +  return(strspn(reginput, OPERAND(node)));    break;    case ANYBUT: -  while (*scan != '\0' && strchr(opnd, *scan) == NULL) { -  count++; -  scan++; -  } +  return(strcspn(reginput, OPERAND(node)));    break;    default: /* Oh dear. Called inappropriately. */    regerror("internal foulup"); -  count = 0; /* Best compromise. */ +  return(0); /* Best compromise. */    break;    } -  reginput = scan; -  -  return (count); +  /* NOREACHED */   }         /*    - regnext - dig the "nxt" pointer out of a node    */   static char *regnext(register char *p)   {    register int offset;