17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*	Copyright (c) 1988 AT&T	*/
237c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
247c478bdstevel@tonic-gate
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/*
277c478bdstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
287c478bdstevel@tonic-gate * Use is subject to license terms.
297c478bdstevel@tonic-gate */
307c478bdstevel@tonic-gate
31981fe1bJohn Levon/*
32981fe1bJohn Levon * Copyright (c) 2018, Joyent, Inc.
33981fe1bJohn Levon */
34981fe1bJohn Levon
357c478bdstevel@tonic-gate/*LINTLIBRARY*/
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate#include <sys/types.h>
387c478bdstevel@tonic-gate#include <stdlib.h>
397c478bdstevel@tonic-gate#include <unistd.h>
407c478bdstevel@tonic-gate#include "utility.h"
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate/*
437c478bdstevel@tonic-gate *	this code was taken from REGCMP(3X)
447c478bdstevel@tonic-gate */
457c478bdstevel@tonic-gate/*VARARGS*/
467c478bdstevel@tonic-gate/*ARGSUSED*/
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate#define	SSIZE	50
497c478bdstevel@tonic-gate#define	TGRP	48
507c478bdstevel@tonic-gate#define	A256	01
517c478bdstevel@tonic-gate#define	A512	02
527c478bdstevel@tonic-gate#define	A768	03
537c478bdstevel@tonic-gate#define	NBRA	10
547c478bdstevel@tonic-gate#define	CIRCFL	32
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate#define	CBRA	60
577c478bdstevel@tonic-gate#define	GRP	40
587c478bdstevel@tonic-gate#define	SGRP	56
597c478bdstevel@tonic-gate#define	PGRP	68
607c478bdstevel@tonic-gate#define	EGRP	44
617c478bdstevel@tonic-gate#define	RNGE	03
627c478bdstevel@tonic-gate#define	CCHR	20
637c478bdstevel@tonic-gate#define	CDOT	64
647c478bdstevel@tonic-gate#define	CCL	24
657c478bdstevel@tonic-gate#define	NCCL	8
667c478bdstevel@tonic-gate#define	CDOL	28
677c478bdstevel@tonic-gate#define	FCEOF	52 /* This was originally CEOF but it clashes with the header */
687c478bdstevel@tonic-gate			/* definition so it was changed to FCEOF */
697c478bdstevel@tonic-gate#define	CKET	12
707c478bdstevel@tonic-gate
717c478bdstevel@tonic-gate#define	STAR	01
727c478bdstevel@tonic-gate#define	PLUS	02
737c478bdstevel@tonic-gate#define	MINUS	16
747c478bdstevel@tonic-gate
757c478bdstevel@tonic-gatechar	*__braslist[NBRA];
767c478bdstevel@tonic-gatechar	*__braelist[NBRA];
777c478bdstevel@tonic-gatechar	*__loc1;
787c478bdstevel@tonic-gateintptr_t	__bravar[NBRA];
797c478bdstevel@tonic-gateintptr_t	*__st[SSIZE + 1];
807c478bdstevel@tonic-gateintptr_t	*__eptr_, *__lptr_;
817c478bdstevel@tonic-gateintptr_t	__cflg;
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gatechar *
847c478bdstevel@tonic-gatelibform_regex(char *addrc, char *addrl, char *a1)
857c478bdstevel@tonic-gate{
867c478bdstevel@tonic-gate	intptr_t cur, in;
877c478bdstevel@tonic-gate	intptr_t *adx;
887c478bdstevel@tonic-gate	char *p1, *p2;
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gate	for (in = 0; in < NBRA; in++) {
917c478bdstevel@tonic-gate		__braslist[in] = 0;
927c478bdstevel@tonic-gate		__bravar[in] = -1;
937c478bdstevel@tonic-gate	}
947c478bdstevel@tonic-gate	__cflg = 0;
957c478bdstevel@tonic-gate	cur = __execute(addrc, addrl);
967c478bdstevel@tonic-gate	adx = (intptr_t *)&a1;
977c478bdstevel@tonic-gate	for (in = 0; in < NBRA; in++) {
987c478bdstevel@tonic-gate		if (((p1 = __braslist[in]) != 0) && (__bravar[in] >= 0)) {
997c478bdstevel@tonic-gate			p2 = (char *)adx[__bravar[in]];
1007c478bdstevel@tonic-gate			while (p1 < __braelist[in]) *p2++ = *p1++;
1017c478bdstevel@tonic-gate			*p2 = '\0';
1027c478bdstevel@tonic-gate		}
1037c478bdstevel@tonic-gate	}
1047c478bdstevel@tonic-gate	if (!__cflg)
1057c478bdstevel@tonic-gate		return ((addrl == (char *)cur) ? (char *)0 : (char *)cur);
1067c478bdstevel@tonic-gate	else
1077c478bdstevel@tonic-gate		return ((char *)cur);
1087c478bdstevel@tonic-gate}
1097c478bdstevel@tonic-gate
1107c478bdstevel@tonic-gateintptr_t
1117c478bdstevel@tonic-gate__execute(char *addrc, char *addrl)
1127c478bdstevel@tonic-gate{
1137c478bdstevel@tonic-gate	char *p1, *p2, c;
1147c478bdstevel@tonic-gate	intptr_t i;
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate	p1 = addrl;
1177c478bdstevel@tonic-gate	p2 = addrc;
1187c478bdstevel@tonic-gate	__eptr_ = (intptr_t *)&__st[SSIZE];
1197c478bdstevel@tonic-gate	__lptr_ = (intptr_t *)&__st[0];
1207c478bdstevel@tonic-gate	if (*p2 == CIRCFL) {
1217c478bdstevel@tonic-gate		__loc1 = p1;
1227c478bdstevel@tonic-gate		return ((i = __advance(p1, ++p2)) ? i : (intptr_t)addrl);
1237c478bdstevel@tonic-gate	}
1247c478bdstevel@tonic-gate	/* fast check for first character */
1257c478bdstevel@tonic-gate	if (*p2 == CCHR) {
1267c478bdstevel@tonic-gate		c = p2[1];
1277c478bdstevel@tonic-gate		do {
1287c478bdstevel@tonic-gate			if (*p1 != c)
1297c478bdstevel@tonic-gate				continue;
1307c478bdstevel@tonic-gate			__eptr_ = (intptr_t *)&__st[SSIZE];
1317c478bdstevel@tonic-gate			__lptr_ = (intptr_t *)&__st[0];
1327c478bdstevel@tonic-gate			if (i = __advance(p1, p2))  {
1337c478bdstevel@tonic-gate				__loc1 = p1;
1347c478bdstevel@tonic-gate				return (i);
1357c478bdstevel@tonic-gate			}
1367c478bdstevel@tonic-gate		} while (*p1++);
1377c478bdstevel@tonic-gate		return ((intptr_t)addrl);
1387c478bdstevel@tonic-gate	}
1397c478bdstevel@tonic-gate	/* regular algorithm */
1407c478bdstevel@tonic-gate	do {
141981fe1bJohn Levon		__eptr_ = (intptr_t *)&__st[SSIZE];
142981fe1bJohn Levon		__lptr_ = (intptr_t *)&__st[0];
1437c478bdstevel@tonic-gate		if (i = __advance(p1, p2))  {
1447c478bdstevel@tonic-gate			__loc1 = p1;
1457c478bdstevel@tonic-gate			return (i);
1467c478bdstevel@tonic-gate		}
1477c478bdstevel@tonic-gate	} while (*p1++);
1487c478bdstevel@tonic-gate	return ((intptr_t)addrl);
1497c478bdstevel@tonic-gate}
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gateintptr_t
1527c478bdstevel@tonic-gate__advance(char *alp, char *aep)
1537c478bdstevel@tonic-gate{
1547c478bdstevel@tonic-gate	char *lp, *ep, *curlp;
1557c478bdstevel@tonic-gate	char *sep, *dp;
1567c478bdstevel@tonic-gate	intptr_t i, lcnt, dcnt, gflg;
1577c478bdstevel@tonic-gate
1587c478bdstevel@tonic-gate	lp = alp;
1597c478bdstevel@tonic-gate	ep = aep;
1607c478bdstevel@tonic-gate	gflg = 0;
1617c478bdstevel@tonic-gate	for (; ; ) {
1627c478bdstevel@tonic-gate		switch (*ep++) {
1637c478bdstevel@tonic-gate
1647c478bdstevel@tonic-gate	case CCHR:
1657c478bdstevel@tonic-gate		if (*ep++ == *lp++)
1667c478bdstevel@tonic-gate			continue;
1677c478bdstevel@tonic-gate		return (0);
1687c478bdstevel@tonic-gate
1697c478bdstevel@tonic-gate	case EGRP|RNGE:
1707c478bdstevel@tonic-gate		return ((intptr_t)lp);
1717c478bdstevel@tonic-gate	case EGRP:
1727c478bdstevel@tonic-gate	case GRP:
1737c478bdstevel@tonic-gate		ep++;
1747c478bdstevel@tonic-gate		continue;
1757c478bdstevel@tonic-gate
1767c478bdstevel@tonic-gate	case EGRP|STAR:
1777c478bdstevel@tonic-gate		(void) __xpop(0);
17802b0e3bToomas Soome		/* FALLTHROUGH */
1797c478bdstevel@tonic-gate	case EGRP|PLUS:
1807c478bdstevel@tonic-gate		(void) __xpush(0, ++ep);
1817c478bdstevel@tonic-gate		return ((intptr_t)lp);
1827c478bdstevel@tonic-gate
1837c478bdstevel@tonic-gate	case CDOT:
1847c478bdstevel@tonic-gate		if (*lp++)
1857c478bdstevel@tonic-gate			continue;
1867c478bdstevel@tonic-gate		return (0);
1877c478bdstevel@tonic-gate
1887c478bdstevel@tonic-gate	case CDOL:
1897c478bdstevel@tonic-gate		if (*lp == 0)
1907c478bdstevel@tonic-gate			continue;
1917c478bdstevel@tonic-gate		lp++;
1927c478bdstevel@tonic-gate		return (0);
1937c478bdstevel@tonic-gate
1947c478bdstevel@tonic-gate	case FCEOF:
1957c478bdstevel@tonic-gate		__cflg = 1;
1967c478bdstevel@tonic-gate		return ((intptr_t)lp);
1977c478bdstevel@tonic-gate
1987c478bdstevel@tonic-gate	case TGRP:
1997c478bdstevel@tonic-gate	case TGRP|A768:
2007c478bdstevel@tonic-gate	case TGRP|A512:
2017c478bdstevel@tonic-gate	case TGRP|A256:
2027c478bdstevel@tonic-gate		i = (((ep[-1] & 03) << 8) + (*ep) & 0377);
2037c478bdstevel@tonic-gate		ep++;
2047c478bdstevel@tonic-gate		(void) __xpush(0, ep + i + 2);
2057c478bdstevel@tonic-gate		(void) __xpush(0, ++ep);
2067c478bdstevel@tonic-gate		(void) __xpush(0, ++ep);
2077c478bdstevel@tonic-gate		gflg = 1;
2087c478bdstevel@tonic-gate		(void) __getrnge(&lcnt, &dcnt, &ep[i]);
2097c478bdstevel@tonic-gate		while (lcnt--)
2107c478bdstevel@tonic-gate			if (!(lp = (char *)__advance(lp, ep)))
2117c478bdstevel@tonic-gate				return (0);
2127c478bdstevel@tonic-gate		(void) __xpush(1, curlp = lp);
2137c478bdstevel@tonic-gate		while (dcnt--)
2147c478bdstevel@tonic-gate			if (!(dp = (char *)__advance(lp, ep))) break;
2157c478bdstevel@tonic-gate			else
2167c478bdstevel@tonic-gate				(void) __xpush(1, lp = dp);
2177c478bdstevel@tonic-gate		ep = (char *)__xpop(0);
2187c478bdstevel@tonic-gate		goto star;
2197c478bdstevel@tonic-gate	case CCHR|RNGE:
2207c478bdstevel@tonic-gate		sep = ep++;
2217c478bdstevel@tonic-gate		(void) __getrnge(&lcnt, &dcnt, ep);
2227c478bdstevel@tonic-gate		while (lcnt--)
2237c478bdstevel@tonic-gate			if (*lp++ != *sep)
2247c478bdstevel@tonic-gate				return (0);
2257c478bdstevel@tonic-gate		curlp = lp;
2267c478bdstevel@tonic-gate		while (dcnt--)
2277c478bdstevel@tonic-gate			if (*lp++ != *sep) break;
2287c478bdstevel@tonic-gate		if (dcnt < 0) lp++;
2297c478bdstevel@tonic-gate		ep += 2;
2307c478bdstevel@tonic-gate		goto star;
2317c478bdstevel@tonic-gate	case CDOT|RNGE:
2327c478bdstevel@tonic-gate		(void) __getrnge(&lcnt, &dcnt, ep);
2337c478bdstevel@tonic-gate		while (lcnt--)
2347c478bdstevel@tonic-gate			if (*lp++ == '\0')
2357c478bdstevel@tonic-gate				return (0);
2367c478bdstevel@tonic-gate		curlp = lp;
2377c478bdstevel@tonic-gate		while (dcnt--)
2387c478bdstevel@tonic-gate			if (*lp++ == '\0') break;
2397c478bdstevel@tonic-gate		if (dcnt < 0) lp++;
2407c478bdstevel@tonic-gate		ep += 2;
2417c478bdstevel@tonic-gate		goto star;
2427c478bdstevel@tonic-gate	case CCL|RNGE:
2437c478bdstevel@tonic-gate	case NCCL|RNGE:
2447c478bdstevel@tonic-gate		(void) __getrnge(&lcnt, &dcnt, (ep + (*ep & 0377)));
2457c478bdstevel@tonic-gate		while (lcnt--)
2467c478bdstevel@tonic-gate			if (!__cclass(ep, *lp++, ep[-1] == (CCL | RNGE)))
2477c478bdstevel@tonic-gate				return (0);
2487c478bdstevel@tonic-gate		curlp = lp;
2497c478bdstevel@tonic-gate		while (dcnt--)
2507c478bdstevel@tonic-gate			if (!__cclass(ep, *lp++, ep[-1] == (CCL|RNGE)))
2517c478bdstevel@tonic-gate				break;
2527c478bdstevel@tonic-gate		if (dcnt < 0) lp++;
2537c478bdstevel@tonic-gate		ep += (*ep + 2);
2547c478bdstevel@tonic-gate		goto star;
2557c478bdstevel@tonic-gate	case CCL:
2567c478bdstevel@tonic-gate		if (__cclass(ep, *lp++, 1)) {
2577c478bdstevel@tonic-gate			ep += *ep;
2587c478bdstevel@tonic-gate			continue;
2597c478bdstevel@tonic-gate		}
2607c478bdstevel@tonic-gate		return (0);
2617c478bdstevel@tonic-gate
2627c478bdstevel@tonic-gate	case NCCL:
2637c478bdstevel@tonic-gate		if (__cclass(ep, *lp++, 0)) {
2647c478bdstevel@tonic-gate			ep += *ep;
2657c478bdstevel@tonic-gate			continue;
2667c478bdstevel@tonic-gate		}
2677c478bdstevel@tonic-gate		return (0);
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate	case CBRA:
2707c478bdstevel@tonic-gate		__braslist[*ep++] = lp;
2717c478bdstevel@tonic-gate		continue;
2727c478bdstevel@tonic-gate
2737c478bdstevel@tonic-gate	case CKET:
2747c478bdstevel@tonic-gate		__braelist[*ep] = lp;
2757c478bdstevel@tonic-gate		__bravar[*ep] = ep[1];
2767c478bdstevel@tonic-gate		ep += 2;
2777c478bdstevel@tonic-gate		continue;
2787c478bdstevel@tonic-gate
2797c478bdstevel@tonic-gate	case CDOT|PLUS:
2807c478bdstevel@tonic-gate		if (*lp++ == '\0')
2817c478bdstevel@tonic-gate			return (0);
28202b0e3bToomas Soome		/* FALLTHROUGH */
2837c478bdstevel@tonic-gate	case CDOT|STAR:
2847c478bdstevel@tonic-gate		curlp = lp;
28502b0e3bToomas Soome		while (*lp++)
28602b0e3bToomas Soome			;
2877c478bdstevel@tonic-gate		goto star;
2887c478bdstevel@tonic-gate
2897c478bdstevel@tonic-gate	case CCHR|PLUS:
2907c478bdstevel@tonic-gate		if (*lp++ != *ep)
2917c478bdstevel@tonic-gate			return (0);
29202b0e3bToomas Soome		/* FALLTHROUGH */
2937c478bdstevel@tonic-gate	case CCHR|STAR:
2947c478bdstevel@tonic-gate		curlp = lp;
29502b0e3bToomas Soome		while (*lp++ == *ep)
29602b0e3bToomas Soome			;
2977c478bdstevel@tonic-gate		ep++;
2987c478bdstevel@tonic-gate		goto star;
2997c478bdstevel@tonic-gate
3007c478bdstevel@tonic-gate	case PGRP:
3017c478bdstevel@tonic-gate	case PGRP|A256:
3027c478bdstevel@tonic-gate	case PGRP|A512:
3037c478bdstevel@tonic-gate	case PGRP|A768:
3047c478bdstevel@tonic-gate		if (!(lp = (char *)__advance(lp, ep+1)))
3057c478bdstevel@tonic-gate			return (0);
30602b0e3bToomas Soome		/* FALLTHROUGH */
3077c478bdstevel@tonic-gate	case SGRP|A768:
3087c478bdstevel@tonic-gate	case SGRP|A512:
3097c478bdstevel@tonic-gate	case SGRP|A256:
3107c478bdstevel@tonic-gate	case SGRP:
3117c478bdstevel@tonic-gate		i = (((ep[-1]&03) << 8) + (*ep & 0377));
3127c478bdstevel@tonic-gate		ep++;
3137c478bdstevel@tonic-gate		(void) __xpush(0, ep + i);
3147c478bdstevel@tonic-gate		(void) __xpush(1, curlp = lp);
3157c478bdstevel@tonic-gate		while (i = __advance(lp, ep))
3167c478bdstevel@tonic-gate			(void) __xpush(1, lp = (char *)i);
3177c478bdstevel@tonic-gate		ep = (char *)__xpop(0);
3187c478bdstevel@tonic-gate		gflg = 1;
3197c478bdstevel@tonic-gate		goto star;
3207c478bdstevel@tonic-gate
3217c478bdstevel@tonic-gate	case CCL|PLUS:
3227c478bdstevel@tonic-gate	case NCCL|PLUS:
3237c478bdstevel@tonic-gate		if (!__cclass(ep, *lp++, ep[-1] == (CCL | PLUS)))
3247c478bdstevel@tonic-gate			return (0);
32502b0e3bToomas Soome		/* FALLTHROUGH */
3267c478bdstevel@tonic-gate	case CCL|STAR:
3277c478bdstevel@tonic-gate	case NCCL|STAR:
3287c478bdstevel@tonic-gate		curlp = lp;
3297c478bdstevel@tonic-gate		while (__cclass(ep, *lp++, ((ep[-1] == (CCL | STAR)) ||
33002b0e3bToomas Soome		    (ep[-1] == (CCL | PLUS)))))
33102b0e3bToomas Soome			;
3327c478bdstevel@tonic-gate		ep += *ep;
3337c478bdstevel@tonic-gate		goto star;
3347c478bdstevel@tonic-gate
3357c478bdstevel@tonic-gate	star:
3367c478bdstevel@tonic-gate		do {
3377c478bdstevel@tonic-gate			if (!gflg) lp--;
3387c478bdstevel@tonic-gate			else if (!(lp = (char *)__xpop(1))) break;
3397c478bdstevel@tonic-gate			if (i = __advance(lp, ep))
3407c478bdstevel@tonic-gate				return (i);
3417c478bdstevel@tonic-gate		} while (lp > curlp);
3427c478bdstevel@tonic-gate		return (0);
3437c478bdstevel@tonic-gate
3447c478bdstevel@tonic-gate	default:
3457c478bdstevel@tonic-gate		return (0);
3467c478bdstevel@tonic-gate	}
3477c478bdstevel@tonic-gate	}
3487c478bdstevel@tonic-gate}
3497c478bdstevel@tonic-gate
3507c478bdstevel@tonic-gateintptr_t
3517c478bdstevel@tonic-gate__cclass(char *aset, char ac, intptr_t af)
3527c478bdstevel@tonic-gate{
3537c478bdstevel@tonic-gate	char *set, c;
3547c478bdstevel@tonic-gate	intptr_t n;
3557c478bdstevel@tonic-gate
3567c478bdstevel@tonic-gate	set = (char *)aset;
3577c478bdstevel@tonic-gate	if ((c = ac) == 0)
3587c478bdstevel@tonic-gate		return (0);
3597c478bdstevel@tonic-gate	n = *set++;
3607c478bdstevel@tonic-gate	while (--n) {
3617c478bdstevel@tonic-gate		if (*set == MINUS) {
3627c478bdstevel@tonic-gate			if ((set[2] - set[1]) < 0)
3637c478bdstevel@tonic-gate				return (0);
3647c478bdstevel@tonic-gate			if (*++set <= c) {
3657c478bdstevel@tonic-gate				if (c <= *++set)
3667c478bdstevel@tonic-gate					return (af);
3677c478bdstevel@tonic-gate			} else
3687c478bdstevel@tonic-gate				++set;
3697c478bdstevel@tonic-gate			++set;
3707c478bdstevel@tonic-gate			n -= 2;
3717c478bdstevel@tonic-gate			continue;
3727c478bdstevel@tonic-gate		}
3737c478bdstevel@tonic-gate		if (*set++ == c)
3747c478bdstevel@tonic-gate			return (af);
3757c478bdstevel@tonic-gate	}
3767c478bdstevel@tonic-gate	return (!af);
3777c478bdstevel@tonic-gate}
3787c478bdstevel@tonic-gate
3797c478bdstevel@tonic-gateintptr_t
3807c478bdstevel@tonic-gate__xpush(intptr_t i, char *p)
3817c478bdstevel@tonic-gate{
3827c478bdstevel@tonic-gate	if (__lptr_ >= __eptr_) {
3837c478bdstevel@tonic-gate		(void) write(2, "stack overflow\n", 15);
3847c478bdstevel@tonic-gate		(void) exit(1);
3857c478bdstevel@tonic-gate	}
3867c478bdstevel@tonic-gate	if (i)
3877c478bdstevel@tonic-gate		*__lptr_++ = (intptr_t)p;
3887c478bdstevel@tonic-gate	else
3897c478bdstevel@tonic-gate		*__eptr_-- = (intptr_t)p;
3907c478bdstevel@tonic-gate	return (1);
3917c478bdstevel@tonic-gate}
3927c478bdstevel@tonic-gate
3937c478bdstevel@tonic-gateintptr_t
3947c478bdstevel@tonic-gate__xpop(intptr_t i)
3957c478bdstevel@tonic-gate{
3967c478bdstevel@tonic-gate	if (i)
3977c478bdstevel@tonic-gate		return ((__lptr_ < (intptr_t *)&__st[0]) ? 0 : *--__lptr_);
3987c478bdstevel@tonic-gate	else
3997c478bdstevel@tonic-gate		return ((__eptr_ > (intptr_t *)&__st[SSIZE]) ? 0 : *++__eptr_);
4007c478bdstevel@tonic-gate}
4017c478bdstevel@tonic-gate
4027c478bdstevel@tonic-gateintptr_t
4037c478bdstevel@tonic-gate__getrnge(intptr_t *i, intptr_t *j, char *k)
4047c478bdstevel@tonic-gate{
4057c478bdstevel@tonic-gate	*i = (*k++&0377);
4067c478bdstevel@tonic-gate	if (*k == (char)-1)
4077c478bdstevel@tonic-gate		*j = 20000;
4087c478bdstevel@tonic-gate	else
4097c478bdstevel@tonic-gate		*j = ((*k&0377) - *i);
4107c478bdstevel@tonic-gate	return (1);
4117c478bdstevel@tonic-gate}
412