4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
35 #include <sys/types.h>
39 /* this code was taken from REGCMP(3X) */
48 #define FEOF 0 /* This was originally EOF but it clashes with the header */
49 /* definition so it was changed to FEOF */
62 #define FCEOF 52 /* This was originally CEOF but it clashes with the header */
63 /* definition so it was changed to FCEOF */
76 libform_regcmp(char *cs1
, char *cs2
)
82 char *lastep
, *sep
, *eptr
;
85 intptr_t stack
[SSIZE
];
89 __stmax
= &stack
[SSIZE
];
94 i
+= __size((char *)(intptr_t)*adx
++);
96 sp
= (char *)(intptr_t)*adx
++;
97 if ((sep
= ep
= malloc((unsigned)(2 * i
+ SLOP
))) == NULL
)
99 if ((c
= *sp
++) == FEOF
)
105 if ((c
== '*') || (c
== '+') || (c
== '{'))
109 if ((c
= *sp
++) == FEOF
) {
111 sp
= (char *)(intptr_t)*adx
++;
115 if (--nbra
> NBRA
|| *__sp_
!= -1)
117 __i_size
= (int) (ep
- sep
);
120 if ((c
!= '*') && (c
!= '{') && (c
!= '+'))
125 if (!__rpush(ep
)) goto cerror
;
130 if (!(eptr
= (char *)__rpop())) goto cerror
;
131 if ((c
= *sp
++) == '$') {
132 if ('0' > (c
= *sp
++) || c
> '9')
135 *ep
++ = *++eptr
= nbra
++;
156 i
= (int) (ep
- eptr
- 2);
157 for (cclcnt
= 0; i
>= 256; cclcnt
++)
159 if (cclcnt
> 3) goto cerror
;
166 if ((c
= *sp
++) == FEOF
)
175 if ((c
= *sp
++) == '}') goto cerror
;
178 if ('0' <= c
&& c
<= '9')
181 } while (((c
= *sp
++) != '}') && (c
!= ','));
182 if (i
> 255) goto cerror
;
185 if (cflg
++) goto cerror
;
186 if ((c
= *sp
++) == '}') {
196 else if ((ep
[-1]&0377) < (ep
[-2]&0377))
205 if (*lastep
== CBRA
|| *lastep
== CKET
)
211 if (*lastep
== CBRA
|| *lastep
== CKET
)
217 if ((*sp
!= FEOF
) || (*adx
))
226 if ((c
= *sp
++) == '^') {
233 if ((c
== '-') && (cclcnt
> 1) &&
243 } while ((c
= *sp
++) != ']');
244 lastep
[1] = (char) cclcnt
;
272 return ((*__sp_
== -1)?0:*__sp_
--);
278 if (__sp_
>= __stmax
)
280 *++__sp_
= (intptr_t)ptr
;