regexp.c (e5af7cce311c40ac0c6cf3c9d3e81b3f0a9c7c3a) regexp.c (a6dda84350c269f3e2c54cc01367177554a7cbd8)
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#pragma ident "%Z%%M% %I% %E% SMI"
8
9#include <ctype.h>
10
11typedef int boolean;
12#define TRUE 1
13#define FALSE 0
14#define NIL 0
15
16extern boolean l_onecase; /* true if upper and lower equivalent */
17extern char *l_idchars; /* set of characters legal in identifiers
18 in addition to letters and digits */
19
20extern char *strchr();
21static void expconv(void);
22
23#define isidchr(c) \
24 (isalnum(c) || ((c) != NIL && strchr(l_idchars, (c)) != NIL))
25#define makelower(c) (isupper((c)) ? tolower((c)) : (c))
26
27/* STRNCMP - like strncmp except that we convert the
7#include <ctype.h>
8
9typedef int boolean;
10#define TRUE 1
11#define FALSE 0
12#define NIL 0
13
14extern boolean l_onecase; /* true if upper and lower equivalent */
15extern char *l_idchars; /* set of characters legal in identifiers
16 in addition to letters and digits */
17
18extern char *strchr();
19static void expconv(void);
20
21#define isidchr(c) \
22 (isalnum(c) || ((c) != NIL && strchr(l_idchars, (c)) != NIL))
23#define makelower(c) (isupper((c)) ? tolower((c)) : (c))
24
25/* STRNCMP - like strncmp except that we convert the
28 * first string to lower case before comparing
26 * first string to lower case before comparing
29 * if l_onecase is set.
30 */
31
32int
33STRNCMP(char *s1, char *s2, int len)
34{
35 if (l_onecase) {
36 do

--- 56 unchanged lines hidden (view full) ---

93#define ONEXT(A) (A+3) /* next character after the operation */
94#define OPTR(A) (A+*(A+2)) /* place pointed to by the operator */
95
96#define SCNT(A) (*(A+1)) /* byte count of a string */
97#define SSTR(A) (A+2) /* address of the string */
98#define SNEXT(A) (A+2+*(A+1)) /* character following the string */
99
100/*
27 * if l_onecase is set.
28 */
29
30int
31STRNCMP(char *s1, char *s2, int len)
32{
33 if (l_onecase) {
34 do

--- 56 unchanged lines hidden (view full) ---

91#define ONEXT(A) (A+3) /* next character after the operation */
92#define OPTR(A) (A+*(A+2)) /* place pointed to by the operator */
93
94#define SCNT(A) (*(A+1)) /* byte count of a string */
95#define SSTR(A) (A+2) /* address of the string */
96#define SNEXT(A) (A+2+*(A+1)) /* character following the string */
97
98/*
101 * bit flags in the descriptor
99 * bit flags in the descriptor
102 */
103#define OPT 1
104#define STR 2
105#define META 4
106#define ALT 8
107#define OPER 16
108
109char *ure; /* pointer current position in unconverted exp */

--- 45 unchanged lines hidden (view full) ---

155
156 /* escaped characters are just characters */
157 default:
158 if (cs == NIL || (*cs & STR) == 0) {
159 cs = ccre;
160 *cs = STR;
161 SCNT(cs) = 1;
162 ccre += 2;
100 */
101#define OPT 1
102#define STR 2
103#define META 4
104#define ALT 8
105#define OPER 16
106
107char *ure; /* pointer current position in unconverted exp */

--- 45 unchanged lines hidden (view full) ---

153
154 /* escaped characters are just characters */
155 default:
156 if (cs == NIL || (*cs & STR) == 0) {
157 cs = ccre;
158 *cs = STR;
159 SCNT(cs) = 1;
160 ccre += 2;
163 } else
161 } else {
164 SCNT(cs)++;
162 SCNT(cs)++;
163 }
165 *ccre++ = c;
166 break;
167
168 /* normal(?) metacharacters */
169 case 'a':
170 case 'd':
171 case 'e':
172 case 'p':
173 if (acs != NIL && acs != cs) {
174 do {
175 temp = OCNT(acs);
164 *ccre++ = c;
165 break;
166
167 /* normal(?) metacharacters */
168 case 'a':
169 case 'd':
170 case 'e':
171 case 'p':
172 if (acs != NIL && acs != cs) {
173 do {
174 temp = OCNT(acs);
176 OCNT(acs) = ccre - acs;
175 OCNT(acs) = ccre - acs;
177 acs -= temp;
178 } while (temp != 0);
179 acs = NIL;
180 }
181 cs = ccre;
182 *cs = META;
183 MSYM(cs) = c;
184 ccre = MNEXT(cs);
185 break;
186 }
187 break;
176 acs -= temp;
177 } while (temp != 0);
178 acs = NIL;
179 }
180 cs = ccre;
181 *cs = META;
182 MSYM(cs) = c;
183 ccre = MNEXT(cs);
184 break;
185 }
186 break;
188
187
189 /* just put the symbol in */
190 case '^':
191 case '$':
192 if (acs != NIL && acs != cs) {
193 do {
194 temp = OCNT(acs);
195 OCNT(acs) = ccre - acs;
196 acs -= temp;

--- 4 unchanged lines hidden (view full) ---

201 *cs = META;
202 MSYM(cs) = c;
203 ccre = MNEXT(cs);
204 break;
205
206 /* mark the last match sequence as optional */
207 case '?':
208 if (cs)
188 /* just put the symbol in */
189 case '^':
190 case '$':
191 if (acs != NIL && acs != cs) {
192 do {
193 temp = OCNT(acs);
194 OCNT(acs) = ccre - acs;
195 acs -= temp;

--- 4 unchanged lines hidden (view full) ---

200 *cs = META;
201 MSYM(cs) = c;
202 ccre = MNEXT(cs);
203 break;
204
205 /* mark the last match sequence as optional */
206 case '?':
207 if (cs)
209 *cs = *cs | OPT;
208 *cs = *cs | OPT;
210 break;
211
212 /* recurse and define a subexpression */
213 case '(':
214 if (acs != NIL && acs != cs) {
215 do {
216 temp = OCNT(acs);
217 OCNT(acs) = ccre - acs;

--- 79 unchanged lines hidden (view full) ---

297 * the area pointed to by 'name'.
298 * \| - alternation
299 * \( \) - grouping used mostly for alternation and
300 * optionality
301 *
302 * The irregular expression must be translated to internal form
303 * prior to calling this routine
304 *
209 break;
210
211 /* recurse and define a subexpression */
212 case '(':
213 if (acs != NIL && acs != cs) {
214 do {
215 temp = OCNT(acs);
216 OCNT(acs) = ccre - acs;

--- 79 unchanged lines hidden (view full) ---

296 * the area pointed to by 'name'.
297 * \| - alternation
298 * \( \) - grouping used mostly for alternation and
299 * optionality
300 *
301 * The irregular expression must be translated to internal form
302 * prior to calling this routine
303 *
305 * The value returned is the pointer to the first non \a
304 * The value returned is the pointer to the first non \a
306 * character matched.
307 */
308
305 * character matched.
306 */
307
309boolean _escaped; /* true if we are currently _escaped */
310char *Start; /* start of string */
308extern boolean _escaped; /* true if we are currently _escaped */
309extern char *Start; /* start of string */
311
312char *
313expmatch(char *s, char *re, char *mstring)
314 /* s - string to check for a match in */
315 /* re - a converted irregular expression */
316 /* mstring - where to put whatever matches a \p */
317{
318 char *cs; /* the current symbol */

--- 143 unchanged lines hidden (view full) ---

462 _escaped = FALSE;
463 } while (*s1++);
464 return (NIL);
465
466 /* fail if we are currently _escaped */
467 case 'e':
468 if (_escaped)
469 return(NIL);
310
311char *
312expmatch(char *s, char *re, char *mstring)
313 /* s - string to check for a match in */
314 /* re - a converted irregular expression */
315 /* mstring - where to put whatever matches a \p */
316{
317 char *cs; /* the current symbol */

--- 143 unchanged lines hidden (view full) ---

461 _escaped = FALSE;
462 } while (*s1++);
463 return (NIL);
464
465 /* fail if we are currently _escaped */
466 case 'e':
467 if (_escaped)
468 return(NIL);
470 cs = MNEXT(cs);
469 cs = MNEXT(cs);
471 break;
472
473 /* match any number of tabs and spaces */
474 case 'd':
475 ptr = s;
476 while (*s == ' ' || *s == '\t')
477 s++;
478 if (s != ptr || s == Start) {
479
480 /* match, be happy */
481 matched = 1;
470 break;
471
472 /* match any number of tabs and spaces */
473 case 'd':
474 ptr = s;
475 while (*s == ' ' || *s == '\t')
476 s++;
477 if (s != ptr || s == Start) {
478
479 /* match, be happy */
480 matched = 1;
482 cs = MNEXT(cs);
481 cs = MNEXT(cs);
483 } else if (*s == '\n' || *s == '\0') {
484
485 /* match, be happy */
486 matched = 1;
482 } else if (*s == '\n' || *s == '\0') {
483
484 /* match, be happy */
485 matched = 1;
487 cs = MNEXT(cs);
486 cs = MNEXT(cs);
488 } else if (*cs & ALT) {
489
490 /* try the next part */
491 matched = 0;
492 cs = MNEXT(cs);
493 } else if (*cs & OPT) {
494
495 /* doesn't matter */

--- 64 unchanged lines hidden ---
487 } else if (*cs & ALT) {
488
489 /* try the next part */
490 matched = 0;
491 cs = MNEXT(cs);
492 } else if (*cs & OPT) {
493
494 /* doesn't matter */

--- 64 unchanged lines hidden ---