ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/rexpr.c
(Generate patch)

Comparing ray/src/common/rexpr.c (file contents):
Revision 1.2 by greg, Tue Jul 16 10:51:42 1991 UTC vs.
Revision 2.6 by greg, Tue May 13 17:58:32 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1990 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
4 + /*
5 + * Regular expression parsing routines.
6 + *
7 + * External symbols declared in standard.h
8 + */
9  
10 + #include "copyright.h"
11 +
12   #include <stdio.h>
13 + #include <stdlib.h>
14   #include <ctype.h>
15   /*
16   * rexpr.c - regular expression parser (ala grep)
# Line 28 | Line 34 | static char SCCSid[] = "$SunId$ LBL";
34   #define  memcpy(to,from,len)    bcopy(from,to,len)
35   #endif
36  
37 + static int     advance(), cclass();
38 +
39   static char    expbuf[ESIZE];
40   static int     iflag;
41   static int     circf;
# Line 105 | Line 113 | int iflg, wflag;
113                          if ((c = *sp++) == '\0')
114                                  return(-1);
115                          if (c == '<') {
116 <                                *ep++ = CBRC;
116 >                                if (ep == expbuf || ep[-1] != CBRC)
117 >                                        *ep++ = CBRC;
118                                  continue;
119                          }
120                          if (c == '>') {
# Line 123 | Line 132 | int iflg, wflag;
132   char *
133   expsave()                     /* save compiled string */
134   {
126        extern char  *malloc();
135          register char  *ep;
136  
137          if (explen == 0)
138                  return(NULL);
139 <        if ((ep = malloc(explen+3)) == NULL)
139 >        if ((ep = (char *)malloc(explen+3)) == NULL)
140                  return(NULL);
141          ep[0] = iflag;
142          ep[1] = circf;
# Line 137 | Line 145 | expsave()                    /* save compiled string */
145          return(ep);
146   }
147  
148 + void
149   expset(ep)                      /* install saved string */
150   register char  *ep;
151   {
# Line 146 | Line 155 | register char  *ep;
155   }
156  
157   char *
158 < eindex(sp)                    /* find the expression in str */
158 > eindex(sp)                    /* find the expression in string sp */
159   register char *sp;
160   {
161 <        if (circf) {
162 <                if (advance(sp, expbuf))
163 <                        return(sp);
161 >        /* check for match at beginning of line, watch CBRC */
162 >        if (advance(sp, expbuf[0]==CBRC ? expbuf+1 : expbuf))
163 >                return(sp);
164 >        if (circf)
165                  return(NULL);
156        }
166          /* fast check for first character */
167          if (expbuf[0]==CCHR) {
168                  register c = expbuf[1];
169 <                do {
169 >                while (*++sp)
170                          if (same(*sp, c) && advance(sp, expbuf))
171                                  return(sp);
163                } while (*sp++);
172                  return(NULL);
173          }
174          /* regular algorithm */
175 <        do {
175 >        while (*++sp)
176                  if (advance(sp, expbuf))
177                          return(sp);
170        } while (*sp++);
178          return(NULL);
179   }
180  
# Line 245 | Line 252 | register char *ep;
252                  return(0);
253  
254          case CBRC:
248                if (lp == expbuf)
249                        continue;
255                  if ((isalnum(*lp) || *lp == '_') && !(isalnum(lp[-1]) || lp[-1] == '_'))
256                          continue;
257                  return (0);
# Line 265 | Line 270 | static int
270   cclass(set, c, af)
271   register char *set;
272   register c;
273 + int af;
274   {
275          register n;
276  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines