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

version» Context lines:

pike.git/src/modules/Regexp/pike_regexp.c:251:    */   regexp *pike_regcomp(char *exp,int excompat)   {    register regexp *r;    register char *scan;    register char *longest;    register ptrdiff_t len;    int flags;    short *exp2,*dest,c;    -  if (exp == (char *)NULL) +  if (exp == NULL)    FAIL("NULL argument");       exp2=xalloc( (strlen(exp)+1) * sizeof(short) );    for ( scan=exp,dest=exp2;( c= UCHARAT(scan++)); ) {    switch (c) {    case '(':    case ')':    *dest++ = excompat ? c : c | SPECIAL;    break;    case '.':
pike.git/src/modules/Regexp/pike_regexp.c:301:    default:    *dest++ = c;    }    }    *dest=0;    /* First pass: determine size, legality. */    regparse = exp2;    regnpar = 1;    regsize = 0L;    regcode = &regdummy; -  if (reg(0, &flags) == (char *)NULL) -  return ((regexp *)NULL); +  if (reg(0, &flags) == NULL) +  return (NULL);       /* Small enough for pointer-storage convention? */    if (regsize >= 32767L) /* Probably could be 65535L. */    FAIL("regexp too big");       /* Allocate space. */    r = xalloc(sizeof(regexp) + (unsigned) regsize);       /* Second pass: emit code. */    regparse = exp2;    regnpar = 1;    regcode = r->program;    if (reg(0, &flags) == NULL) -  return ((regexp *) NULL); +  return (NULL);       /* Dig out information for optimizations. */    r->regstart = '\0'; /* Worst-case defaults. */    r->reganch = 0;    r->regmust = NULL;    r->regmlen = 0;    scan = r->program; /* First BRANCH. */    if (OP(regnext(scan)) == END) { /* Only one top-level choice. */    scan = OPERAND(scan);   
pike.git/src/modules/Regexp/pike_regexp.c:385:    *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));    } else -  ret = (char *)NULL; +  ret = NULL;       /* Pick up the branches, linking them together. */    br = regbranch(&flags); -  if (br == (char *)NULL) -  return ((char *)NULL); -  if (ret != (char *)NULL) +  if (br == NULL) +  return (NULL); +  if (ret != NULL)    regtail(ret, br); /* OPEN -> first. */    else    ret = br;    if (!(flags & HASWIDTH))    *flagp &= ~HASWIDTH;    *flagp |= flags & SPSTART;    while (*regparse == OR_OP) {    regparse++;    br = regbranch(&flags); -  if (br == (char *)NULL) -  return ((char *)NULL); +  if (br == NULL) +  return (NULL);    regtail(ret, br); /* BRANCH -> BRANCH. */    if (!(flags & HASWIDTH))    *flagp &= ~HASWIDTH;    *flagp |= flags & SPSTART;    }       /* Make a closing node, and hook it on the end. */    ender = regnode((char)((paren) ? (CLOSE + parno) : END));    regtail(ret, ender);       /* Hook the tails of the branches to the closing node. */ -  for (br = ret; br != (char *)NULL; br = regnext(br)) +  for (br = ret; br != NULL; br = regnext(br))    regoptail(br, ender);       /* Check for proper termination. */    if (paren && *regparse++ != RBRAC) {    FAIL("unmatched ()");    } else if (!paren && *regparse != '\0') {    if (*regparse == RBRAC) {    FAIL("unmatched ()");    } else    FAIL("junk on end");/* "Can't happen". */
pike.git/src/modules/Regexp/pike_regexp.c:445:   static char *regbranch(int *flagp)   {    register char *ret;    register char *chain;    register char *latest;    int flags;       *flagp = WORST; /* Tentatively. */       ret = regnode(BRANCH); -  chain = (char *)NULL; +  chain = NULL;    while (*regparse != '\0' && *regparse != OR_OP && *regparse != RBRAC) {    latest = regpiece(&flags); -  if (latest == (char *)NULL) -  return ((char *)NULL); +  if (latest == NULL) +  return (NULL);    *flagp |= flags & HASWIDTH; -  if (chain == (char *)NULL) /* First piece. */ +  if (chain == NULL) /* First piece. */    *flagp |= flags & SPSTART;    else    regtail(chain, latest);    chain = latest;    } -  if (chain == (char *)NULL) /* Loop ran zero times. */ +  if (chain == NULL) /* Loop ran zero times. */    regnode(NOTHING);       return (ret);   }      /*    - 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
pike.git/src/modules/Regexp/pike_regexp.c:479:    * be dispensed with entirely, but the endmarker role is not redundant.    */   static char *regpiece(int *flagp)   {    register char *ret;    register short op;    /* register char *nxt; */    int flags;       ret = regatom(&flags); -  if (ret == (char *)NULL) -  return ((char *)NULL); +  if (ret == NULL) +  return (NULL);       op = *regparse;    if (!ISMULT(op)) {    *flagp = flags;    return (ret);    }    if (!(flags & HASWIDTH))    FAIL("* or + operand could be empty");    *flagp = (WORST | SPSTART);   
pike.git/src/modules/Regexp/pike_regexp.c:607:    }    regc('\0');    if (*regparse != RSQBRAC)    FAIL("unmatched []");    regparse++;    *flagp |= HASWIDTH | SIMPLE;    }    break;    case LBRAC:    ret = reg(1, &flags); -  if (ret == (char *)NULL) -  return ((char *)NULL); +  if (ret == NULL) +  return (NULL);    *flagp |= flags & (HASWIDTH | SPSTART);    break;    case '\0':    case OR_OP:    case RBRAC:    FAIL("internal urp"); /* Supposed to be caught earlier. */       case ASTERIX:    FAIL("* follows nothing\n");   
pike.git/src/modules/Regexp/pike_regexp.c:725:    register char *temp;    register ptrdiff_t offset;       if (p == &regdummy)    return;       /* Find last node. */    scan = p;    for (;;) {    temp = regnext(scan); -  if (temp == (char *)NULL) +  if (temp == NULL)    break;    scan = temp;    }       if (OP(scan) == BACK)    offset = scan - val;    else    offset = val - scan;    *(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) +  if (p == NULL || p == &regdummy || OP(p) != BRANCH)    return;    regtail(OPERAND(p), val);   }      /*    * regexec and friends    */      /*    * Global work variables for regexec().
pike.git/src/modules/Regexp/pike_regexp.c:782:   #endif      /*    - regexec - match a regexp against a string    */   int pike_regexec(regexp *prog, char *string)   {    register char *s;       /* Be paranoid... */ -  if (prog == (regexp *)NULL || string == (char *)NULL) { +  if (prog == NULL || string == NULL) {    regerror("NULL parameter");    return (0);    }       /* If there is a "must appear" string, look for it. */ -  if (prog->regmust != (char *)NULL) { +  if (prog->regmust != NULL) {    s = string; -  while ((s = strchr(s, prog->regmust[0])) != (char *)NULL) { +  while ((s = strchr(s, prog->regmust[0])) != NULL) {    if (strncmp(s, prog->regmust, prog->regmlen) == 0)    break; /* Found it. */    s++;    } -  if (s == (char *)NULL) /* Not present. */ +  if (s == NULL) /* Not present. */    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')    /* We know what char it must start with. */ -  while ((s = strchr(s, prog->regstart)) != (char *)NULL) { +  while ((s = strchr(s, prog->regstart)) != NULL) {    if (regtry(prog, s))    return (1);    s++;    }    else    /* We don't -- general case. */    do {    if (regtry(prog, s))    return (1);    } while (*s++ != '\0');
pike.git/src/modules/Regexp/pike_regexp.c:851:    register char **sp;    register char **ep;       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; +  *sp++ = NULL; +  *ep++ = NULL;    }    if (regmatch(prog->program)) {    prog->startp[0] = string;    prog->endp[0] = reginput;    return (1);    } else    return (0);   }      /*
pike.git/src/modules/Regexp/pike_regexp.c:890:      #endif   {    register char *scan; /* Current node. */    char *nxt; /* nxt node. */       check_c_stack (4 * sizeof (void *));       scan = prog;   #ifdef PIKE_DEBUG -  if (scan != (char *)NULL && regnarrate) +  if (scan != NULL && regnarrate)    fprintf(stderr, "%s(\n", regprop(scan));   #endif -  while (scan != (char *)NULL) { +  while (scan != NULL) {   #ifdef PIKE_DEBUG    if (regnarrate)    fprintf(stderr, "%s...\n", regprop(scan));   #endif    nxt = regnext(scan);       switch (OP(scan)) {    case BOL:    if (reginput != regbol)    return (0);
pike.git/src/modules/Regexp/pike_regexp.c:946:    if (*opnd != *reginput)    return (0);    len = strlen(opnd);    if (len > 1 && strncmp(opnd, reginput, len) != 0)    return (0);    reginput += len;    }    break;    case ANYOF:    if (*reginput == '\0' || -  strchr(OPERAND(scan), *reginput) == (char *)NULL) +  strchr(OPERAND(scan), *reginput) == NULL)    return (0);    reginput++;    break;    case ANYBUT:    if (*reginput == '\0' || -  strchr(OPERAND(scan), *reginput) != (char *)NULL) +  strchr(OPERAND(scan), *reginput) != NULL)    return (0);    reginput++;    break;    case NOTHING:    break;    case BACK:    break;       case BRANCH:{    register char *save;       if (OP(nxt) != BRANCH) /* No choice. */    nxt = OPERAND(scan); /* Avoid recursion. */    else {    do {    save = reginput;    if (regmatch(OPERAND(scan)))    return (1);    reginput = save;    scan = regnext(scan); -  } while (scan != (char *)NULL && OP(scan) == BRANCH); +  } while (scan != NULL && OP(scan) == BRANCH);    return (0);    /* NOTREACHED */    }    }    break;    case KPLUS:    case STAR:{    register char nextch;    register ptrdiff_t no;    register char *save;
pike.git/src/modules/Regexp/pike_regexp.c:1025:    register char *save;       no = OP(scan) - OPEN;    save = reginput;       if (regmatch(nxt)) {    /*    * Don't set startp if some later invocation of the same    * parentheses already has.    */ -  if (regstartp[no] == (char *)NULL) +  if (regstartp[no] == NULL)    regstartp[no] = save;    return (1);    } else    return (0);    }       if(OP(scan) >= CLOSE && OP(scan)<CLOSE+NSUBEXP)    {    register int no;    register char *save;       no = OP(scan) - CLOSE;    save = reginput;       if (regmatch(nxt)) {    /*    * Don't set endp if some later invocation of the same    * parentheses already has.    */ -  if (regendp[no] == (char *)NULL) +  if (regendp[no] == NULL)    regendp[no] = save;    return (1);    } else    return (0);    }    regerror("memory corruption");    return (0);       }   
pike.git/src/modules/Regexp/pike_regexp.c:1099:    count = strlen(scan);    scan += count;    break;    case EXACTLY:    while (*opnd == *scan) {    count++;    scan++;    }    break;    case ANYOF: -  while (*scan != '\0' && strchr(opnd, *scan) != (char *)NULL) { +  while (*scan != '\0' && strchr(opnd, *scan) != NULL) {    count++;    scan++;    }    break;    case ANYBUT: -  while (*scan != '\0' && strchr(opnd, *scan) == (char *)NULL) { +  while (*scan != '\0' && strchr(opnd, *scan) == NULL) {    count++;    scan++;    }    break;    default: /* Oh dear. Called inappropriately. */    regerror("internal foulup");    count = 0; /* Best compromise. */    break;    }    reginput = scan;
pike.git/src/modules/Regexp/pike_regexp.c:1138:   #else      static char *regnext(p)   register char *p;      #endif   {    register int offset;       if (p == &regdummy) -  return ((char *)NULL); +  return (NULL);       offset = NEXT(p);    if (offset == 0) -  return ((char *)NULL); +  return (NULL);       if (OP(p) == BACK)    return (p - offset);    else    return (p + offset);   }      #ifdef PIKE_DEBUG      STATIC char *regprop(char *);
pike.git/src/modules/Regexp/pike_regexp.c:1179:    register char op = EXACTLY; /* Arbitrary non-END op. */    register char *nxt;       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. */ +  if (nxt == NULL) /* nxt ptr. */    printf("(0)");    else    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++;
pike.git/src/modules/Regexp/pike_regexp.c:1201:    s++;    }    putchar('\n');    }       /* Header fields of interest. */    if (r->regstart != '\0')    printf("start `%c' ", r->regstart);    if (r->reganch)    printf("anchored "); -  if (r->regmust != (char *)NULL) +  if (r->regmust != NULL)    printf("must have \"%s\"", r->regmust);    printf("\n");   }      /*    - regprop - printable representation of opcode    */   #ifdef __STDC__      static char *regprop(char *op)
pike.git/src/modules/Regexp/pike_regexp.c:1269:    break;       case KPLUS:    p = "KPLUS";    break;       default:    if(OP(op) >= OPEN && OP(op) < OPEN+NSUBEXP)    {    sprintf(buf + strlen(buf), "OPEN%d", OP(op) - OPEN); -  p = (char *)NULL; +  p = NULL;    break;    }    if(OP(op) >= CLOSE && OP(op) < CLOSE+NSUBEXP)    {    sprintf(buf + strlen(buf), "CLOSE%d", OP(op) - CLOSE); -  p = (char *)NULL; +  p = NULL;    break;    }    regerror("corrupted opcode"); -  p=(char *)NULL; +  p=NULL;    break;    } -  if (p != (char *)NULL) +  if (p != NULL)    strcat(buf, p);    return (buf);   }   #endif      /*    - 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 ptrdiff_t len;    -  if (prog == (regexp *)NULL || -  source == (char *)NULL || dest == (char *)NULL) { +  if (prog == NULL || +  source == NULL || dest == NULL) {    regerror("NULL parm to regsub");    return NULL;    }       src = source;    dst = dest;    while ((c = *src++) != '\0') {    if (c == '&')    no = 0;    else if (c == '\\' && '0' <= *src && *src <= '9')
pike.git/src/modules/Regexp/pike_regexp.c:1324:    no = -1;       if (no < 0) { /* Ordinary character. */    if (c == '\\' && (*src == '\\' || *src == '&'))    c = *src++;    if (--n < 0) { /* amylaar */    regerror("line too long");    return NULL;    }    *dst++ = c; -  } else if (prog->startp[no] != (char *)NULL && -  prog->endp[no] != (char *)NULL) { +  } else if (prog->startp[no] != NULL && +  prog->endp[no] != NULL) {    len = prog->endp[no] - prog->startp[no];    if ( (n-=len) < 0 ) { /* amylaar */    regerror("line too long");    return NULL;    }    strncpy(dst, prog->startp[no], len);    dst += len;    if (len != 0 && *(dst - 1) == '\0') { /* strncpy hit NUL. */    regerror("damaged match string");    return NULL;    }    }    }    if (--n < 0) { /* amylaar */    regerror("line too long");    return NULL;    }    *dst = '\0';    return dst;   }