--- ray/src/common/rexpr.c 1991/09/05 15:03:48 1.3 +++ ray/src/common/rexpr.c 2003/06/07 12:50:20 2.7 @@ -1,11 +1,19 @@ -/* Copyright (c) 1990 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: rexpr.c,v 2.7 2003/06/07 12:50:20 schorsch Exp $"; #endif +/* + * Regular expression parsing routines. + * + * External symbols declared in standard.h + */ +#include "copyright.h" + #include +#include #include +#include + /* * rexpr.c - regular expression parser (ala grep) */ @@ -28,6 +36,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define memcpy(to,from,len) bcopy(from,to,len) #endif +static int advance(), cclass(); + static char expbuf[ESIZE]; static int iflag; static int circf; @@ -105,7 +115,8 @@ int iflg, wflag; if ((c = *sp++) == '\0') return(-1); if (c == '<') { - *ep++ = CBRC; + if (ep == expbuf || ep[-1] != CBRC) + *ep++ = CBRC; continue; } if (c == '>') { @@ -123,12 +134,11 @@ int iflg, wflag; char * expsave() /* save compiled string */ { - extern char *malloc(); register char *ep; if (explen == 0) return(NULL); - if ((ep = malloc(explen+3)) == NULL) + if ((ep = (char *)malloc(explen+3)) == NULL) return(NULL); ep[0] = iflag; ep[1] = circf; @@ -137,6 +147,7 @@ expsave() /* save compiled string */ return(ep); } +void expset(ep) /* install saved string */ register char *ep; { @@ -146,28 +157,26 @@ register char *ep; } char * -eindex(sp) /* find the expression in str */ +eindex(sp) /* find the expression in string sp */ register char *sp; { - if (circf) { - if (advance(sp, expbuf)) - return(sp); + /* check for match at beginning of line, watch CBRC */ + if (advance(sp, expbuf[0]==CBRC ? expbuf+1 : expbuf)) + return(sp); + if (circf) return(NULL); - } /* fast check for first character */ if (expbuf[0]==CCHR) { register c = expbuf[1]; - do { + while (*++sp) if (same(*sp, c) && advance(sp, expbuf)) return(sp); - } while (*sp++); return(NULL); } /* regular algorithm */ - do { + while (*++sp) if (advance(sp, expbuf)) return(sp); - } while (*sp++); return(NULL); } @@ -245,8 +254,6 @@ register char *ep; return(0); case CBRC: - if (lp == alp) - continue; if ((isalnum(*lp) || *lp == '_') && !(isalnum(lp[-1]) || lp[-1] == '_')) continue; return (0); @@ -265,6 +272,7 @@ static int cclass(set, c, af) register char *set; register c; +int af; { register n;