--- ray/src/common/rexpr.c 1991/11/12 16:54:41 2.1
+++ ray/src/common/rexpr.c 2003/02/22 02:07:22 2.4
@@ -1,10 +1,71 @@
-/* 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.4 2003/02/22 02:07:22 greg Exp $";
#endif
+/*
+ * Regular expression parsing routines.
+ *
+ * External symbols declared in standard.h
+ */
+/* ====================================================================
+ * The Radiance Software License, Version 1.0
+ *
+ * Copyright (c) 1990 - 2002 The Regents of the University of California,
+ * through Lawrence Berkeley National Laboratory. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes Radiance software
+ * (http://radsite.lbl.gov/)
+ * developed by the Lawrence Berkeley National Laboratory
+ * (http://www.lbl.gov/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
+ * and "The Regents of the University of California" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact radiance@radsite.lbl.gov.
+ *
+ * 5. Products derived from this software may not be called "Radiance",
+ * nor may "Radiance" appear in their name, without prior written
+ * permission of Lawrence Berkeley National Laboratory.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of Lawrence Berkeley National Laboratory. For more
+ * information on Lawrence Berkeley National Laboratory, please see
+ * .
+ */
+
#include
+#include
#include
/*
* rexpr.c - regular expression parser (ala grep)
@@ -107,7 +168,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 == '>') {
@@ -125,12 +187,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;
@@ -139,6 +200,7 @@ expsave() /* save compiled string */
return(ep);
}
+void
expset(ep) /* install saved string */
register char *ep;
{
@@ -148,28 +210,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);
}
@@ -247,8 +307,6 @@ register char *ep;
return(0);
case CBRC:
- if (lp == alp)
- continue;
if ((isalnum(*lp) || *lp == '_') && !(isalnum(lp[-1]) || lp[-1] == '_'))
continue;
return (0);
@@ -267,6 +325,7 @@ static int
cclass(set, c, af)
register char *set;
register c;
+int af;
{
register n;