compile.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#define GETC(x) (*x++)
#define PEEKC(x) (*x)
#define UNGETC(x) (--x)
#define CBRA 2
#define CCHR 4
#define CDOT 8
#define CCL 12
#define CXCL 16
#define CDOL 20
#define CCEOF 22
#define CKET 24
#define CBACK 36
#define NCCL 40
#define STAR 01
#define RNGE 03
#define NBRA 9
static int nodelim;
int circf;
static int low;
static int size;
/*
* 128 cannot be represented in a char (it becomes -127) - thus
* decl changed to unsigned char.
*/
char *
register char *ep;
void (*errfunc)();
{
register c;
int cclcnt;
int closed;
int neg;
int lc;
int i, cflg;
int iflag; /* used for non-ascii characters in brackets */
/*
(re)initialize globals (necessary so that if compile()
is called more than once, globals will be reset ... see
fmlexpr() which references several of these globals)
*/
lastep = 0;
if(c == '\n') {
nodelim = 1;
}
(*errfunc)(41);
return(ep);
}
if(c == '^')
circf++;
else
while(1) {
(*errfunc)(50);
if(c == eof) {
(*errfunc)(42);
return(ep);
}
switch(c) {
case '.':
continue;
case '\n':
if(!sed) {
nodelim = 1;
(*errfunc)(42);
return(ep);
}
else (*errfunc)(36);
case '*':
goto defchar;
continue;
case '$':
goto defchar;
continue;
case '[':
(*errfunc)(50);
lc = 0;
for(i = 0; i < 16; i++)
ep[i] = 0;
neg = 0;
neg = 1;
}
iflag = 1;
do {
c &= 0377;
if(c == '\0' || c == '\n')
(*errfunc)(49);
if((c & 0200) && iflag) {
iflag = 0;
(*errfunc)(50);
for(i = 16; i < 32; i++)
ep[i] = 0;
}
if(c == '-' && lc != 0) {
PLACE('-');
break;
}
if((c & 0200) && iflag) {
iflag = 0;
(*errfunc)(50);
for(i = 16; i < 32; i++)
ep[i] = 0;
}
while(lc < c ) {
lc++;
}
}
lc = c;
PLACE(c);
if(iflag)
iflag = 16;
else
iflag = 32;
if(neg) {
if(iflag == 32) {
ep[0] &= 0376;
} else {
/* make nulls match so test fails */
ep[0] |= 01;
}
}
continue;
case '\\':
case '(':
(*errfunc)(43);
continue;
case ')':
(*errfunc)(42);
closed++;
continue;
case '{':
if(lastep == (char *) 0)
goto defchar;
cflg = 0;
nlim:
i = 0;
do {
if('0' <= c && c <= '9')
i = 10 * i + c - '0';
else
(*errfunc)(16);
if(i >= 255)
(*errfunc)(11);
*ep++ = i;
if(c == ',') {
if(cflg++)
(*errfunc)(44);
*ep++ = 255;
else {
goto nlim;
/* get 2'nd number */
}
}
(*errfunc)(45);
if(!cflg) /* one number */
*ep++ = i;
(*errfunc)(46);
continue;
case '\n':
(*errfunc)(36);
case 'n':
c = '\n';
goto defchar;
default:
if(c >= '1' && c <= '9') {
if((c -= '1') >= closed)
(*errfunc)(25);
*ep++ = c;
continue;
}
}
/* Drop through to default to use \ to turn off special chars */
default:
*ep++ = c;
}
}
}
{
register c;
if(circf) {
}
/* fast check for first character */
c = p2[1];
do {
if(*p1 != c)
continue;
return(1);
}
} while(*p1++);
return(0);
}
/* regular algorithm */
do {
return(1);
}
} while(*p1++);
return(0);
}
{
register char *curlp;
int c;
char *bbeg;
register char neg;
int ct;
while(1) {
neg = 0;
switch(*ep++) {
case CCHR:
continue;
return(0);
case CDOT:
if(*lp++)
continue;
return(0);
case CDOL:
if(*lp == 0)
continue;
return(0);
case CCEOF:
return(1);
case CXCL:
c = (unsigned char)*lp++;
if(ISTHERE(c)) {
ep += 32;
continue;
}
return(0);
case NCCL:
neg = 1;
case CCL:
c = *lp++;
ep += 16;
continue;
}
return(0);
case CBRA:
continue;
case CKET:
continue;
c = *ep++;
while(low--)
if(*lp++ != c)
return(0);
while(size--)
if(*lp++ != c)
break;
if(size < 0)
lp++;
ep += 2;
goto star;
while(low--)
if(*lp++ == '\0')
return(0);
while(size--)
if(*lp++ == '\0')
break;
if(size < 0)
lp++;
ep += 2;
goto star;
while(low--) {
c = (unsigned char)*lp++;
if(!ISTHERE(c))
return(0);
}
while(size--) {
c = (unsigned char)*lp++;
if(!ISTHERE(c))
break;
}
if(size < 0)
lp++;
goto star;
neg = 1;
while(low--) {
c = *lp++;
return(0);
}
while(size--) {
c = *lp++;
break;
}
if(size < 0)
lp++;
goto star;
case CBACK:
continue;
}
return(0);
}
return(0);
while(*lp++);
goto star;
ep++;
goto star;
do {
c = (unsigned char)*lp++;
} while(ISTHERE(c));
ep += 32;
goto star;
neg = 1;
do {
c = *lp++;
ep += 16;
goto star;
star:
do {
break;
return(1);
return(0);
}
}
}
static
register char *str;
{
}