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"
35 #include <sys/types.h>
41 * this code was taken from REGCMP(3X)
65 #define FCEOF 52 /* This was originally CEOF but it clashes with the header */
66 /* definition so it was changed to FCEOF */
73 char *__braslist
[NBRA
];
74 char *__braelist
[NBRA
];
76 intptr_t __bravar
[NBRA
];
77 intptr_t *__st
[SSIZE
+ 1];
78 intptr_t *__eptr_
, *__lptr_
;
82 libform_regex(char *addrc
, char *addrl
, char *a1
)
88 for (in
= 0; in
< NBRA
; in
++) {
93 cur
= __execute(addrc
, addrl
);
94 adx
= (intptr_t *)&a1
;
95 for (in
= 0; in
< NBRA
; in
++) {
96 if (((p1
= __braslist
[in
]) != 0) && (__bravar
[in
] >= 0)) {
97 p2
= (char *)adx
[__bravar
[in
]];
98 while (p1
< __braelist
[in
]) *p2
++ = *p1
++;
103 return ((addrl
== (char *)cur
) ? (char *)0 : (char *)cur
);
105 return ((char *)cur
);
109 __execute(char *addrc
, char *addrl
)
116 __eptr_
= (intptr_t *)&__st
[SSIZE
];
117 __lptr_
= (intptr_t *)&__st
[0];
120 return ((i
= __advance(p1
, ++p2
)) ? i
: (intptr_t)addrl
);
122 /* fast check for first character */
128 __eptr_
= (intptr_t *)&__st
[SSIZE
];
129 __lptr_
= (intptr_t *)&__st
[0];
130 if (i
= __advance(p1
, p2
)) {
135 return ((intptr_t)addrl
);
137 /* regular algorithm */
139 __eptr_
= (intptr_t *)&__st
[SSIZE
];
140 __lptr_
= (intptr_t *)&__st
[0];
141 if (i
= __advance(p1
, p2
)) {
146 return ((intptr_t)addrl
);
150 __advance(char *alp
, char *aep
)
152 char *lp
, *ep
, *curlp
;
154 intptr_t i
, lcnt
, dcnt
, gflg
;
168 return ((intptr_t)lp
);
177 (void) __xpush(0, ++ep
);
178 return ((intptr_t)lp
);
193 return ((intptr_t)lp
);
199 i
= (((ep
[-1] & 03) << 8) + (*ep
) & 0377);
201 (void) __xpush(0, ep
+ i
+ 2);
202 (void) __xpush(0, ++ep
);
203 (void) __xpush(0, ++ep
);
205 (void) __getrnge(&lcnt
, &dcnt
, &ep
[i
]);
207 if (!(lp
= (char *)__advance(lp
, ep
)))
209 (void) __xpush(1, curlp
= lp
);
211 if (!(dp
= (char *)__advance(lp
, ep
))) break;
213 (void) __xpush(1, lp
= dp
);
214 ep
= (char *)__xpop(0);
218 (void) __getrnge(&lcnt
, &dcnt
, ep
);
224 if (*lp
++ != *sep
) break;
229 (void) __getrnge(&lcnt
, &dcnt
, ep
);
235 if (*lp
++ == '\0') break;
241 (void) __getrnge(&lcnt
, &dcnt
, (ep
+ (*ep
& 0377)));
243 if (!__cclass(ep
, *lp
++, ep
[-1] == (CCL
| RNGE
)))
247 if (!__cclass(ep
, *lp
++, ep
[-1] == (CCL
|RNGE
)))
253 if (__cclass(ep
, *lp
++, 1)) {
260 if (__cclass(ep
, *lp
++, 0)) {
267 __braslist
[*ep
++] = lp
;
271 __braelist
[*ep
] = lp
;
272 __bravar
[*ep
] = ep
[1];
289 while (*lp
++ == *ep
);
297 if (!(lp
= (char *)__advance(lp
, ep
+1)))
303 i
= (((ep
[-1]&03) << 8) + (*ep
& 0377));
305 (void) __xpush(0, ep
+ i
);
306 (void) __xpush(1, curlp
= lp
);
307 while (i
= __advance(lp
, ep
))
308 (void) __xpush(1, lp
= (char *)i
);
309 ep
= (char *)__xpop(0);
315 if (!__cclass(ep
, *lp
++, ep
[-1] == (CCL
| PLUS
)))
320 while (__cclass(ep
, *lp
++, ((ep
[-1] == (CCL
| STAR
)) ||
321 (ep
[-1] == (CCL
| PLUS
)))));
328 else if (!(lp
= (char *)__xpop(1))) break;
329 if (i
= __advance(lp
, ep
))
331 } while (lp
> curlp
);
341 __cclass(char *aset
, char ac
, intptr_t af
)
352 if ((set
[2] - set
[1]) < 0)
370 __xpush(intptr_t i
, char *p
)
372 if (__lptr_
>= __eptr_
) {
373 (void) write(2, "stack overflow\n", 15);
377 *__lptr_
++ = (intptr_t)p
;
379 *__eptr_
-- = (intptr_t)p
;
387 return ((__lptr_
< (intptr_t *)&__st
[0]) ? 0 : *--__lptr_
);
389 return ((__eptr_
> (intptr_t *)&__st
[SSIZE
]) ? 0 : *++__eptr_
);
393 __getrnge(intptr_t *i
, intptr_t *j
, char *k
)
399 *j
= ((*k
&0377) - *i
);