1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 36*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 37*7c478bd9Sstevel@tonic-gate #include <unistd.h> 38*7c478bd9Sstevel@tonic-gate #include "utility.h" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * this code was taken from REGCMP(3X) 42*7c478bd9Sstevel@tonic-gate */ 43*7c478bd9Sstevel@tonic-gate /*VARARGS*/ 44*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #define SSIZE 50 47*7c478bd9Sstevel@tonic-gate #define TGRP 48 48*7c478bd9Sstevel@tonic-gate #define A256 01 49*7c478bd9Sstevel@tonic-gate #define A512 02 50*7c478bd9Sstevel@tonic-gate #define A768 03 51*7c478bd9Sstevel@tonic-gate #define NBRA 10 52*7c478bd9Sstevel@tonic-gate #define CIRCFL 32 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate #define CBRA 60 55*7c478bd9Sstevel@tonic-gate #define GRP 40 56*7c478bd9Sstevel@tonic-gate #define SGRP 56 57*7c478bd9Sstevel@tonic-gate #define PGRP 68 58*7c478bd9Sstevel@tonic-gate #define EGRP 44 59*7c478bd9Sstevel@tonic-gate #define RNGE 03 60*7c478bd9Sstevel@tonic-gate #define CCHR 20 61*7c478bd9Sstevel@tonic-gate #define CDOT 64 62*7c478bd9Sstevel@tonic-gate #define CCL 24 63*7c478bd9Sstevel@tonic-gate #define NCCL 8 64*7c478bd9Sstevel@tonic-gate #define CDOL 28 65*7c478bd9Sstevel@tonic-gate #define FCEOF 52 /* This was originally CEOF but it clashes with the header */ 66*7c478bd9Sstevel@tonic-gate /* definition so it was changed to FCEOF */ 67*7c478bd9Sstevel@tonic-gate #define CKET 12 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate #define STAR 01 70*7c478bd9Sstevel@tonic-gate #define PLUS 02 71*7c478bd9Sstevel@tonic-gate #define MINUS 16 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate char *__braslist[NBRA]; 74*7c478bd9Sstevel@tonic-gate char *__braelist[NBRA]; 75*7c478bd9Sstevel@tonic-gate char *__loc1; 76*7c478bd9Sstevel@tonic-gate intptr_t __bravar[NBRA]; 77*7c478bd9Sstevel@tonic-gate intptr_t *__st[SSIZE + 1]; 78*7c478bd9Sstevel@tonic-gate intptr_t *__eptr_, *__lptr_; 79*7c478bd9Sstevel@tonic-gate intptr_t __cflg; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate char * 82*7c478bd9Sstevel@tonic-gate libform_regex(char *addrc, char *addrl, char *a1) 83*7c478bd9Sstevel@tonic-gate { 84*7c478bd9Sstevel@tonic-gate intptr_t cur, in; 85*7c478bd9Sstevel@tonic-gate intptr_t *adx; 86*7c478bd9Sstevel@tonic-gate char *p1, *p2; 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate for (in = 0; in < NBRA; in++) { 89*7c478bd9Sstevel@tonic-gate __braslist[in] = 0; 90*7c478bd9Sstevel@tonic-gate __bravar[in] = -1; 91*7c478bd9Sstevel@tonic-gate } 92*7c478bd9Sstevel@tonic-gate __cflg = 0; 93*7c478bd9Sstevel@tonic-gate cur = __execute(addrc, addrl); 94*7c478bd9Sstevel@tonic-gate adx = (intptr_t *)&a1; 95*7c478bd9Sstevel@tonic-gate for (in = 0; in < NBRA; in++) { 96*7c478bd9Sstevel@tonic-gate if (((p1 = __braslist[in]) != 0) && (__bravar[in] >= 0)) { 97*7c478bd9Sstevel@tonic-gate p2 = (char *)adx[__bravar[in]]; 98*7c478bd9Sstevel@tonic-gate while (p1 < __braelist[in]) *p2++ = *p1++; 99*7c478bd9Sstevel@tonic-gate *p2 = '\0'; 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate if (!__cflg) 103*7c478bd9Sstevel@tonic-gate return ((addrl == (char *)cur) ? (char *)0 : (char *)cur); 104*7c478bd9Sstevel@tonic-gate else 105*7c478bd9Sstevel@tonic-gate return ((char *)cur); 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate intptr_t 109*7c478bd9Sstevel@tonic-gate __execute(char *addrc, char *addrl) 110*7c478bd9Sstevel@tonic-gate { 111*7c478bd9Sstevel@tonic-gate char *p1, *p2, c; 112*7c478bd9Sstevel@tonic-gate intptr_t i; 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate p1 = addrl; 115*7c478bd9Sstevel@tonic-gate p2 = addrc; 116*7c478bd9Sstevel@tonic-gate __eptr_ = (intptr_t *)&__st[SSIZE]; 117*7c478bd9Sstevel@tonic-gate __lptr_ = (intptr_t *)&__st[0]; 118*7c478bd9Sstevel@tonic-gate if (*p2 == CIRCFL) { 119*7c478bd9Sstevel@tonic-gate __loc1 = p1; 120*7c478bd9Sstevel@tonic-gate return ((i = __advance(p1, ++p2)) ? i : (intptr_t)addrl); 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate /* fast check for first character */ 123*7c478bd9Sstevel@tonic-gate if (*p2 == CCHR) { 124*7c478bd9Sstevel@tonic-gate c = p2[1]; 125*7c478bd9Sstevel@tonic-gate do { 126*7c478bd9Sstevel@tonic-gate if (*p1 != c) 127*7c478bd9Sstevel@tonic-gate continue; 128*7c478bd9Sstevel@tonic-gate __eptr_ = (intptr_t *)&__st[SSIZE]; 129*7c478bd9Sstevel@tonic-gate __lptr_ = (intptr_t *)&__st[0]; 130*7c478bd9Sstevel@tonic-gate if (i = __advance(p1, p2)) { 131*7c478bd9Sstevel@tonic-gate __loc1 = p1; 132*7c478bd9Sstevel@tonic-gate return (i); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate } while (*p1++); 135*7c478bd9Sstevel@tonic-gate return ((intptr_t)addrl); 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate /* regular algorithm */ 138*7c478bd9Sstevel@tonic-gate do { 139*7c478bd9Sstevel@tonic-gate __eptr_ = (intptr_t *)&__st[SSIZE]; 140*7c478bd9Sstevel@tonic-gate __lptr_ = (intptr_t *)&__st[0]; 141*7c478bd9Sstevel@tonic-gate if (i = __advance(p1, p2)) { 142*7c478bd9Sstevel@tonic-gate __loc1 = p1; 143*7c478bd9Sstevel@tonic-gate return (i); 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate } while (*p1++); 146*7c478bd9Sstevel@tonic-gate return ((intptr_t)addrl); 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate intptr_t 150*7c478bd9Sstevel@tonic-gate __advance(char *alp, char *aep) 151*7c478bd9Sstevel@tonic-gate { 152*7c478bd9Sstevel@tonic-gate char *lp, *ep, *curlp; 153*7c478bd9Sstevel@tonic-gate char *sep, *dp; 154*7c478bd9Sstevel@tonic-gate intptr_t i, lcnt, dcnt, gflg; 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate lp = alp; 157*7c478bd9Sstevel@tonic-gate ep = aep; 158*7c478bd9Sstevel@tonic-gate gflg = 0; 159*7c478bd9Sstevel@tonic-gate for (; ; ) { 160*7c478bd9Sstevel@tonic-gate switch (*ep++) { 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate case CCHR: 163*7c478bd9Sstevel@tonic-gate if (*ep++ == *lp++) 164*7c478bd9Sstevel@tonic-gate continue; 165*7c478bd9Sstevel@tonic-gate return (0); 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate case EGRP|RNGE: 168*7c478bd9Sstevel@tonic-gate return ((intptr_t)lp); 169*7c478bd9Sstevel@tonic-gate case EGRP: 170*7c478bd9Sstevel@tonic-gate case GRP: 171*7c478bd9Sstevel@tonic-gate ep++; 172*7c478bd9Sstevel@tonic-gate continue; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate case EGRP|STAR: 175*7c478bd9Sstevel@tonic-gate (void) __xpop(0); 176*7c478bd9Sstevel@tonic-gate case EGRP|PLUS: 177*7c478bd9Sstevel@tonic-gate (void) __xpush(0, ++ep); 178*7c478bd9Sstevel@tonic-gate return ((intptr_t)lp); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate case CDOT: 181*7c478bd9Sstevel@tonic-gate if (*lp++) 182*7c478bd9Sstevel@tonic-gate continue; 183*7c478bd9Sstevel@tonic-gate return (0); 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate case CDOL: 186*7c478bd9Sstevel@tonic-gate if (*lp == 0) 187*7c478bd9Sstevel@tonic-gate continue; 188*7c478bd9Sstevel@tonic-gate lp++; 189*7c478bd9Sstevel@tonic-gate return (0); 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate case FCEOF: 192*7c478bd9Sstevel@tonic-gate __cflg = 1; 193*7c478bd9Sstevel@tonic-gate return ((intptr_t)lp); 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate case TGRP: 196*7c478bd9Sstevel@tonic-gate case TGRP|A768: 197*7c478bd9Sstevel@tonic-gate case TGRP|A512: 198*7c478bd9Sstevel@tonic-gate case TGRP|A256: 199*7c478bd9Sstevel@tonic-gate i = (((ep[-1] & 03) << 8) + (*ep) & 0377); 200*7c478bd9Sstevel@tonic-gate ep++; 201*7c478bd9Sstevel@tonic-gate (void) __xpush(0, ep + i + 2); 202*7c478bd9Sstevel@tonic-gate (void) __xpush(0, ++ep); 203*7c478bd9Sstevel@tonic-gate (void) __xpush(0, ++ep); 204*7c478bd9Sstevel@tonic-gate gflg = 1; 205*7c478bd9Sstevel@tonic-gate (void) __getrnge(&lcnt, &dcnt, &ep[i]); 206*7c478bd9Sstevel@tonic-gate while (lcnt--) 207*7c478bd9Sstevel@tonic-gate if (!(lp = (char *)__advance(lp, ep))) 208*7c478bd9Sstevel@tonic-gate return (0); 209*7c478bd9Sstevel@tonic-gate (void) __xpush(1, curlp = lp); 210*7c478bd9Sstevel@tonic-gate while (dcnt--) 211*7c478bd9Sstevel@tonic-gate if (!(dp = (char *)__advance(lp, ep))) break; 212*7c478bd9Sstevel@tonic-gate else 213*7c478bd9Sstevel@tonic-gate (void) __xpush(1, lp = dp); 214*7c478bd9Sstevel@tonic-gate ep = (char *)__xpop(0); 215*7c478bd9Sstevel@tonic-gate goto star; 216*7c478bd9Sstevel@tonic-gate case CCHR|RNGE: 217*7c478bd9Sstevel@tonic-gate sep = ep++; 218*7c478bd9Sstevel@tonic-gate (void) __getrnge(&lcnt, &dcnt, ep); 219*7c478bd9Sstevel@tonic-gate while (lcnt--) 220*7c478bd9Sstevel@tonic-gate if (*lp++ != *sep) 221*7c478bd9Sstevel@tonic-gate return (0); 222*7c478bd9Sstevel@tonic-gate curlp = lp; 223*7c478bd9Sstevel@tonic-gate while (dcnt--) 224*7c478bd9Sstevel@tonic-gate if (*lp++ != *sep) break; 225*7c478bd9Sstevel@tonic-gate if (dcnt < 0) lp++; 226*7c478bd9Sstevel@tonic-gate ep += 2; 227*7c478bd9Sstevel@tonic-gate goto star; 228*7c478bd9Sstevel@tonic-gate case CDOT|RNGE: 229*7c478bd9Sstevel@tonic-gate (void) __getrnge(&lcnt, &dcnt, ep); 230*7c478bd9Sstevel@tonic-gate while (lcnt--) 231*7c478bd9Sstevel@tonic-gate if (*lp++ == '\0') 232*7c478bd9Sstevel@tonic-gate return (0); 233*7c478bd9Sstevel@tonic-gate curlp = lp; 234*7c478bd9Sstevel@tonic-gate while (dcnt--) 235*7c478bd9Sstevel@tonic-gate if (*lp++ == '\0') break; 236*7c478bd9Sstevel@tonic-gate if (dcnt < 0) lp++; 237*7c478bd9Sstevel@tonic-gate ep += 2; 238*7c478bd9Sstevel@tonic-gate goto star; 239*7c478bd9Sstevel@tonic-gate case CCL|RNGE: 240*7c478bd9Sstevel@tonic-gate case NCCL|RNGE: 241*7c478bd9Sstevel@tonic-gate (void) __getrnge(&lcnt, &dcnt, (ep + (*ep & 0377))); 242*7c478bd9Sstevel@tonic-gate while (lcnt--) 243*7c478bd9Sstevel@tonic-gate if (!__cclass(ep, *lp++, ep[-1] == (CCL | RNGE))) 244*7c478bd9Sstevel@tonic-gate return (0); 245*7c478bd9Sstevel@tonic-gate curlp = lp; 246*7c478bd9Sstevel@tonic-gate while (dcnt--) 247*7c478bd9Sstevel@tonic-gate if (!__cclass(ep, *lp++, ep[-1] == (CCL|RNGE))) 248*7c478bd9Sstevel@tonic-gate break; 249*7c478bd9Sstevel@tonic-gate if (dcnt < 0) lp++; 250*7c478bd9Sstevel@tonic-gate ep += (*ep + 2); 251*7c478bd9Sstevel@tonic-gate goto star; 252*7c478bd9Sstevel@tonic-gate case CCL: 253*7c478bd9Sstevel@tonic-gate if (__cclass(ep, *lp++, 1)) { 254*7c478bd9Sstevel@tonic-gate ep += *ep; 255*7c478bd9Sstevel@tonic-gate continue; 256*7c478bd9Sstevel@tonic-gate } 257*7c478bd9Sstevel@tonic-gate return (0); 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate case NCCL: 260*7c478bd9Sstevel@tonic-gate if (__cclass(ep, *lp++, 0)) { 261*7c478bd9Sstevel@tonic-gate ep += *ep; 262*7c478bd9Sstevel@tonic-gate continue; 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate return (0); 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate case CBRA: 267*7c478bd9Sstevel@tonic-gate __braslist[*ep++] = lp; 268*7c478bd9Sstevel@tonic-gate continue; 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate case CKET: 271*7c478bd9Sstevel@tonic-gate __braelist[*ep] = lp; 272*7c478bd9Sstevel@tonic-gate __bravar[*ep] = ep[1]; 273*7c478bd9Sstevel@tonic-gate ep += 2; 274*7c478bd9Sstevel@tonic-gate continue; 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate case CDOT|PLUS: 277*7c478bd9Sstevel@tonic-gate if (*lp++ == '\0') 278*7c478bd9Sstevel@tonic-gate return (0); 279*7c478bd9Sstevel@tonic-gate case CDOT|STAR: 280*7c478bd9Sstevel@tonic-gate curlp = lp; 281*7c478bd9Sstevel@tonic-gate while (*lp++); 282*7c478bd9Sstevel@tonic-gate goto star; 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate case CCHR|PLUS: 285*7c478bd9Sstevel@tonic-gate if (*lp++ != *ep) 286*7c478bd9Sstevel@tonic-gate return (0); 287*7c478bd9Sstevel@tonic-gate case CCHR|STAR: 288*7c478bd9Sstevel@tonic-gate curlp = lp; 289*7c478bd9Sstevel@tonic-gate while (*lp++ == *ep); 290*7c478bd9Sstevel@tonic-gate ep++; 291*7c478bd9Sstevel@tonic-gate goto star; 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate case PGRP: 294*7c478bd9Sstevel@tonic-gate case PGRP|A256: 295*7c478bd9Sstevel@tonic-gate case PGRP|A512: 296*7c478bd9Sstevel@tonic-gate case PGRP|A768: 297*7c478bd9Sstevel@tonic-gate if (!(lp = (char *)__advance(lp, ep+1))) 298*7c478bd9Sstevel@tonic-gate return (0); 299*7c478bd9Sstevel@tonic-gate case SGRP|A768: 300*7c478bd9Sstevel@tonic-gate case SGRP|A512: 301*7c478bd9Sstevel@tonic-gate case SGRP|A256: 302*7c478bd9Sstevel@tonic-gate case SGRP: 303*7c478bd9Sstevel@tonic-gate i = (((ep[-1]&03) << 8) + (*ep & 0377)); 304*7c478bd9Sstevel@tonic-gate ep++; 305*7c478bd9Sstevel@tonic-gate (void) __xpush(0, ep + i); 306*7c478bd9Sstevel@tonic-gate (void) __xpush(1, curlp = lp); 307*7c478bd9Sstevel@tonic-gate while (i = __advance(lp, ep)) 308*7c478bd9Sstevel@tonic-gate (void) __xpush(1, lp = (char *)i); 309*7c478bd9Sstevel@tonic-gate ep = (char *)__xpop(0); 310*7c478bd9Sstevel@tonic-gate gflg = 1; 311*7c478bd9Sstevel@tonic-gate goto star; 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate case CCL|PLUS: 314*7c478bd9Sstevel@tonic-gate case NCCL|PLUS: 315*7c478bd9Sstevel@tonic-gate if (!__cclass(ep, *lp++, ep[-1] == (CCL | PLUS))) 316*7c478bd9Sstevel@tonic-gate return (0); 317*7c478bd9Sstevel@tonic-gate case CCL|STAR: 318*7c478bd9Sstevel@tonic-gate case NCCL|STAR: 319*7c478bd9Sstevel@tonic-gate curlp = lp; 320*7c478bd9Sstevel@tonic-gate while (__cclass(ep, *lp++, ((ep[-1] == (CCL | STAR)) || 321*7c478bd9Sstevel@tonic-gate (ep[-1] == (CCL | PLUS))))); 322*7c478bd9Sstevel@tonic-gate ep += *ep; 323*7c478bd9Sstevel@tonic-gate goto star; 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate star: 326*7c478bd9Sstevel@tonic-gate do { 327*7c478bd9Sstevel@tonic-gate if (!gflg) lp--; 328*7c478bd9Sstevel@tonic-gate else if (!(lp = (char *)__xpop(1))) break; 329*7c478bd9Sstevel@tonic-gate if (i = __advance(lp, ep)) 330*7c478bd9Sstevel@tonic-gate return (i); 331*7c478bd9Sstevel@tonic-gate } while (lp > curlp); 332*7c478bd9Sstevel@tonic-gate return (0); 333*7c478bd9Sstevel@tonic-gate 334*7c478bd9Sstevel@tonic-gate default: 335*7c478bd9Sstevel@tonic-gate return (0); 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate 340*7c478bd9Sstevel@tonic-gate intptr_t 341*7c478bd9Sstevel@tonic-gate __cclass(char *aset, char ac, intptr_t af) 342*7c478bd9Sstevel@tonic-gate { 343*7c478bd9Sstevel@tonic-gate char *set, c; 344*7c478bd9Sstevel@tonic-gate intptr_t n; 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate set = (char *)aset; 347*7c478bd9Sstevel@tonic-gate if ((c = ac) == 0) 348*7c478bd9Sstevel@tonic-gate return (0); 349*7c478bd9Sstevel@tonic-gate n = *set++; 350*7c478bd9Sstevel@tonic-gate while (--n) { 351*7c478bd9Sstevel@tonic-gate if (*set == MINUS) { 352*7c478bd9Sstevel@tonic-gate if ((set[2] - set[1]) < 0) 353*7c478bd9Sstevel@tonic-gate return (0); 354*7c478bd9Sstevel@tonic-gate if (*++set <= c) { 355*7c478bd9Sstevel@tonic-gate if (c <= *++set) 356*7c478bd9Sstevel@tonic-gate return (af); 357*7c478bd9Sstevel@tonic-gate } else 358*7c478bd9Sstevel@tonic-gate ++set; 359*7c478bd9Sstevel@tonic-gate ++set; 360*7c478bd9Sstevel@tonic-gate n -= 2; 361*7c478bd9Sstevel@tonic-gate continue; 362*7c478bd9Sstevel@tonic-gate } 363*7c478bd9Sstevel@tonic-gate if (*set++ == c) 364*7c478bd9Sstevel@tonic-gate return (af); 365*7c478bd9Sstevel@tonic-gate } 366*7c478bd9Sstevel@tonic-gate return (!af); 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate intptr_t 370*7c478bd9Sstevel@tonic-gate __xpush(intptr_t i, char *p) 371*7c478bd9Sstevel@tonic-gate { 372*7c478bd9Sstevel@tonic-gate if (__lptr_ >= __eptr_) { 373*7c478bd9Sstevel@tonic-gate (void) write(2, "stack overflow\n", 15); 374*7c478bd9Sstevel@tonic-gate (void) exit(1); 375*7c478bd9Sstevel@tonic-gate } 376*7c478bd9Sstevel@tonic-gate if (i) 377*7c478bd9Sstevel@tonic-gate *__lptr_++ = (intptr_t)p; 378*7c478bd9Sstevel@tonic-gate else 379*7c478bd9Sstevel@tonic-gate *__eptr_-- = (intptr_t)p; 380*7c478bd9Sstevel@tonic-gate return (1); 381*7c478bd9Sstevel@tonic-gate } 382*7c478bd9Sstevel@tonic-gate 383*7c478bd9Sstevel@tonic-gate intptr_t 384*7c478bd9Sstevel@tonic-gate __xpop(intptr_t i) 385*7c478bd9Sstevel@tonic-gate { 386*7c478bd9Sstevel@tonic-gate if (i) 387*7c478bd9Sstevel@tonic-gate return ((__lptr_ < (intptr_t *)&__st[0]) ? 0 : *--__lptr_); 388*7c478bd9Sstevel@tonic-gate else 389*7c478bd9Sstevel@tonic-gate return ((__eptr_ > (intptr_t *)&__st[SSIZE]) ? 0 : *++__eptr_); 390*7c478bd9Sstevel@tonic-gate } 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate intptr_t 393*7c478bd9Sstevel@tonic-gate __getrnge(intptr_t *i, intptr_t *j, char *k) 394*7c478bd9Sstevel@tonic-gate { 395*7c478bd9Sstevel@tonic-gate *i = (*k++&0377); 396*7c478bd9Sstevel@tonic-gate if (*k == (char)-1) 397*7c478bd9Sstevel@tonic-gate *j = 20000; 398*7c478bd9Sstevel@tonic-gate else 399*7c478bd9Sstevel@tonic-gate *j = ((*k&0377) - *i); 400*7c478bd9Sstevel@tonic-gate return (1); 401*7c478bd9Sstevel@tonic-gate } 402