4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 /* Copyright (c) 1988 AT&T */
22 /* All Rights Reserved */
25 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
56 #define PLACE(c) ep[c >> 3] |= bittab[c & 07]
57 #define ISTHERE(c) (ep[c >> 3] & bittab[c & 07])
58 #define ecmp(s1, s2, n) (strncmp(s1, s2, n) == 0)
60 static char *braslist
[NBRA
];
61 static char *braelist
[NBRA
];
63 char *loc1
, *loc2
, *locs
;
70 static unsigned char bittab
[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
72 int advance(const char *lp
, const char *ep
);
73 static void getrnge(const char *str
);
76 compile(char *instring
, char *ep
, const char *endbuf
, int seof
)
78 INIT
/* Dependent declarations and initializations */
80 register int eof
= seof
;
83 char bracket
[NBRA
], *bracketp
;
88 int iflag
; /* used for non-ascii characters in brackets */
96 if ((c
= GETC()) == eof
|| c
== '\n') {
101 if (*ep
== 0 && !sed
)
106 circf
= closed
= nbra
= 0;
115 if (c
!= '*' && ((c
!= '\\') || (PEEKC() != '{')))
119 if (bracketp
!= bracket
)
134 if (bracketp
!= bracket
)
139 if (lastep
== NULL
|| *lastep
== CBRA
||
146 if (PEEKC() != eof
&& PEEKC() != '\n')
152 if (&ep
[17] >= endbuf
)
157 for (i
= 0; i
< 16; i
++)
161 if ((c
= GETC()) == '^') {
168 if (c
== '\0' || c
== '\n')
170 if ((c
& 0200) && iflag
) {
172 if (&ep
[32] >= endbuf
)
175 for (i
= 16; i
< 32; i
++)
178 if (c
== '-' && lc
!= 0) {
179 if ((c
= GETC()) == ']') {
183 if ((c
& 0200) && iflag
) {
185 if (&ep
[32] >= endbuf
)
188 for (i
= 16; i
< 32; i
++)
198 } while ((c
= GETC()) != ']');
207 for (cclcnt
= 0; cclcnt
< iflag
;
213 /* make nulls match so test fails */
223 switch (c
= GETC()) {
228 *bracketp
++ = (char)nbra
;
230 *ep
++ = (char)nbra
++;
234 if (bracketp
<= bracket
)
250 if ('0' <= c
&& c
<= '9')
251 i
= 10 * i
+ c
- '0';
254 } while (((c
= GETC()) != '\\') && (c
!= ','));
261 if ((c
= GETC()) == '\\')
266 /* get 2'nd number */
271 if (!cflg
) /* one number */
273 else if ((ep
[-1] & 0377) < (ep
[-2] & 0377))
285 if (c
>= '1' && c
<= '9') {
286 if ((c
-= '1') >= closed
)
293 /* Drop through to default to use \ to turn off special chars */
306 step(const char *p1
, const char *p2
)
313 return (advance(p1
, p2
));
315 /* fast check for first character */
321 if (advance(p1
, p2
)) {
328 /* regular algorithm */
330 if (advance(p1
, p2
)) {
339 advance(const char *lp
, const char *ep
)
375 c
= (unsigned char)*lp
++;
389 if (((c
& 0200) == 0 && ISTHERE(c
)) ^ neg
) {
397 braslist
[*ep
++] = (char *)lp
;
402 braelist
[*ep
++] = (char *)lp
;
440 c
= (unsigned char)*lp
++;
446 c
= (unsigned char)*lp
++;
452 ep
+= 34; /* 32 + 2 */
464 if (((c
& 0200) || !ISTHERE(c
)) ^ neg
)
470 if (((c
& 0200) || !ISTHERE(c
)) ^ neg
)
475 ep
+= 18; /* 16 + 2 */
480 bbeg
= braslist
[*ep
];
481 ct
= braelist
[*ep
++] - bbeg
;
483 if (ecmp(bbeg
, lp
, ct
)) {
491 bbeg
= braslist
[*ep
];
492 ct
= braelist
[*ep
++] - bbeg
;
494 while (ecmp(bbeg
, lp
, ct
))
497 while (lp
>= curlp
) {
513 while (*lp
++ == *ep
);
521 c
= (unsigned char)*lp
++;
522 } while (ISTHERE(c
));
535 } while (((c
& 0200) == 0 && ISTHERE(c
)) ^ neg
);
546 } while (lp
> curlp
);
555 getrnge(const char *str
)
558 size
= ((*str
& 0377) == 255)? 20000: (*str
&0377) - low
;
565 #endif /* _REGEXP_H */