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
)
295 /* Drop through to default to use \ to turn off special chars */
308 step(const char *p1
, const char *p2
)
315 return (advance(p1
, p2
));
317 /* fast check for first character */
323 if (advance(p1
, p2
)) {
330 /* regular algorithm */
332 if (advance(p1
, p2
)) {
341 advance(const char *lp
, const char *ep
)
377 c
= (unsigned char)*lp
++;
391 if (((c
& 0200) == 0 && ISTHERE(c
)) ^ neg
) {
399 braslist
[*ep
++] = (char *)lp
;
404 braelist
[*ep
++] = (char *)lp
;
442 c
= (unsigned char)*lp
++;
448 c
= (unsigned char)*lp
++;
454 ep
+= 34; /* 32 + 2 */
466 if (((c
& 0200) || !ISTHERE(c
)) ^ neg
)
472 if (((c
& 0200) || !ISTHERE(c
)) ^ neg
)
477 ep
+= 18; /* 16 + 2 */
482 bbeg
= braslist
[*ep
];
483 ct
= braelist
[*ep
++] - bbeg
;
485 if (ecmp(bbeg
, lp
, ct
)) {
493 bbeg
= braslist
[*ep
];
494 ct
= braelist
[*ep
++] - bbeg
;
496 while (ecmp(bbeg
, lp
, ct
))
499 while (lp
>= curlp
) {
525 c
= (unsigned char)*lp
++;
526 } while (ISTHERE(c
));
539 } while (((c
& 0200) == 0 && ISTHERE(c
)) ^ neg
);
550 } while (lp
> curlp
);
559 getrnge(const char *str
)
562 size
= ((*str
& 0377) == 255)? 20000: (*str
&0377) - low
;
569 #endif /* _REGEXP_H */