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 <stdio.h> |
10 |
> |
#include "copyright.h" |
11 |
> |
|
12 |
> |
#include <stdlib.h> |
13 |
|
#include <ctype.h> |
14 |
+ |
|
15 |
+ |
#include "rtio.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(); |
36 |
> |
static int advance(char *, char *); |
37 |
> |
static int cclass(char *, int c, int af); |
38 |
|
|
39 |
|
static char expbuf[ESIZE]; |
40 |
|
static int iflag; |
47 |
|
register char *sp; |
48 |
|
int iflg, wflag; |
49 |
|
{ |
50 |
< |
register c; |
50 |
> |
register int c; |
51 |
|
register char *ep; |
52 |
< |
char *lastep; |
52 |
> |
char *lastep = NULL; |
53 |
|
int cclcnt; |
54 |
|
|
55 |
|
iflag = iflg; |
132 |
|
char * |
133 |
|
expsave() /* save compiled string */ |
134 |
|
{ |
129 |
– |
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; |
145 |
|
return(ep); |
146 |
|
} |
147 |
|
|
148 |
+ |
void |
149 |
|
expset(ep) /* install saved string */ |
150 |
|
register char *ep; |
151 |
|
{ |
165 |
|
return(NULL); |
166 |
|
/* fast check for first character */ |
167 |
|
if (expbuf[0]==CCHR) { |
168 |
< |
register c = expbuf[1]; |
168 |
> |
register int c = expbuf[1]; |
169 |
|
while (*++sp) |
170 |
|
if (same(*sp, c) && advance(sp, expbuf)) |
171 |
|
return(sp); |
269 |
|
static int |
270 |
|
cclass(set, c, af) |
271 |
|
register char *set; |
272 |
< |
register c; |
272 |
> |
register int c; |
273 |
> |
int af; |
274 |
|
{ |
275 |
< |
register n; |
275 |
> |
register int n; |
276 |
|
|
277 |
|
if (c == 0) |
278 |
|
return(0); |