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 |
+ |
#include <string.h> |
16 |
+ |
|
17 |
|
/* |
18 |
|
* rexpr.c - regular expression parser (ala grep) |
19 |
|
*/ |
32 |
|
|
33 |
|
#define same(a,b) (a==b || (iflag && (a^b)==' ' && isalpha(a))) |
34 |
|
|
27 |
– |
#ifdef BSD |
28 |
– |
#define memcpy(to,from,len) bcopy(from,to,len) |
29 |
– |
#endif |
35 |
|
|
36 |
|
static int advance(), cclass(); |
37 |
|
|
112 |
|
if ((c = *sp++) == '\0') |
113 |
|
return(-1); |
114 |
|
if (c == '<') { |
115 |
< |
*ep++ = CBRC; |
115 |
> |
if (ep == expbuf || ep[-1] != CBRC) |
116 |
> |
*ep++ = CBRC; |
117 |
|
continue; |
118 |
|
} |
119 |
|
if (c == '>') { |
131 |
|
char * |
132 |
|
expsave() /* save compiled string */ |
133 |
|
{ |
128 |
– |
extern char *malloc(); |
134 |
|
register char *ep; |
135 |
|
|
136 |
|
if (explen == 0) |
137 |
|
return(NULL); |
138 |
< |
if ((ep = malloc(explen+3)) == NULL) |
138 |
> |
if ((ep = (char *)malloc(explen+3)) == NULL) |
139 |
|
return(NULL); |
140 |
|
ep[0] = iflag; |
141 |
|
ep[1] = circf; |
144 |
|
return(ep); |
145 |
|
} |
146 |
|
|
147 |
+ |
void |
148 |
|
expset(ep) /* install saved string */ |
149 |
|
register char *ep; |
150 |
|
{ |
154 |
|
} |
155 |
|
|
156 |
|
char * |
157 |
< |
eindex(sp) /* find the expression in str */ |
157 |
> |
eindex(sp) /* find the expression in string sp */ |
158 |
|
register char *sp; |
159 |
|
{ |
160 |
< |
if (circf) { |
161 |
< |
if (advance(sp, expbuf)) |
162 |
< |
return(sp); |
160 |
> |
/* check for match at beginning of line, watch CBRC */ |
161 |
> |
if (advance(sp, expbuf[0]==CBRC ? expbuf+1 : expbuf)) |
162 |
> |
return(sp); |
163 |
> |
if (circf) |
164 |
|
return(NULL); |
158 |
– |
} |
165 |
|
/* fast check for first character */ |
166 |
|
if (expbuf[0]==CCHR) { |
167 |
|
register c = expbuf[1]; |
168 |
< |
do { |
168 |
> |
while (*++sp) |
169 |
|
if (same(*sp, c) && advance(sp, expbuf)) |
170 |
|
return(sp); |
165 |
– |
} while (*sp++); |
171 |
|
return(NULL); |
172 |
|
} |
173 |
|
/* regular algorithm */ |
174 |
< |
do { |
174 |
> |
while (*++sp) |
175 |
|
if (advance(sp, expbuf)) |
176 |
|
return(sp); |
172 |
– |
} while (*sp++); |
177 |
|
return(NULL); |
178 |
|
} |
179 |
|
|
251 |
|
return(0); |
252 |
|
|
253 |
|
case CBRC: |
250 |
– |
if (lp == alp) |
251 |
– |
continue; |
254 |
|
if ((isalnum(*lp) || *lp == '_') && !(isalnum(lp[-1]) || lp[-1] == '_')) |
255 |
|
continue; |
256 |
|
return (0); |
269 |
|
cclass(set, c, af) |
270 |
|
register char *set; |
271 |
|
register c; |
272 |
+ |
int af; |
273 |
|
{ |
274 |
|
register n; |
275 |
|
|