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 1997-2002 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 #ifndef _REGEXP_H 32*7c478bd9Sstevel@tonic-gate #define _REGEXP_H 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <string.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 39*7c478bd9Sstevel@tonic-gate extern "C" { 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #define CBRA 2 43*7c478bd9Sstevel@tonic-gate #define CCHR 4 44*7c478bd9Sstevel@tonic-gate #define CDOT 8 45*7c478bd9Sstevel@tonic-gate #define CCL 12 46*7c478bd9Sstevel@tonic-gate #define CXCL 16 47*7c478bd9Sstevel@tonic-gate #define CDOL 20 48*7c478bd9Sstevel@tonic-gate #define CCEOF 22 49*7c478bd9Sstevel@tonic-gate #define CKET 24 50*7c478bd9Sstevel@tonic-gate #define CBACK 36 51*7c478bd9Sstevel@tonic-gate #define NCCL 40 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #define STAR 01 54*7c478bd9Sstevel@tonic-gate #define RNGE 03 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #define NBRA 9 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #define PLACE(c) ep[c >> 3] |= bittab[c & 07] 59*7c478bd9Sstevel@tonic-gate #define ISTHERE(c) (ep[c >> 3] & bittab[c & 07]) 60*7c478bd9Sstevel@tonic-gate #define ecmp(s1, s2, n) (strncmp(s1, s2, n) == 0) 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate static char *braslist[NBRA]; 63*7c478bd9Sstevel@tonic-gate static char *braelist[NBRA]; 64*7c478bd9Sstevel@tonic-gate int sed, nbra; 65*7c478bd9Sstevel@tonic-gate char *loc1, *loc2, *locs; 66*7c478bd9Sstevel@tonic-gate static int nodelim; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate int circf; 69*7c478bd9Sstevel@tonic-gate static int low; 70*7c478bd9Sstevel@tonic-gate static int size; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate static unsigned char bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 75*7c478bd9Sstevel@tonic-gate int advance(const char *lp, const char *ep); 76*7c478bd9Sstevel@tonic-gate static void getrnge(const char *str); 77*7c478bd9Sstevel@tonic-gate #else 78*7c478bd9Sstevel@tonic-gate int advance(); 79*7c478bd9Sstevel@tonic-gate static void getrnge(); 80*7c478bd9Sstevel@tonic-gate #endif 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate char * 83*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 84*7c478bd9Sstevel@tonic-gate compile(char *instring, char *ep, const char *endbuf, int seof) 85*7c478bd9Sstevel@tonic-gate #else 86*7c478bd9Sstevel@tonic-gate compile(instring, ep, endbuf, seof) 87*7c478bd9Sstevel@tonic-gate register char *ep; 88*7c478bd9Sstevel@tonic-gate char *instring, *endbuf; 89*7c478bd9Sstevel@tonic-gate int seof; 90*7c478bd9Sstevel@tonic-gate #endif 91*7c478bd9Sstevel@tonic-gate { 92*7c478bd9Sstevel@tonic-gate INIT /* Dependent declarations and initializations */ 93*7c478bd9Sstevel@tonic-gate register int c; 94*7c478bd9Sstevel@tonic-gate register int eof = seof; 95*7c478bd9Sstevel@tonic-gate char *lastep; 96*7c478bd9Sstevel@tonic-gate int cclcnt; 97*7c478bd9Sstevel@tonic-gate char bracket[NBRA], *bracketp; 98*7c478bd9Sstevel@tonic-gate int closed; 99*7c478bd9Sstevel@tonic-gate int neg; 100*7c478bd9Sstevel@tonic-gate int lc; 101*7c478bd9Sstevel@tonic-gate int i, cflg; 102*7c478bd9Sstevel@tonic-gate int iflag; /* used for non-ascii characters in brackets */ 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate lastep = NULL; 105*7c478bd9Sstevel@tonic-gate if ((c = GETC()) == eof || c == '\n') { 106*7c478bd9Sstevel@tonic-gate if (c == '\n') { 107*7c478bd9Sstevel@tonic-gate UNGETC(c); 108*7c478bd9Sstevel@tonic-gate nodelim = 1; 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate if (*ep == 0 && !sed) 111*7c478bd9Sstevel@tonic-gate ERROR(41); 112*7c478bd9Sstevel@tonic-gate RETURN(ep); 113*7c478bd9Sstevel@tonic-gate } 114*7c478bd9Sstevel@tonic-gate bracketp = bracket; 115*7c478bd9Sstevel@tonic-gate circf = closed = nbra = 0; 116*7c478bd9Sstevel@tonic-gate if (c == '^') 117*7c478bd9Sstevel@tonic-gate circf++; 118*7c478bd9Sstevel@tonic-gate else 119*7c478bd9Sstevel@tonic-gate UNGETC(c); 120*7c478bd9Sstevel@tonic-gate while (1) { 121*7c478bd9Sstevel@tonic-gate if (ep >= endbuf) 122*7c478bd9Sstevel@tonic-gate ERROR(50); 123*7c478bd9Sstevel@tonic-gate c = GETC(); 124*7c478bd9Sstevel@tonic-gate if (c != '*' && ((c != '\\') || (PEEKC() != '{'))) 125*7c478bd9Sstevel@tonic-gate lastep = ep; 126*7c478bd9Sstevel@tonic-gate if (c == eof) { 127*7c478bd9Sstevel@tonic-gate *ep++ = CCEOF; 128*7c478bd9Sstevel@tonic-gate if (bracketp != bracket) 129*7c478bd9Sstevel@tonic-gate ERROR(42); 130*7c478bd9Sstevel@tonic-gate RETURN(ep); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate switch (c) { 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate case '.': 135*7c478bd9Sstevel@tonic-gate *ep++ = CDOT; 136*7c478bd9Sstevel@tonic-gate continue; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate case '\n': 139*7c478bd9Sstevel@tonic-gate if (!sed) { 140*7c478bd9Sstevel@tonic-gate UNGETC(c); 141*7c478bd9Sstevel@tonic-gate *ep++ = CCEOF; 142*7c478bd9Sstevel@tonic-gate nodelim = 1; 143*7c478bd9Sstevel@tonic-gate if (bracketp != bracket) 144*7c478bd9Sstevel@tonic-gate ERROR(42); 145*7c478bd9Sstevel@tonic-gate RETURN(ep); 146*7c478bd9Sstevel@tonic-gate } else ERROR(36); 147*7c478bd9Sstevel@tonic-gate case '*': 148*7c478bd9Sstevel@tonic-gate if (lastep == NULL || *lastep == CBRA || 149*7c478bd9Sstevel@tonic-gate *lastep == CKET) 150*7c478bd9Sstevel@tonic-gate goto defchar; 151*7c478bd9Sstevel@tonic-gate *lastep |= STAR; 152*7c478bd9Sstevel@tonic-gate continue; 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate case '$': 155*7c478bd9Sstevel@tonic-gate if (PEEKC() != eof && PEEKC() != '\n') 156*7c478bd9Sstevel@tonic-gate goto defchar; 157*7c478bd9Sstevel@tonic-gate *ep++ = CDOL; 158*7c478bd9Sstevel@tonic-gate continue; 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate case '[': 161*7c478bd9Sstevel@tonic-gate if (&ep[17] >= endbuf) 162*7c478bd9Sstevel@tonic-gate ERROR(50); 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate *ep++ = CCL; 165*7c478bd9Sstevel@tonic-gate lc = 0; 166*7c478bd9Sstevel@tonic-gate for (i = 0; i < 16; i++) 167*7c478bd9Sstevel@tonic-gate ep[i] = 0; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate neg = 0; 170*7c478bd9Sstevel@tonic-gate if ((c = GETC()) == '^') { 171*7c478bd9Sstevel@tonic-gate neg = 1; 172*7c478bd9Sstevel@tonic-gate c = GETC(); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate iflag = 1; 175*7c478bd9Sstevel@tonic-gate do { 176*7c478bd9Sstevel@tonic-gate c &= 0377; 177*7c478bd9Sstevel@tonic-gate if (c == '\0' || c == '\n') 178*7c478bd9Sstevel@tonic-gate ERROR(49); 179*7c478bd9Sstevel@tonic-gate if ((c & 0200) && iflag) { 180*7c478bd9Sstevel@tonic-gate iflag = 0; 181*7c478bd9Sstevel@tonic-gate if (&ep[32] >= endbuf) 182*7c478bd9Sstevel@tonic-gate ERROR(50); 183*7c478bd9Sstevel@tonic-gate ep[-1] = CXCL; 184*7c478bd9Sstevel@tonic-gate for (i = 16; i < 32; i++) 185*7c478bd9Sstevel@tonic-gate ep[i] = 0; 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate if (c == '-' && lc != 0) { 188*7c478bd9Sstevel@tonic-gate if ((c = GETC()) == ']') { 189*7c478bd9Sstevel@tonic-gate PLACE('-'); 190*7c478bd9Sstevel@tonic-gate break; 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate if ((c & 0200) && iflag) { 193*7c478bd9Sstevel@tonic-gate iflag = 0; 194*7c478bd9Sstevel@tonic-gate if (&ep[32] >= endbuf) 195*7c478bd9Sstevel@tonic-gate ERROR(50); 196*7c478bd9Sstevel@tonic-gate ep[-1] = CXCL; 197*7c478bd9Sstevel@tonic-gate for (i = 16; i < 32; i++) 198*7c478bd9Sstevel@tonic-gate ep[i] = 0; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate while (lc < c) { 201*7c478bd9Sstevel@tonic-gate PLACE(lc); 202*7c478bd9Sstevel@tonic-gate lc++; 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate lc = c; 206*7c478bd9Sstevel@tonic-gate PLACE(c); 207*7c478bd9Sstevel@tonic-gate } while ((c = GETC()) != ']'); 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate if (iflag) 210*7c478bd9Sstevel@tonic-gate iflag = 16; 211*7c478bd9Sstevel@tonic-gate else 212*7c478bd9Sstevel@tonic-gate iflag = 32; 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate if (neg) { 215*7c478bd9Sstevel@tonic-gate if (iflag == 32) { 216*7c478bd9Sstevel@tonic-gate for (cclcnt = 0; cclcnt < iflag; 217*7c478bd9Sstevel@tonic-gate cclcnt++) 218*7c478bd9Sstevel@tonic-gate ep[cclcnt] ^= 0377; 219*7c478bd9Sstevel@tonic-gate ep[0] &= 0376; 220*7c478bd9Sstevel@tonic-gate } else { 221*7c478bd9Sstevel@tonic-gate ep[-1] = NCCL; 222*7c478bd9Sstevel@tonic-gate /* make nulls match so test fails */ 223*7c478bd9Sstevel@tonic-gate ep[0] |= 01; 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate ep += iflag; 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate continue; 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate case '\\': 232*7c478bd9Sstevel@tonic-gate switch (c = GETC()) { 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate case '(': 235*7c478bd9Sstevel@tonic-gate if (nbra >= NBRA) 236*7c478bd9Sstevel@tonic-gate ERROR(43); 237*7c478bd9Sstevel@tonic-gate *bracketp++ = (char)nbra; 238*7c478bd9Sstevel@tonic-gate *ep++ = CBRA; 239*7c478bd9Sstevel@tonic-gate *ep++ = (char)nbra++; 240*7c478bd9Sstevel@tonic-gate continue; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate case ')': 243*7c478bd9Sstevel@tonic-gate if (bracketp <= bracket) 244*7c478bd9Sstevel@tonic-gate ERROR(42); 245*7c478bd9Sstevel@tonic-gate *ep++ = CKET; 246*7c478bd9Sstevel@tonic-gate *ep++ = *--bracketp; 247*7c478bd9Sstevel@tonic-gate closed++; 248*7c478bd9Sstevel@tonic-gate continue; 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate case '{': 251*7c478bd9Sstevel@tonic-gate if (lastep == NULL) 252*7c478bd9Sstevel@tonic-gate goto defchar; 253*7c478bd9Sstevel@tonic-gate *lastep |= RNGE; 254*7c478bd9Sstevel@tonic-gate cflg = 0; 255*7c478bd9Sstevel@tonic-gate nlim: 256*7c478bd9Sstevel@tonic-gate c = GETC(); 257*7c478bd9Sstevel@tonic-gate i = 0; 258*7c478bd9Sstevel@tonic-gate do { 259*7c478bd9Sstevel@tonic-gate if ('0' <= c && c <= '9') 260*7c478bd9Sstevel@tonic-gate i = 10 * i + c - '0'; 261*7c478bd9Sstevel@tonic-gate else 262*7c478bd9Sstevel@tonic-gate ERROR(16); 263*7c478bd9Sstevel@tonic-gate } while (((c = GETC()) != '\\') && (c != ',')); 264*7c478bd9Sstevel@tonic-gate if (i >= 255) 265*7c478bd9Sstevel@tonic-gate ERROR(11); 266*7c478bd9Sstevel@tonic-gate *ep++ = (char)i; 267*7c478bd9Sstevel@tonic-gate if (c == ',') { 268*7c478bd9Sstevel@tonic-gate if (cflg++) 269*7c478bd9Sstevel@tonic-gate ERROR(44); 270*7c478bd9Sstevel@tonic-gate if ((c = GETC()) == '\\') 271*7c478bd9Sstevel@tonic-gate *ep++ = (char)255; 272*7c478bd9Sstevel@tonic-gate else { 273*7c478bd9Sstevel@tonic-gate UNGETC(c); 274*7c478bd9Sstevel@tonic-gate goto nlim; 275*7c478bd9Sstevel@tonic-gate /* get 2'nd number */ 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate if (GETC() != '}') 279*7c478bd9Sstevel@tonic-gate ERROR(45); 280*7c478bd9Sstevel@tonic-gate if (!cflg) /* one number */ 281*7c478bd9Sstevel@tonic-gate *ep++ = (char)i; 282*7c478bd9Sstevel@tonic-gate else if ((ep[-1] & 0377) < (ep[-2] & 0377)) 283*7c478bd9Sstevel@tonic-gate ERROR(46); 284*7c478bd9Sstevel@tonic-gate continue; 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate case '\n': 287*7c478bd9Sstevel@tonic-gate ERROR(36); 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate case 'n': 290*7c478bd9Sstevel@tonic-gate c = '\n'; 291*7c478bd9Sstevel@tonic-gate goto defchar; 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate default: 294*7c478bd9Sstevel@tonic-gate if (c >= '1' && c <= '9') { 295*7c478bd9Sstevel@tonic-gate if ((c -= '1') >= closed) 296*7c478bd9Sstevel@tonic-gate ERROR(25); 297*7c478bd9Sstevel@tonic-gate *ep++ = CBACK; 298*7c478bd9Sstevel@tonic-gate *ep++ = (char)c; 299*7c478bd9Sstevel@tonic-gate continue; 300*7c478bd9Sstevel@tonic-gate } 301*7c478bd9Sstevel@tonic-gate } 302*7c478bd9Sstevel@tonic-gate /* Drop through to default to use \ to turn off special chars */ 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate defchar: 305*7c478bd9Sstevel@tonic-gate default: 306*7c478bd9Sstevel@tonic-gate lastep = ep; 307*7c478bd9Sstevel@tonic-gate *ep++ = CCHR; 308*7c478bd9Sstevel@tonic-gate *ep++ = (char)c; 309*7c478bd9Sstevel@tonic-gate } 310*7c478bd9Sstevel@tonic-gate } 311*7c478bd9Sstevel@tonic-gate } 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 314*7c478bd9Sstevel@tonic-gate int 315*7c478bd9Sstevel@tonic-gate step(const char *p1, const char *p2) 316*7c478bd9Sstevel@tonic-gate #else 317*7c478bd9Sstevel@tonic-gate int 318*7c478bd9Sstevel@tonic-gate step(p1, p2) 319*7c478bd9Sstevel@tonic-gate register char *p1, *p2; 320*7c478bd9Sstevel@tonic-gate #endif 321*7c478bd9Sstevel@tonic-gate { 322*7c478bd9Sstevel@tonic-gate char c; 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate if (circf) { 326*7c478bd9Sstevel@tonic-gate loc1 = (char *)p1; 327*7c478bd9Sstevel@tonic-gate return (advance(p1, p2)); 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate /* fast check for first character */ 330*7c478bd9Sstevel@tonic-gate if (*p2 == CCHR) { 331*7c478bd9Sstevel@tonic-gate c = p2[1]; 332*7c478bd9Sstevel@tonic-gate do { 333*7c478bd9Sstevel@tonic-gate if (*p1 != c) 334*7c478bd9Sstevel@tonic-gate continue; 335*7c478bd9Sstevel@tonic-gate if (advance(p1, p2)) { 336*7c478bd9Sstevel@tonic-gate loc1 = (char *)p1; 337*7c478bd9Sstevel@tonic-gate return (1); 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate } while (*p1++); 340*7c478bd9Sstevel@tonic-gate return (0); 341*7c478bd9Sstevel@tonic-gate } 342*7c478bd9Sstevel@tonic-gate /* regular algorithm */ 343*7c478bd9Sstevel@tonic-gate do { 344*7c478bd9Sstevel@tonic-gate if (advance(p1, p2)) { 345*7c478bd9Sstevel@tonic-gate loc1 = (char *)p1; 346*7c478bd9Sstevel@tonic-gate return (1); 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate } while (*p1++); 349*7c478bd9Sstevel@tonic-gate return (0); 350*7c478bd9Sstevel@tonic-gate } 351*7c478bd9Sstevel@tonic-gate 352*7c478bd9Sstevel@tonic-gate int 353*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 354*7c478bd9Sstevel@tonic-gate advance(const char *lp, const char *ep) 355*7c478bd9Sstevel@tonic-gate #else 356*7c478bd9Sstevel@tonic-gate advance(lp, ep) 357*7c478bd9Sstevel@tonic-gate register char *lp, *ep; 358*7c478bd9Sstevel@tonic-gate #endif 359*7c478bd9Sstevel@tonic-gate { 360*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 361*7c478bd9Sstevel@tonic-gate const char *curlp; 362*7c478bd9Sstevel@tonic-gate #else 363*7c478bd9Sstevel@tonic-gate register char *curlp; 364*7c478bd9Sstevel@tonic-gate #endif 365*7c478bd9Sstevel@tonic-gate int c; 366*7c478bd9Sstevel@tonic-gate char *bbeg; 367*7c478bd9Sstevel@tonic-gate register char neg; 368*7c478bd9Sstevel@tonic-gate size_t ct; 369*7c478bd9Sstevel@tonic-gate 370*7c478bd9Sstevel@tonic-gate while (1) { 371*7c478bd9Sstevel@tonic-gate neg = 0; 372*7c478bd9Sstevel@tonic-gate switch (*ep++) { 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate case CCHR: 375*7c478bd9Sstevel@tonic-gate if (*ep++ == *lp++) 376*7c478bd9Sstevel@tonic-gate continue; 377*7c478bd9Sstevel@tonic-gate return (0); 378*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate case CDOT: 381*7c478bd9Sstevel@tonic-gate if (*lp++) 382*7c478bd9Sstevel@tonic-gate continue; 383*7c478bd9Sstevel@tonic-gate return (0); 384*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate case CDOL: 387*7c478bd9Sstevel@tonic-gate if (*lp == 0) 388*7c478bd9Sstevel@tonic-gate continue; 389*7c478bd9Sstevel@tonic-gate return (0); 390*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate case CCEOF: 393*7c478bd9Sstevel@tonic-gate loc2 = (char *)lp; 394*7c478bd9Sstevel@tonic-gate return (1); 395*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 396*7c478bd9Sstevel@tonic-gate 397*7c478bd9Sstevel@tonic-gate case CXCL: 398*7c478bd9Sstevel@tonic-gate c = (unsigned char)*lp++; 399*7c478bd9Sstevel@tonic-gate if (ISTHERE(c)) { 400*7c478bd9Sstevel@tonic-gate ep += 32; 401*7c478bd9Sstevel@tonic-gate continue; 402*7c478bd9Sstevel@tonic-gate } 403*7c478bd9Sstevel@tonic-gate return (0); 404*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 405*7c478bd9Sstevel@tonic-gate 406*7c478bd9Sstevel@tonic-gate case NCCL: 407*7c478bd9Sstevel@tonic-gate neg = 1; 408*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate case CCL: 411*7c478bd9Sstevel@tonic-gate c = *lp++; 412*7c478bd9Sstevel@tonic-gate if (((c & 0200) == 0 && ISTHERE(c)) ^ neg) { 413*7c478bd9Sstevel@tonic-gate ep += 16; 414*7c478bd9Sstevel@tonic-gate continue; 415*7c478bd9Sstevel@tonic-gate } 416*7c478bd9Sstevel@tonic-gate return (0); 417*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 418*7c478bd9Sstevel@tonic-gate 419*7c478bd9Sstevel@tonic-gate case CBRA: 420*7c478bd9Sstevel@tonic-gate braslist[*ep++] = (char *)lp; 421*7c478bd9Sstevel@tonic-gate continue; 422*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 423*7c478bd9Sstevel@tonic-gate 424*7c478bd9Sstevel@tonic-gate case CKET: 425*7c478bd9Sstevel@tonic-gate braelist[*ep++] = (char *)lp; 426*7c478bd9Sstevel@tonic-gate continue; 427*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 428*7c478bd9Sstevel@tonic-gate 429*7c478bd9Sstevel@tonic-gate case CCHR | RNGE: 430*7c478bd9Sstevel@tonic-gate c = *ep++; 431*7c478bd9Sstevel@tonic-gate getrnge(ep); 432*7c478bd9Sstevel@tonic-gate while (low--) 433*7c478bd9Sstevel@tonic-gate if (*lp++ != c) 434*7c478bd9Sstevel@tonic-gate return (0); 435*7c478bd9Sstevel@tonic-gate curlp = lp; 436*7c478bd9Sstevel@tonic-gate while (size--) 437*7c478bd9Sstevel@tonic-gate if (*lp++ != c) 438*7c478bd9Sstevel@tonic-gate break; 439*7c478bd9Sstevel@tonic-gate if (size < 0) 440*7c478bd9Sstevel@tonic-gate lp++; 441*7c478bd9Sstevel@tonic-gate ep += 2; 442*7c478bd9Sstevel@tonic-gate goto star; 443*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 444*7c478bd9Sstevel@tonic-gate 445*7c478bd9Sstevel@tonic-gate case CDOT | RNGE: 446*7c478bd9Sstevel@tonic-gate getrnge(ep); 447*7c478bd9Sstevel@tonic-gate while (low--) 448*7c478bd9Sstevel@tonic-gate if (*lp++ == '\0') 449*7c478bd9Sstevel@tonic-gate return (0); 450*7c478bd9Sstevel@tonic-gate curlp = lp; 451*7c478bd9Sstevel@tonic-gate while (size--) 452*7c478bd9Sstevel@tonic-gate if (*lp++ == '\0') 453*7c478bd9Sstevel@tonic-gate break; 454*7c478bd9Sstevel@tonic-gate if (size < 0) 455*7c478bd9Sstevel@tonic-gate lp++; 456*7c478bd9Sstevel@tonic-gate ep += 2; 457*7c478bd9Sstevel@tonic-gate goto star; 458*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 459*7c478bd9Sstevel@tonic-gate 460*7c478bd9Sstevel@tonic-gate case CXCL | RNGE: 461*7c478bd9Sstevel@tonic-gate getrnge(ep + 32); 462*7c478bd9Sstevel@tonic-gate while (low--) { 463*7c478bd9Sstevel@tonic-gate c = (unsigned char)*lp++; 464*7c478bd9Sstevel@tonic-gate if (!ISTHERE(c)) 465*7c478bd9Sstevel@tonic-gate return (0); 466*7c478bd9Sstevel@tonic-gate } 467*7c478bd9Sstevel@tonic-gate curlp = lp; 468*7c478bd9Sstevel@tonic-gate while (size--) { 469*7c478bd9Sstevel@tonic-gate c = (unsigned char)*lp++; 470*7c478bd9Sstevel@tonic-gate if (!ISTHERE(c)) 471*7c478bd9Sstevel@tonic-gate break; 472*7c478bd9Sstevel@tonic-gate } 473*7c478bd9Sstevel@tonic-gate if (size < 0) 474*7c478bd9Sstevel@tonic-gate lp++; 475*7c478bd9Sstevel@tonic-gate ep += 34; /* 32 + 2 */ 476*7c478bd9Sstevel@tonic-gate goto star; 477*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate case NCCL | RNGE: 480*7c478bd9Sstevel@tonic-gate neg = 1; 481*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 482*7c478bd9Sstevel@tonic-gate 483*7c478bd9Sstevel@tonic-gate case CCL | RNGE: 484*7c478bd9Sstevel@tonic-gate getrnge(ep + 16); 485*7c478bd9Sstevel@tonic-gate while (low--) { 486*7c478bd9Sstevel@tonic-gate c = *lp++; 487*7c478bd9Sstevel@tonic-gate if (((c & 0200) || !ISTHERE(c)) ^ neg) 488*7c478bd9Sstevel@tonic-gate return (0); 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate curlp = lp; 491*7c478bd9Sstevel@tonic-gate while (size--) { 492*7c478bd9Sstevel@tonic-gate c = *lp++; 493*7c478bd9Sstevel@tonic-gate if (((c & 0200) || !ISTHERE(c)) ^ neg) 494*7c478bd9Sstevel@tonic-gate break; 495*7c478bd9Sstevel@tonic-gate } 496*7c478bd9Sstevel@tonic-gate if (size < 0) 497*7c478bd9Sstevel@tonic-gate lp++; 498*7c478bd9Sstevel@tonic-gate ep += 18; /* 16 + 2 */ 499*7c478bd9Sstevel@tonic-gate goto star; 500*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 501*7c478bd9Sstevel@tonic-gate 502*7c478bd9Sstevel@tonic-gate case CBACK: 503*7c478bd9Sstevel@tonic-gate bbeg = braslist[*ep]; 504*7c478bd9Sstevel@tonic-gate ct = braelist[*ep++] - bbeg; 505*7c478bd9Sstevel@tonic-gate 506*7c478bd9Sstevel@tonic-gate if (ecmp(bbeg, lp, ct)) { 507*7c478bd9Sstevel@tonic-gate lp += ct; 508*7c478bd9Sstevel@tonic-gate continue; 509*7c478bd9Sstevel@tonic-gate } 510*7c478bd9Sstevel@tonic-gate return (0); 511*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 512*7c478bd9Sstevel@tonic-gate 513*7c478bd9Sstevel@tonic-gate case CBACK | STAR: 514*7c478bd9Sstevel@tonic-gate bbeg = braslist[*ep]; 515*7c478bd9Sstevel@tonic-gate ct = braelist[*ep++] - bbeg; 516*7c478bd9Sstevel@tonic-gate curlp = lp; 517*7c478bd9Sstevel@tonic-gate while (ecmp(bbeg, lp, ct)) 518*7c478bd9Sstevel@tonic-gate lp += ct; 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate while (lp >= curlp) { 521*7c478bd9Sstevel@tonic-gate if (advance(lp, ep)) 522*7c478bd9Sstevel@tonic-gate return (1); 523*7c478bd9Sstevel@tonic-gate lp -= ct; 524*7c478bd9Sstevel@tonic-gate } 525*7c478bd9Sstevel@tonic-gate return (0); 526*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 527*7c478bd9Sstevel@tonic-gate 528*7c478bd9Sstevel@tonic-gate case CDOT | STAR: 529*7c478bd9Sstevel@tonic-gate curlp = lp; 530*7c478bd9Sstevel@tonic-gate while (*lp++); 531*7c478bd9Sstevel@tonic-gate goto star; 532*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 533*7c478bd9Sstevel@tonic-gate 534*7c478bd9Sstevel@tonic-gate case CCHR | STAR: 535*7c478bd9Sstevel@tonic-gate curlp = lp; 536*7c478bd9Sstevel@tonic-gate while (*lp++ == *ep); 537*7c478bd9Sstevel@tonic-gate ep++; 538*7c478bd9Sstevel@tonic-gate goto star; 539*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 540*7c478bd9Sstevel@tonic-gate 541*7c478bd9Sstevel@tonic-gate case CXCL | STAR: 542*7c478bd9Sstevel@tonic-gate curlp = lp; 543*7c478bd9Sstevel@tonic-gate do { 544*7c478bd9Sstevel@tonic-gate c = (unsigned char)*lp++; 545*7c478bd9Sstevel@tonic-gate } while (ISTHERE(c)); 546*7c478bd9Sstevel@tonic-gate ep += 32; 547*7c478bd9Sstevel@tonic-gate goto star; 548*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate case NCCL | STAR: 551*7c478bd9Sstevel@tonic-gate neg = 1; 552*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 553*7c478bd9Sstevel@tonic-gate 554*7c478bd9Sstevel@tonic-gate case CCL | STAR: 555*7c478bd9Sstevel@tonic-gate curlp = lp; 556*7c478bd9Sstevel@tonic-gate do { 557*7c478bd9Sstevel@tonic-gate c = *lp++; 558*7c478bd9Sstevel@tonic-gate } while (((c & 0200) == 0 && ISTHERE(c)) ^ neg); 559*7c478bd9Sstevel@tonic-gate ep += 16; 560*7c478bd9Sstevel@tonic-gate goto star; 561*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 562*7c478bd9Sstevel@tonic-gate 563*7c478bd9Sstevel@tonic-gate star: 564*7c478bd9Sstevel@tonic-gate do { 565*7c478bd9Sstevel@tonic-gate if (--lp == locs) 566*7c478bd9Sstevel@tonic-gate break; 567*7c478bd9Sstevel@tonic-gate if (advance(lp, ep)) 568*7c478bd9Sstevel@tonic-gate return (1); 569*7c478bd9Sstevel@tonic-gate } while (lp > curlp); 570*7c478bd9Sstevel@tonic-gate return (0); 571*7c478bd9Sstevel@tonic-gate 572*7c478bd9Sstevel@tonic-gate } 573*7c478bd9Sstevel@tonic-gate } 574*7c478bd9Sstevel@tonic-gate } 575*7c478bd9Sstevel@tonic-gate 576*7c478bd9Sstevel@tonic-gate static void 577*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 578*7c478bd9Sstevel@tonic-gate getrnge(const char *str) 579*7c478bd9Sstevel@tonic-gate #else 580*7c478bd9Sstevel@tonic-gate getrnge(str) 581*7c478bd9Sstevel@tonic-gate register char *str; 582*7c478bd9Sstevel@tonic-gate #endif 583*7c478bd9Sstevel@tonic-gate { 584*7c478bd9Sstevel@tonic-gate low = *str++ & 0377; 585*7c478bd9Sstevel@tonic-gate size = ((*str & 0377) == 255)? 20000: (*str &0377) - low; 586*7c478bd9Sstevel@tonic-gate } 587*7c478bd9Sstevel@tonic-gate 588*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 589*7c478bd9Sstevel@tonic-gate } 590*7c478bd9Sstevel@tonic-gate #endif 591*7c478bd9Sstevel@tonic-gate 592*7c478bd9Sstevel@tonic-gate #endif /* _REGEXP_H */ 593