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

version» Context lines:

pike.git/src/modules/Regexp/pike_regexp.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: pike_regexp.c,v 1.23 2002/10/21 17:06:22 marcus Exp $ + || $Id: pike_regexp.c,v 1.24 2003/08/12 16:47:52 nilsson 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.
pike.git/src/modules/Regexp/pike_regexp.c:162:    * code generation knows about this implicit relationship.)    *    * Using two bytes for the "nxt" pointer is vast overkill for most things,    * but allows patterns to get big without disasters.    */   #define OP(p) (*(p))   #define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))   #define OPERAND(p) ((p) + 3)      /* -  * The first byte of the regexp internal "program" is actually this magic -  * number; the start node begins in the second byte. -  */ - #define MAGIC 0234 -  - /* +     * Utility definitions.    */      #define regerror(X) Pike_error("Regexp: %s\n",X);   #define SPECIAL 0x100   #define LBRAC ('('|SPECIAL)   #define RBRAC (')'|SPECIAL)   #define ASTERIX ('*'|SPECIAL)   #define PLUS ('+'|SPECIAL)   #define OR_OP ('|'|SPECIAL)
pike.git/src/modules/Regexp/pike_regexp.c:304:    default:    *dest++ = c;    }    }    *dest=0;    /* First pass: determine size, legality. */    regparse = exp2;    regnpar = 1;    regsize = 0L;    regcode = &regdummy; -  regc(MAGIC); +     if (reg(0, &flags) == (char *)NULL)    return ((regexp *)NULL);       /* Small enough for pointer-storage convention? */    if (regsize >= 32767L) /* Probably could be 65535L. */    FAIL("regexp too big");       /* Allocate space. */    r = (regexp *) xalloc(sizeof(regexp) + (unsigned) regsize);    if (r == (regexp *) NULL)    FAIL("out of space");       /* Second pass: emit code. */    regparse = exp2;    regnpar = 1;    regcode = r->program; -  regc(MAGIC); +     if (reg(0, &flags) == NULL)    return ((regexp *) NULL);       /* Dig out information for optimizations. */    r->regstart = '\0'; /* Worst-case defaults. */    r->reganch = 0;    r->regmust = NULL;    r->regmlen = 0; -  scan = r->program + 1; /* First BRANCH. */ +  scan = r->program; /* First BRANCH. */    if (OP(regnext(scan)) == END) { /* Only one top-level choice. */    scan = OPERAND(scan);       /* Starting-point info. */    if (OP(scan) == EXACTLY)    r->regstart = *OPERAND(scan);    else if (OP(scan) == BOL)    r->reganch++;       /*
pike.git/src/modules/Regexp/pike_regexp.c:781:    */   int pike_regexec(regexp *prog, char *string)   {    register char *s;       /* Be paranoid... */    if (prog == (regexp *)NULL || string == (char *)NULL) {    regerror("NULL parameter");    return (0);    } -  /* Check validity of program. */ -  if (UCHARAT(prog->program) != MAGIC) { -  regerror("corrupted program"); -  return (0); -  } +     /* If there is a "must appear" string, look for it. */    if (prog->regmust != (char *)NULL) {    s = string;    while ((s = STRCHR(s, prog->regmust[0])) != (char *)NULL) {    if (strncmp(s, prog->regmust, prog->regmlen) == 0)    break; /* Found it. */    s++;    }    if (s == (char *)NULL) /* Not present. */    return (0);
pike.git/src/modules/Regexp/pike_regexp.c:853:    reginput = string;    regstartp = prog->startp;    regendp = prog->endp;       sp = prog->startp;    ep = prog->endp;    for (i = NSUBEXP; i > 0; i--) {    *sp++ = (char *)NULL;    *ep++ = (char *)NULL;    } -  if (regmatch(prog->program + 1)) { +  if (regmatch(prog->program)) {    prog->startp[0] = string;    prog->endp[0] = reginput;    return (1);    } else    return (0);   }      /*    - regmatch - main matching routine    *
pike.git/src/modules/Regexp/pike_regexp.c:1168: Inside #if defined(PIKE_DEBUG)
     void regdump(r)   regexp *r;      #endif   {    register char *s;    register char op = EXACTLY; /* Arbitrary non-END op. */    register char *nxt;    -  s = r->program + 1; +  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));    nxt = regnext(s);    if (nxt == (char *)NULL) /* nxt ptr. */    printf("(0)");    else    printf("(%ld)",
pike.git/src/modules/Regexp/pike_regexp.c:1297:    register char *dst;    register char c;    register int no;    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; -  } +     src = source;    dst = dest;    while ((c = *src++) != '\0') {    if (c == '&')    no = 0;    else if (c == '\\' && '0' <= *src && *src <= '9')    no = *src++ - '0';    else    no = -1;