Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,594 @@
/* $XConsortium: recomp.c /main/3 1995/11/01 18:22:03 rswiston $ */
/***************************************************************
* *
* AT&T - PROPRIETARY *
* *
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
* AT&T CORP. *
* *
* Copyright (c) 1995 AT&T Corp. *
* All Rights Reserved *
* *
* This software is licensed by AT&T Corp. *
* under the terms and conditions of the license in *
* http://www.research.att.com/orgs/ssr/book/reuse *
* *
* This software was created by the *
* Software Engineering Research Department *
* AT&T Bell Laboratories *
* *
* For further information contact *
* gsf@research.att.com *
* *
***************************************************************/
/* : : generated by proto : : */
#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__ "C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x) x
#define __OTORP__(x)
#define __PARAM__(n,o) n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void int
#define volatile
#define __V_ char
#else
#define __V_ void
#endif
#else
#define __PROTO__(x) ()
#define __OTORP__(x) x
#define __PARAM__(n,o) o
#define __MANGLE__
#define __V_ char
#define const
#define signed
#define void int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__ ...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a) va_start(p,a)
#else
#define __VA_START__(p,a) va_start(p)
#endif
#endif
#include "relib.h"
typedef struct /* parser info */
{
Inst_t* first;
Inst_t* last;
} Node_t;
#define NSTACK 32 /* misc stack depth */
typedef struct
{
Node_t andstack[NSTACK];
Node_t* andp;
int atorstack[NSTACK];
int* atorp;
int subidstack[NSTACK]; /* parallel to atorstack */
int* subidp;
int cursubid; /* current sub-expression id */
int refsubid; /* reference sub-expression id */
int lastwasand; /* last token was operand */
int nbra;
unsigned char* exprp; /* next source expression char */
int nclass;
Class_t* classp;
Inst_t* freep;
int errors;
int flags; /* RE_MATCH if '\[0-9]' */
} State_t;
static State_t* re; /* compiler state */
static void
rcerror __PARAM__((char* s), (s)) __OTORP__(char* s;){
re->errors++;
reerror(s);
}
static void
reerr2 __PARAM__((register char* s, int c), (s, c)) __OTORP__(register char* s; int c;){
char buf[100];
s = strcopy(buf, s);
*s++ = c;
*s = 0;
rcerror(buf);
}
static void
cant __PARAM__((char* s), (s)) __OTORP__(char* s;){
char buf[100];
strcopy(strcopy(buf, "internal error: "), s);
rcerror(buf);
}
static Inst_t*
newinst __PARAM__((int t), (t)) __OTORP__(int t;){
re->freep->type = t;
re->freep->left = 0;
re->freep->right = 0;
return(re->freep++);
}
static void
pushand __PARAM__((Inst_t* f, Inst_t* l), (f, l)) __OTORP__(Inst_t* f; Inst_t* l;){
if (re->andp >= &re->andstack[NSTACK]) cant("operand stack overflow");
re->andp->first = f;
re->andp->last = l;
re->andp++;
}
static Node_t*
popand __PARAM__((int op), (op)) __OTORP__(int op;){
register Inst_t* inst;
if (re->andp <= &re->andstack[0])
{
reerr2("missing operand for ", op);
inst = newinst(NOP);
pushand(inst, inst);
}
return(--re->andp);
}
static void
pushator __PARAM__((int t), (t)) __OTORP__(int t;){
if (re->atorp >= &re->atorstack[NSTACK]) cant("operator stack overflow");
*re->atorp++ = t;
*re->subidp++ = re->cursubid;
}
static int
popator __PARAM__((void), ()){
if (re->atorp <= &re->atorstack[0]) cant("operator stack underflow");
re->subidp--;
return(*--re->atorp);
}
static void
evaluntil __PARAM__((register int pri), (pri)) __OTORP__(register int pri;){
register Node_t* op1;
register Node_t* op2;
register Inst_t* inst1;
register Inst_t* inst2;
while (pri == RBRA || re->atorp[-1] >= pri)
{
switch(popator())
{
case LBRA:
/*
* must have been RBRA
*/
op1 = popand('(');
inst2 = newinst(RBRA);
inst2->subid = *re->subidp;
op1->last->next = inst2;
inst1 = newinst(LBRA);
inst1->subid = *re->subidp;
inst1->next = op1->first;
pushand(inst1, inst2);
return;
case OR:
op2 = popand('|');
op1 = popand('|');
inst2 = newinst(NOP);
op2->last->next = inst2;
op1->last->next = inst2;
inst1 = newinst(OR);
inst1->right = op1->first;
inst1->left = op2->first;
pushand(inst1, inst2);
break;
case CAT:
op2 = popand(0);
op1 = popand(0);
op1->last->next = op2->first;
pushand(op1->first, op2->last);
break;
case STAR:
op2 = popand('*');
inst1 = newinst(OR);
op2->last->next = inst1;
inst1->right = op2->first;
pushand(inst1, inst1);
break;
case PLUS:
op2 = popand('+');
inst1 = newinst(OR);
op2->last->next = inst1;
inst1->right = op2->first;
pushand(op2->first, inst1);
break;
case QUEST:
op2 = popand('?');
inst1 = newinst(OR);
inst2 = newinst(NOP);
inst1->left = inst2;
inst1->right = op2->first;
op2->last->next = inst2;
pushand(inst1, inst2);
break;
default:
cant("unknown operator in evaluntil()");
break;
}
}
}
static void
operation __PARAM__((register int t), (t)) __OTORP__(register int t;){
register int thisisand = 0;
switch (t)
{
case LBRA:
if (re->cursubid < NMATCH) re->cursubid++;
re->nbra++;
if (re->lastwasand) operation(CAT);
pushator(t);
re->lastwasand = 0;
break;
case RBRA:
if (--re->nbra < 0) rcerror("unmatched )");
evaluntil(t);
re->lastwasand = 1;
break;
case STAR:
case QUEST:
case PLUS:
thisisand = 1;
/* fall through ... */
default:
evaluntil(t);
pushator(t);
re->lastwasand = thisisand;
break;
}
}
static void
operand __PARAM__((int t), (t)) __OTORP__(int t;){
register Inst_t* i;
/*
* catenate is implicit
*/
if (re->lastwasand) operation(CAT);
i = newinst(t);
switch (t)
{
case CCLASS:
i->cclass = re->classp[re->nclass - 1].map;
break;
case SUBEXPR:
i->subid = re->refsubid;
break;
}
pushand(i, i);
re->lastwasand = 1;
}
static void
optimize __PARAM__((Re_program_t* pp), (pp)) __OTORP__(Re_program_t* pp;){
register Inst_t* inst;
register Inst_t* target;
for (inst = pp->firstinst; inst->type != END; inst++)
{
target = inst->next;
while (target->type == NOP) target = target->next;
inst->next = target;
}
}
#if DEBUG
static void
dumpstack __PARAM__((void), ()){
Node_t* stk;
int* ip;
sfprintf(sfstdout, "operators\n");
for (ip = re->atorstack; ip < re->atorp; ip++)
sfprintf(sfstdout, "0%o\n", *ip);
sfprintf(sfstdout, "operands\n");
for (stk = re->andstack; stk < re->andp; stk++)
sfprintf(sfstdout, "0%o\t0%o\n", stk->first->type, stk->last->type);
}
static void
dump __PARAM__((Re_program_t* pp), (pp)) __OTORP__(Re_program_t* pp;){
Inst_t* l;
l = pp->firstinst;
do
{
sfprintf(sfstdout, "%d:\t0%o\t%d\t%d\n",
l-pp->firstinst, l->type,
l->left-pp->firstinst, l->right-pp->firstinst);
} while (l++->type);
}
#endif
static int
nextc __PARAM__((void), ()){
register int c;
switch (c = *re->exprp++)
{
case 0:
rcerror("missing ] in character class");
break;
case '\\':
if (!(c = chresc((char*)re->exprp - 1, (char**)&re->exprp)))
rcerror("trailing \\ is invalid");
break;
case ']':
c = 0;
break;
}
return(c);
}
static void
bldcclass __PARAM__((void), ()){
register int c1;
register int c2;
register char* map;
register int negate;
if (re->nclass >= NCLASS) reerr2("too many character classes -- limit ", NCLASS + '0');
map = re->classp[re->nclass++].map;
memzero(map, elementsof(re->classp[0].map));
/*
* we have already seen the '['
*/
if (*re->exprp == '^')
{
re->exprp++;
negate = 1;
}
else negate = 0;
if (*re->exprp == ']')
{
re->exprp++;
setbit(map, ']');
}
if (*re->exprp == '-')
{
re->exprp++;
setbit(map, '-');
}
while (c1 = c2 = nextc())
{
if (*re->exprp == '-')
{
re->exprp++;
c2 = nextc();
}
for (; c1 <= c2; c1++) setbit(map, c1);
}
if (negate)
for (c1 = 0; c1 < elementsof(re->classp[0].map); c1++)
map[c1] = ~map[c1];
/*
* always exclude '\0'
*/
clrbit(map, 0);
}
static int
lex __PARAM__((void), ()){
register int c;
switch(c = *re->exprp++)
{
case 0:
c = END;
re->exprp--;
break;
case '\\':
switch (c = *re->exprp++)
{
case 0:
re->exprp--;
rcerror("trailing \\ is invalid");
break;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if ((c - '0') > re->cursubid) reerr2("invalid sub-expression reference \\", c);
else
{
re->refsubid = c - '0';
re->flags |= RE_MATCH;
c = SUBEXPR;
}
break;
case '?':
if (re->flags & RE_EDSTYLE) c = QUEST;
break;
case '+':
if (re->flags & RE_EDSTYLE) c = PLUS;
break;
case '|':
if (re->flags & RE_EDSTYLE) c = OR;
break;
case '(':
if (re->flags & RE_EDSTYLE) c = LBRA;
break;
case ')':
if (re->flags & RE_EDSTYLE) c = RBRA;
break;
case '<':
if (re->flags & RE_EDSTYLE) c = BID;
break;
case '>':
if (re->flags & RE_EDSTYLE) c = EID;
break;
default:
c = chresc((char*)re->exprp - 2, (char**)&re->exprp);
break;
}
break;
case '*':
c = STAR;
break;
case '.':
c = ANY;
break;
case '^':
c = BOL;
break;
case '$':
c = EOL;
break;
case '[':
c = CCLASS;
bldcclass();
break;
case '?':
if (!(re->flags & RE_EDSTYLE)) c = QUEST;
break;
case '+':
if (!(re->flags & RE_EDSTYLE)) c = PLUS;
break;
case '|':
if (!(re->flags & RE_EDSTYLE)) c = OR;
break;
case '(':
if (!(re->flags & RE_EDSTYLE)) c = LBRA;
break;
case ')':
if (!(re->flags & RE_EDSTYLE)) c = RBRA;
break;
case '<':
if (!(re->flags & RE_EDSTYLE)) c = BID;
break;
case '>':
if (!(re->flags & RE_EDSTYLE)) c = EID;
break;
}
return(c);
}
reprogram*
recomp __PARAM__((const char* s, int reflags), (s, reflags)) __OTORP__(const char* s; int reflags;){
register int token;
Re_program_t* pp;
State_t restate;
/*
* get memory for the program
*/
if (!(pp = newof(0, Re_program_t, 1, 3 * sizeof(Inst_t) * strlen(s))))
{
rcerror("out of memory");
return(0);
}
re = &restate;
re->freep = pp->firstinst;
re->classp = pp->chrset;
re->errors = 0;
re->flags = reflags & ((1<<RE_EXTERNAL) - 1);
/*
* go compile the sucker
*/
re->exprp = (unsigned char*)s;
re->nclass = 0;
re->nbra = 0;
re->atorp = re->atorstack;
re->andp = re->andstack;
re->subidp = re->subidstack;
re->lastwasand = 0;
re->cursubid = 0;
/*
* start with a low priority operator to prime parser
*/
pushator(START - 1);
while ((token = lex()) != END)
{
if (token >= OPERATOR) operation(token);
else operand(token);
}
/*
* close with a low priority operator
*/
evaluntil(START);
/*
* force END
*/
operand(END);
evaluntil(START);
#if DEBUG
dumpstack();
#endif
if (re->nbra) rcerror("unmatched (");
re->andp--;
/*
* re->andp points to first and only operand
*/
pp->startinst = re->andp->first;
pp->flags = re->flags;
#if DEBUG
dump(pp);
#endif
optimize(pp);
#ifdef DEBUG
sfprintf(sfstdout, "start: %d\n", re->andp->first-pp->firstinst);
dump(pp);
#endif
if (re->errors)
{
free(pp);
pp = 0;
}
return((reprogram*)pp);
}
/*
* free program compiled by recomp()
*/
void
refree __PARAM__((reprogram* pp), (pp)) __OTORP__(reprogram* pp;){
free(pp);
}

View File

@@ -0,0 +1,77 @@
/* $XConsortium: reerror.c /main/3 1995/11/01 18:22:20 rswiston $ */
/***************************************************************
* *
* AT&T - PROPRIETARY *
* *
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
* AT&T CORP. *
* *
* Copyright (c) 1995 AT&T Corp. *
* All Rights Reserved *
* *
* This software is licensed by AT&T Corp. *
* under the terms and conditions of the license in *
* http://www.research.att.com/orgs/ssr/book/reuse *
* *
* This software was created by the *
* Software Engineering Research Department *
* AT&T Bell Laboratories *
* *
* For further information contact *
* gsf@research.att.com *
* *
***************************************************************/
/* : : generated by proto : : */
#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__ "C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x) x
#define __OTORP__(x)
#define __PARAM__(n,o) n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void int
#define volatile
#define __V_ char
#else
#define __V_ void
#endif
#else
#define __PROTO__(x) ()
#define __OTORP__(x) x
#define __PARAM__(n,o) o
#define __MANGLE__
#define __V_ char
#define const
#define signed
#define void int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__ ...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a) va_start(p,a)
#else
#define __VA_START__(p,a) va_start(p)
#endif
#endif
#include "relib.h"
#include <error.h>
void
reerror __PARAM__((const char* s), (s)) __OTORP__(const char* s;){
liberror("re", 3, "regular expression: %s", s);
}

View File

@@ -0,0 +1,304 @@
/* $XConsortium: reexec.c /main/3 1995/11/01 18:22:33 rswiston $ */
/***************************************************************
* *
* AT&T - PROPRIETARY *
* *
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
* AT&T CORP. *
* *
* Copyright (c) 1995 AT&T Corp. *
* All Rights Reserved *
* *
* This software is licensed by AT&T Corp. *
* under the terms and conditions of the license in *
* http://www.research.att.com/orgs/ssr/book/reuse *
* *
* This software was created by the *
* Software Engineering Research Department *
* AT&T Bell Laboratories *
* *
* For further information contact *
* gsf@research.att.com *
* *
***************************************************************/
/* : : generated by proto : : */
#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__ "C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x) x
#define __OTORP__(x)
#define __PARAM__(n,o) n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void int
#define volatile
#define __V_ char
#else
#define __V_ void
#endif
#else
#define __PROTO__(x) ()
#define __OTORP__(x) x
#define __PARAM__(n,o) o
#define __MANGLE__
#define __V_ char
#define const
#define signed
#define void int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__ ...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a) va_start(p,a)
#else
#define __VA_START__(p,a) va_start(p)
#endif
#endif
#include "relib.h"
#include <ctype.h>
#define LISTINCREMENT 8
typedef struct
{
Inst_t* inst; /* instruction of the thread */
Subexp_t se; /* matched sub-expressions this thread */
} List_t;
/*
* note optimization in addinst:
* *p must be pending when addinst called; if *l has been looked
* at already, the optimization is a bug.
*/
static List_t*
newthread __PARAM__((register List_t* p, register Inst_t* ip, register Subexp_t* sep), (p, ip, sep)) __OTORP__(register List_t* p; register Inst_t* ip; register Subexp_t* sep;){
for (; p->inst; p++)
if (p->inst == ip)
{
if (sep->m[0].sp < p->se.m[0].sp) p->se = *sep;
return(0);
}
p->inst = ip;
p->se = *sep;
(++p)->inst = 0;
return(p);
}
static void
newmatch __PARAM__((register Subexp_t* mp, register Subexp_t* np), (mp, np)) __OTORP__(register Subexp_t* mp; register Subexp_t* np;){
if (!mp->m[0].sp || np->m[0].sp < mp->m[0].sp || np->m[0].sp == mp->m[0].sp && np->m[0].ep > mp->m[0].ep)
*mp = *np;
}
int
reexec __PARAM__((Re_program_t* aprogp, const char* starts), (aprogp, starts)) __OTORP__(Re_program_t* aprogp; const char* starts;){
Re_program_t* progp = (Re_program_t*)aprogp;
register int flag = 0;
register Inst_t* inst;
register List_t* tlp;
register const char* s;
Subexp_t* mp;
int checkstart;
int startchar;
List_t* tl; /* this list, next list */
List_t* nl; /* this list, next list */
List_t* tle; /* ends of this and next list */
List_t* nle; /* ends of this and next list */
List_t* list[2];
List_t* liste[2];
int match = 0;
static int listsize = LISTINCREMENT;
static Subexp_t sempty; /* empty set of matches */
startchar = progp->startinst->type < TOKEN ? progp->startinst->type : 0;
mp = (progp->flags & RE_MATCH) ? &progp->subexp : 0;
list[0] = 0;
Restart:
match = 0;
checkstart = startchar;
sempty.m[0].sp = 0;
if (mp) mp->m[0].sp = mp->m[0].ep = 0;
if (!list[0])
{
if (!(list[0] = newof(0, List_t, 2 * listsize, 0)))
reerror("list overflow");
list[1] = list[0] + listsize;
liste[0] = list[0] + listsize - 1;
liste[1] = list[1] + listsize - 1;
}
list[0][0].inst = list[1][0].inst = 0;
/*
* execute machine once for each character, including terminal '\0'
*/
s = starts;
do
{
/*
* fast check for first char
*/
if (checkstart && *s != startchar) continue;
tl = list[flag];
tle = liste[flag];
nl = list[flag ^= 1];
nle = liste[flag];
nl->inst = 0;
/*
* add first instruction to this list
*/
sempty.m[0].sp = (char*)s;
newthread(tl, progp->startinst, &sempty);
/*
* execute machine until this list is empty
*/
for (tlp = tl; inst = tlp->inst; tlp++)
{
/*
* assignment =
*/
Switchstmt:
switch (inst->type)
{
case LBRA:
tlp->se.m[inst->subid].sp = (char*)s;
inst = inst->next;
goto Switchstmt;
case RBRA:
tlp->se.m[inst->subid].ep = (char*)s;
inst = inst->next;
goto Switchstmt;
case ANY:
goto Addinst;
case BOL:
if (s == starts)
{
inst = inst->next;
goto Switchstmt;
}
break;
case EOL:
if (!*s)
{
inst = inst->next;
goto Switchstmt;
}
break;
case BID:
if (s == starts || !isalnum(*(s - 1)) && *(s - 1) != '_')
{
inst = inst->next;
goto Switchstmt;
}
break;
case EID:
if (!*s || !isalnum(*s) && *s != '_')
{
inst = inst->next;
goto Switchstmt;
}
break;
case CCLASS:
if (tstbit(inst->cclass, *s)) goto Addinst;
break;
case OR:
/*
* evaluate right choice later
*/
if (newthread(tlp, inst->right, &tlp->se) == tle)
goto Realloc;
/*
* efficiency: advance and re-evaluate
*/
inst = inst->left;
goto Switchstmt;
case SUBEXPR:
{
const char* ss;
const char* ms = (char*)tlp->se.m[inst->subid].sp;
const char* me = (char*)tlp->se.m[inst->subid].ep;
#if DEBUG
{
int c;
c = *me;
*me = 0;
error(-1, "subexpression %d ref=\"%s\"", inst->subid, ms);
*me = c;
error(-1, "subexpression %d src=\"%s\"", inst->subid, s);
}
#endif
if (ms == me)
{
inst = inst->next;
goto Switchstmt;
}
for (ss = s; ms < me && *ss++ == *ms; ms++);
if (ms == me)
{
s = ss - 1;
goto Addinst;
}
}
break;
case END:
/*
* match!
*/
match = 1;
tlp->se.m[0].ep = (char*)s;
if (mp) newmatch(mp, &tlp->se);
break;
default:
/*
* regular character
*/
if (inst->type == *s)
{
Addinst:
if (newthread(nl, inst->next, &tlp->se) == nle)
goto Realloc;
}
break;
}
}
checkstart = startchar && !nl->inst;
} while (*s++);
if (list[0]) free(list[0]);
return(match);
Realloc:
free(list[0]);
list[0] = 0;
listsize += LISTINCREMENT;
goto Restart;
}

View File

@@ -0,0 +1,166 @@
/* $XConsortium: relib.h /main/3 1995/11/01 18:22:46 rswiston $ */
/***************************************************************
* *
* AT&T - PROPRIETARY *
* *
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
* AT&T CORP. *
* *
* Copyright (c) 1995 AT&T Corp. *
* All Rights Reserved *
* *
* This software is licensed by AT&T Corp. *
* under the terms and conditions of the license in *
* http://www.research.att.com/orgs/ssr/book/reuse *
* *
* This software was created by the *
* Software Engineering Research Department *
* AT&T Bell Laboratories *
* *
* For further information contact *
* gsf@research.att.com *
* *
***************************************************************/
/* : : generated by proto : : */
/*
* AT&T Bell Laboratories
*
* regular expression library private definitions
*/
#ifndef _RELIB_H
#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__ "C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x) x
#define __OTORP__(x)
#define __PARAM__(n,o) n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void int
#define volatile
#define __V_ char
#else
#define __V_ void
#endif
#else
#define __PROTO__(x) ()
#define __OTORP__(x) x
#define __PARAM__(n,o) o
#define __MANGLE__
#define __V_ char
#define const
#define signed
#define void int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__ ...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a) va_start(p,a)
#else
#define __VA_START__(p,a) va_start(p)
#endif
#endif
#define _RELIB_H
#include <ast.h>
#define NCLASS 16 /* max # [...] expressions */
#define NMATCH ('9'-'0'+1) /* max # (...) expressions */
typedef struct /* sub-expression match */
{
char* sp; /* start in source string */
char* ep; /* end in source string */
} Match_t;
typedef struct /* sub-expression match table */
{
Match_t m[NMATCH + 1];
} Subexp_t;
typedef struct /* character class bit vector */
{
char map[UCHAR_MAX / CHAR_BIT + 1];
} Class_t;
typedef struct Inst /* machine instruction */
{
int type; /* <TOKEN ==> literal, otherwise action */
union
{
int sid; /* sub-expression id for RBRA and LBRA */
struct Inst* other; /* for right child */
char* cls; /* CCLASS bit vector */
} u;
struct Inst* left; /* left child */
} Inst_t;
/*
* NOTE: subexp must be the first element to match Re_program_t.match
*/
#define _RE_PROGRAM_PRIVATE_ \
Subexp_t subexp; /* sub-expression matches */ \
int flags; /* RE_* flags */ \
Inst_t* startinst; /* start pc */ \
Class_t chrset[NCLASS]; /* .data */ \
Inst_t firstinst[5]; /* .text */
#include <re.h>
#define clrbit(set,bit) (set[(bit)/CHAR_BIT]&=~(1<<((bit)%CHAR_BIT)))
#define setbit(set,bit) (set[(bit)/CHAR_BIT]|=(1<<((bit)%CHAR_BIT)))
#define tstbit(set,bit) ((set[(bit)/CHAR_BIT]&(1<<((bit)%CHAR_BIT)))!=0)
#define next left
#define subid u.sid
#define right u.other
#define cclass u.cls
/*
* tokens and actions
*
* TOKEN<=x<OPERATOR are tokens, i.e. operands for operators
* >=OPERATOR are operators, value == precedence
*/
#define TOKEN (UCHAR_MAX+1)
#define ANY (UCHAR_MAX+1) /* `.' any character */
#define NOP (UCHAR_MAX+2) /* no operation (internal) */
#define BOL (UCHAR_MAX+3) /* `^' beginning of line */
#define EOL (UCHAR_MAX+4) /* `$' end of line */
#define BID (UCHAR_MAX+5) /* `\<' begin identifier */
#define EID (UCHAR_MAX+6) /* `\>' end identifier */
#define CCLASS (UCHAR_MAX+7) /* `[]' character class */
#define SUBEXPR (UCHAR_MAX+8) /* `\#' sub-expression */
#define END (UCHAR_MAX+9) /* terminate: match found */
#define OPERATOR (UCHAR_MAX+11)
#define START (UCHAR_MAX+11) /* start, stack marker */
#define RBRA (UCHAR_MAX+12) /* `)' right bracket */
#define LBRA (UCHAR_MAX+13) /* `(' left bracket */
#define OR (UCHAR_MAX+14) /* `|' alternation */
#define CAT (UCHAR_MAX+15) /* concatentation (implicit) */
#define STAR (UCHAR_MAX+16) /* `*' closure */
#define PLUS (UCHAR_MAX+17) /* a+ == aa* */
#define QUEST (UCHAR_MAX+18) /* a? == 0 or 1 a's */
#endif

View File

@@ -0,0 +1,161 @@
/* $XConsortium: ressub.c /main/3 1995/11/01 18:22:59 rswiston $ */
/***************************************************************
* *
* AT&T - PROPRIETARY *
* *
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
* AT&T CORP. *
* *
* Copyright (c) 1995 AT&T Corp. *
* All Rights Reserved *
* *
* This software is licensed by AT&T Corp. *
* under the terms and conditions of the license in *
* http://www.research.att.com/orgs/ssr/book/reuse *
* *
* This software was created by the *
* Software Engineering Research Department *
* AT&T Bell Laboratories *
* *
* For further information contact *
* gsf@research.att.com *
* *
***************************************************************/
/* : : generated by proto : : */
#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__ "C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x) x
#define __OTORP__(x)
#define __PARAM__(n,o) n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void int
#define volatile
#define __V_ char
#else
#define __V_ void
#endif
#else
#define __PROTO__(x) ()
#define __OTORP__(x) x
#define __PARAM__(n,o) o
#define __MANGLE__
#define __V_ char
#define const
#define signed
#define void int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__ ...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a) va_start(p,a)
#else
#define __VA_START__(p,a) va_start(p)
#endif
#endif
#include "relib.h"
#undef next
#include <ctype.h>
/*
* do a single substitution
*/
static void
sub __PARAM__((register Sfio_t* dp, register const char* sp, register Match_t* mp, register int flags), (dp, sp, mp, flags)) __OTORP__(register Sfio_t* dp; register const char* sp; register Match_t* mp; register int flags;){
register int c;
char* s;
char* e;
flags &= (RE_LOWER|RE_UPPER);
for (;;) switch (c = *sp++)
{
case 0:
return;
case '\\':
switch (c = *sp++)
{
case 0:
sp--;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
c -= '0';
goto group;
default:
sfputc(dp, chresc(sp - 2, &s));
sp = s;
break;
}
break;
case '&':
c = 0;
group:
if (s = mp[c].sp)
{
e = mp[c].ep;
while (s < e)
{
c = *s++;
switch (flags)
{
case RE_UPPER:
if (islower(c)) c = toupper(c);
break;
case RE_LOWER:
if (isupper(c)) c = tolower(c);
break;
}
sfputc(dp, c);
}
}
break;
default:
switch (flags)
{
case RE_UPPER:
if (islower(c)) c = toupper(c);
break;
case RE_LOWER:
if (isupper(c)) c = tolower(c);
break;
}
sfputc(dp, c);
break;
}
}
/*
* ed(1) style substitute using matches from last reexec()
*/
void
ressub __PARAM__((Re_program_t* re, Sfio_t* dp, register const char* op, const char* sp, int flags), (re, dp, op, sp, flags)) __OTORP__(Re_program_t* re; Sfio_t* dp; register const char* op; const char* sp; int flags;){
register Match_t* mp;
mp = re->subexp.m;
do
{
sfwrite(dp, op, mp->sp - op);
sub(dp, sp, mp, flags);
op = mp->ep;
} while ((flags & RE_ALL) && *op && mp->sp != mp->ep && reexec(re, op));
sfputr(dp, op, -1);
}

View File

@@ -0,0 +1,153 @@
/* $XConsortium: resub.c /main/3 1995/11/01 18:23:12 rswiston $ */
/***************************************************************
* *
* AT&T - PROPRIETARY *
* *
* THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
* AT&T CORP. *
* *
* Copyright (c) 1995 AT&T Corp. *
* All Rights Reserved *
* *
* This software is licensed by AT&T Corp. *
* under the terms and conditions of the license in *
* http://www.research.att.com/orgs/ssr/book/reuse *
* *
* This software was created by the *
* Software Engineering Research Department *
* AT&T Bell Laboratories *
* *
* For further information contact *
* gsf@research.att.com *
* *
***************************************************************/
/* : : generated by proto : : */
#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__ "C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x) x
#define __OTORP__(x)
#define __PARAM__(n,o) n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void int
#define volatile
#define __V_ char
#else
#define __V_ void
#endif
#else
#define __PROTO__(x) ()
#define __OTORP__(x) x
#define __PARAM__(n,o) o
#define __MANGLE__
#define __V_ char
#define const
#define signed
#define void int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__ ...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a) va_start(p,a)
#else
#define __VA_START__(p,a) va_start(p)
#endif
#endif
#include "relib.h"
#include <ctype.h>
/*
* do a single substitution
*/
static char*
sub __PARAM__((register const char* sp, register char* dp, register Match_t* mp, int flags), (sp, dp, mp, flags)) __OTORP__(register const char* sp; register char* dp; register Match_t* mp; int flags;){
register int i;
char* s;
NoP(flags);
for (;;) switch (*dp = *sp++)
{
case 0:
return(dp);
case '\\':
switch (i = *sp++)
{
case 0:
sp--;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
i -= '0';
if (mp[i].sp)
{
s = mp[i].sp;
while (s < mp[i].ep) *dp++ = *s++;
}
break;
default:
*dp++ = chresc(sp - 2, &s);
sp = s;
break;
}
break;
case '&':
if (mp[0].sp)
{
s = mp[0].sp;
while (s < mp[0].ep) *dp++ = *s++;
}
break;
default:
dp++;
break;
}
}
/*
* ed(1) style substitute using matches from last reexec()
*/
char*
resub __PARAM__((Re_program_t* re, register const char* op, const char* sp, register char* dp, int flags), (re, op, sp, dp, flags)) __OTORP__(Re_program_t* re; register const char* op; const char* sp; register char* dp; int flags;){
register Match_t* mp;
mp = re->subexp.m;
do
{
while (op < mp->sp) *dp++ = *op++;
op = dp;
dp = sub(sp, dp, mp, flags);
if (flags & (RE_LOWER|RE_UPPER))
{
while (op < dp)
{
if (flags & RE_LOWER)
{
if (isupper(*op)) *(char*)op = tolower(*op);
}
else if (islower(*op)) *(char*)op = toupper(*op);
op++;
}
}
op = mp->ep;
} while ((flags & RE_ALL) && *op && mp->sp != mp->ep && reexec(re, op));
while (*dp++ = *op++);
return(--dp);
}