This now builds under ORCA/C. Completely untested.

This commit is contained in:
gdr 1997-10-08 07:07:51 +00:00
parent b7b8ffe87b
commit 280300e2f8
9 changed files with 209 additions and 195 deletions

24
lib/libc/regex/Makefile Normal file
View File

@ -0,0 +1,24 @@
#
# $Id: Makefile,v 1.1 1997/10/08 07:07:49 gdr Exp $
#
# Devin Reade, October 1997.
#
.INCLUDE: ../../../paths.mk
.INCLUDE: ../../const.mk
OBJS = regcomp.o regerror.o regexec.o regfree.o
# I've not bothered to determine what POSIX_MISTAKE means, but 4.4BSD
# uses it.
CFLAGS += -DPOSIX_MISTAKE
build .PHONY: ../libc
obj: $(OBJS)
.INCLUDE: ../rules.mk
regcomp.o:: cclass.h cname.h regex2.h utils.h
regerror.o:: utils.h
regexec.o:: engine.c regex2.h utils.h
regfree.o:: regex2.h utils.h

View File

@ -35,6 +35,8 @@
* SUCH DAMAGE.
*
* @(#)cclass.h 8.3 (Berkeley) 3/20/94
*
* $Id: cclass.h,v 1.2 1997/10/08 07:07:49 gdr Exp $
*/
/* character-class table */

View File

@ -35,6 +35,8 @@
* SUCH DAMAGE.
*
* @(#)cname.h 8.3 (Berkeley) 3/20/94
*
* $Id: cname.h,v 1.2 1997/10/08 07:07:50 gdr Exp $
*/
/* character-name table */

View File

@ -35,8 +35,14 @@
* SUCH DAMAGE.
*
* @(#)engine.c 8.5 (Berkeley) 3/20/94
*
* $Id: engine.c,v 1.2 1997/10/08 07:07:50 gdr Exp $
*/
#ifdef __ORCAC__
segment "regex_1___";
#endif
/*
* The matching engine and friends. This file is #included by regexec.c
* after suitable #defines of a variety of macros used herein, so that
@ -136,12 +142,11 @@ static char *pchar __P((int ch));
== size_t nmatch, regmatch_t pmatch[], int eflags);
*/
static int /* 0 success, REG_NOMATCH failure */
matcher(g, string, nmatch, pmatch, eflags)
register struct re_guts *g;
char *string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
matcher(register struct re_guts *g,
char *string,
size_t nmatch,
regmatch_t pmatch[],
int eflags)
{
register char *endp;
register int i;
@ -302,12 +307,11 @@ int eflags;
== char *stop, sopno startst, sopno stopst);
*/
static char * /* == stop (success) always */
dissect(m, start, stop, startst, stopst)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
dissect(register struct match *m,
char *start,
char *stop,
sopno startst,
sopno stopst)
{
register int i;
register sopno ss; /* start sop of current subRE */
@ -490,13 +494,12 @@ sopno stopst;
== char *stop, sopno startst, sopno stopst, sopno lev);
*/
static char * /* == stop (success) or NULL (failure) */
backref(m, start, stop, startst, stopst, lev)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
sopno lev; /* PLUS nesting level */
backref(register struct match *m,
char *start,
char *stop,
sopno startst,
sopno stopst,
sopno lev) /* PLUS nesting level */
{
register int i;
register sopno ss; /* start sop of current subRE */
@ -688,18 +691,21 @@ sopno lev; /* PLUS nesting level */
/* NOTREACHED */
}
#ifdef __ORCAC__
segment "regex_2___";
#endif
/*
- fast - step through the string at top speed
== static char *fast(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
*/
static char * /* where tentative match ended, or NULL */
fast(m, start, stop, startst, stopst)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
fast(register struct match *m,
char *start,
char *stop,
sopno startst,
sopno stopst)
{
register states st = m->st;
register states fresh = m->fresh;
@ -785,12 +791,11 @@ sopno stopst;
== char *stop, sopno startst, sopno stopst);
*/
static char * /* where it ended */
slow(m, start, stop, startst, stopst)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
slow(register struct match *m,
char *start,
char *stop,
sopno startst,
sopno stopst)
{
register states st = m->st;
register states empty = m->empty;
@ -881,13 +886,12 @@ sopno stopst;
== #define NNONCHAR (CODEMAX-CHAR_MAX)
*/
static states
step(g, start, stop, bef, ch, aft)
register struct re_guts *g;
sopno start; /* start state within strip */
sopno stop; /* state after stop state within strip */
register states bef; /* states reachable before */
int ch; /* character or NONCHAR code */
register states aft; /* states already known reachable after */
step(register struct re_guts *g,
sopno start, /* start state within strip */
sopno stop, /* state after stop state within strip */
register states bef, /* states reachable before */
int ch, /* character or NONCHAR code */
register states aft) /* states already known reachable after */
{
register cset *cs;
register sop s;
@ -1003,12 +1007,11 @@ register states aft; /* states already known reachable after */
== #endif
*/
static void
print(m, caption, st, ch, d)
struct match *m;
char *caption;
states st;
int ch;
FILE *d;
print(struct match *m,
char *caption,
states st,
int ch,
FILE *d)
{
register struct re_guts *g = m->g;
register int i;
@ -1036,13 +1039,12 @@ FILE *d;
== #endif
*/
static void
at(m, title, start, stop, startst, stopst)
struct match *m;
char *title;
char *start;
char *stop;
sopno startst;
sopno stopst;
at(struct match *m,
char *title,
char *start,
char *stop,
sopno startst,
sopno stopst)
{
if (!(m->eflags&REG_TRACE))
return;
@ -1066,8 +1068,7 @@ sopno stopst;
* the non-debug compilation anyway, so it doesn't matter much.
*/
static char * /* -> representation */
pchar(ch)
int ch;
pchar(int ch)
{
static char pbuf[10];

View File

@ -35,8 +35,14 @@
* SUCH DAMAGE.
*
* @(#)regcomp.c 8.5 (Berkeley) 3/20/94
*
* $Id: regcomp.c,v 1.2 1997/10/08 07:07:50 gdr Exp $
*/
#ifdef __ORCAC__
segment "regex_3___";
#endif
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
@ -176,10 +182,9 @@ static int never = 0; /* for use in asserts; shuts lint up */
= #define REG_DUMP 0200
*/
int /* 0 success, otherwise REG_something */
regcomp(preg, pattern, cflags)
regex_t *preg;
const char *pattern;
int cflags;
regcomp(regex_t *preg,
const char *pattern,
int cflags)
{
struct parse pa;
register struct re_guts *g;
@ -280,9 +285,8 @@ int cflags;
== static void p_ere(register struct parse *p, int stop);
*/
static void
p_ere(p, stop)
register struct parse *p;
int stop; /* character this ERE should end at */
p_ere(register struct parse *p,
int stop) /* character this ERE should end at */
{
register char c;
register sopno prevback;
@ -326,8 +330,7 @@ int stop; /* character this ERE should end at */
== static void p_ere_exp(register struct parse *p);
*/
static void
p_ere_exp(p)
register struct parse *p;
p_ere_exp(register struct parse *p)
{
register char c;
register sopno pos;
@ -475,8 +478,7 @@ register struct parse *p;
== static void p_str(register struct parse *p);
*/
static void
p_str(p)
register struct parse *p;
p_str(register struct parse *p)
{
REQUIRE(MORE(), REG_EMPTY);
while (MORE())
@ -496,10 +498,9 @@ register struct parse *p;
* The amount of lookahead needed to avoid this kludge is excessive.
*/
static void
p_bre(p, end1, end2)
register struct parse *p;
register int end1; /* first terminating character */
register int end2; /* second terminating character */
p_bre(register struct parse *p,
register int end1, /* first terminating character */
register int end2) /* second terminating character */
{
register sopno start = HERE();
register int first = 1; /* first subexpression? */
@ -529,9 +530,8 @@ register int end2; /* second terminating character */
== static int p_simp_re(register struct parse *p, int starordinary);
*/
static int /* was the simple RE an unbackslashed $? */
p_simp_re(p, starordinary)
register struct parse *p;
int starordinary; /* is a leading * an ordinary character? */
p_simp_re(register struct parse *p,
int starordinary) /* is a leading * an ordinary character? */
{
register int c;
register int count;
@ -647,8 +647,7 @@ int starordinary; /* is a leading * an ordinary character? */
== static int p_count(register struct parse *p);
*/
static int /* the value */
p_count(p)
register struct parse *p;
p_count(register struct parse *p)
{
register int count = 0;
register int ndigits = 0;
@ -670,8 +669,7 @@ register struct parse *p;
* no set operations are done.
*/
static void
p_bracket(p)
register struct parse *p;
p_bracket(register struct parse *p)
{
register char c;
register cset *cs = allocset(p);
@ -745,9 +743,8 @@ register struct parse *p;
== static void p_b_term(register struct parse *p, register cset *cs);
*/
static void
p_b_term(p, cs)
register struct parse *p;
register cset *cs;
p_b_term(register struct parse *p,
register cset *cs)
{
register char c;
register char start, finish;
@ -806,14 +803,17 @@ register cset *cs;
}
}
#ifdef __ORCAC__
segment "regex_4___";
#endif
/*
- p_b_cclass - parse a character-class name and deal with it
== static void p_b_cclass(register struct parse *p, register cset *cs);
*/
static void
p_b_cclass(p, cs)
register struct parse *p;
register cset *cs;
p_b_cclass(register struct parse *p,
register cset *cs)
{
register char *sp = p->next;
register struct cclass *cp;
@ -847,9 +847,8 @@ register cset *cs;
* This implementation is incomplete. xxx
*/
static void
p_b_eclass(p, cs)
register struct parse *p;
register cset *cs;
p_b_eclass(register struct parse *p,
register cset *cs)
{
register char c;
@ -862,8 +861,7 @@ register cset *cs;
== static char p_b_symbol(register struct parse *p);
*/
static char /* value of symbol */
p_b_symbol(p)
register struct parse *p;
p_b_symbol(register struct parse *p)
{
register char value;
@ -882,9 +880,8 @@ register struct parse *p;
== static char p_b_coll_elem(register struct parse *p, int endc);
*/
static char /* value of collating element */
p_b_coll_elem(p, endc)
register struct parse *p;
int endc; /* name ended by endc,']' */
p_b_coll_elem(register struct parse *p,
int endc) /* name ended by endc,']' */
{
register char *sp = p->next;
register struct cname *cp;
@ -912,8 +909,7 @@ int endc; /* name ended by endc,']' */
== static char othercase(int ch);
*/
static char /* if no counterpart, return ch */
othercase(ch)
int ch;
othercase(int ch)
{
assert(isalpha(ch));
if (isupper(ch))
@ -931,9 +927,8 @@ int ch;
* Boy, is this implementation ever a kludge...
*/
static void
bothcases(p, ch)
register struct parse *p;
int ch;
bothcases(register struct parse *p,
int ch)
{
register char *oldnext = p->next;
register char *oldend = p->end;
@ -956,9 +951,8 @@ int ch;
== static void ordinary(register struct parse *p, register int ch);
*/
static void
ordinary(p, ch)
register struct parse *p;
register int ch;
ordinary(register struct parse *p,
register int ch)
{
register cat_t *cap = p->g->categories;
@ -978,8 +972,7 @@ register int ch;
* Boy, is this implementation ever a kludge...
*/
static void
nonnewline(p)
register struct parse *p;
nonnewline(register struct parse *p)
{
register char *oldnext = p->next;
register char *oldend = p->end;
@ -1002,11 +995,10 @@ register struct parse *p;
== static void repeat(register struct parse *p, sopno start, int from, int to);
*/
static void
repeat(p, start, from, to)
register struct parse *p;
sopno start; /* operand from here to end of strip */
int from; /* repeated from this number */
int to; /* to this number of times (maybe INFINITY) */
repeat(register struct parse *p,
sopno start, /* operand from here to end of strip */
int from, /* repeated from this number */
int to) /* to this number of times (maybe INFINITY) */
{
register sopno finish = HERE();
# define N 2
@ -1074,9 +1066,8 @@ int to; /* to this number of times (maybe INFINITY) */
== static int seterr(register struct parse *p, int e);
*/
static int /* useless but makes type checking happy */
seterr(p, e)
register struct parse *p;
int e;
seterr(register struct parse *p,
int e)
{
if (p->error == 0) /* keep earliest error condition */
p->error = e;
@ -1090,8 +1081,7 @@ int e;
== static cset *allocset(register struct parse *p);
*/
static cset *
allocset(p)
register struct parse *p;
allocset(register struct parse *p)
{
register int no = p->g->ncsets++;
register size_t nc;
@ -1145,9 +1135,8 @@ register struct parse *p;
== static void freeset(register struct parse *p, register cset *cs);
*/
static void
freeset(p, cs)
register struct parse *p;
register cset *cs;
freeset(register struct parse *p,
register cset *cs)
{
register int i;
register cset *top = &p->g->sets[p->g->ncsets];
@ -1170,9 +1159,8 @@ register cset *cs;
* the same value!
*/
static int /* set number */
freezeset(p, cs)
register struct parse *p;
register cset *cs;
freezeset(register struct parse *p,
register cset *cs)
{
register uch h = cs->hash;
register int i;
@ -1204,9 +1192,8 @@ register cset *cs;
== static int firstch(register struct parse *p, register cset *cs);
*/
static int /* character; there is no "none" value */
firstch(p, cs)
register struct parse *p;
register cset *cs;
firstch(register struct parse *p,
register cset *cs)
{
register int i;
register size_t css = (size_t)p->g->csetsize;
@ -1223,9 +1210,8 @@ register cset *cs;
== static int nch(register struct parse *p, register cset *cs);
*/
static int
nch(p, cs)
register struct parse *p;
register cset *cs;
nch(register struct parse *p,
register cset *cs)
{
register int i;
register size_t css = (size_t)p->g->csetsize;
@ -1243,10 +1229,9 @@ register cset *cs;
== register char *cp);
*/
static void
mcadd(p, cs, cp)
register struct parse *p;
register cset *cs;
register char *cp;
mcadd(register struct parse *p,
register cset *cs,
register char *cp)
{
register size_t oldend = cs->smultis;
@ -1269,9 +1254,8 @@ register char *cp;
== static void mcsub(register cset *cs, register char *cp);
*/
static void
mcsub(cs, cp)
register cset *cs;
register char *cp;
mcsub(register cset *cs,
register char *cp)
{
register char *fp = mcfind(cs, cp);
register size_t len = strlen(fp);
@ -1296,9 +1280,8 @@ register char *cp;
== static int mcin(register cset *cs, register char *cp);
*/
static int
mcin(cs, cp)
register cset *cs;
register char *cp;
mcin(register cset *cs,
register char *cp)
{
return(mcfind(cs, cp) != NULL);
}
@ -1308,9 +1291,8 @@ register char *cp;
== static char *mcfind(register cset *cs, register char *cp);
*/
static char *
mcfind(cs, cp)
register cset *cs;
register char *cp;
mcfind(register cset *cs,
register char *cp)
{
register char *p;
@ -1330,9 +1312,8 @@ register char *cp;
* is deferred.
*/
static void
mcinvert(p, cs)
register struct parse *p;
register cset *cs;
mcinvert(register struct parse *p,
register cset *cs)
{
assert(cs->multis == NULL); /* xxx */
}
@ -1345,9 +1326,8 @@ register cset *cs;
* is deferred.
*/
static void
mccase(p, cs)
register struct parse *p;
register cset *cs;
mccase(register struct parse *p,
register cset *cs)
{
assert(cs->multis == NULL); /* xxx */
}
@ -1357,9 +1337,8 @@ register cset *cs;
== static int isinsets(register struct re_guts *g, int c);
*/
static int /* predicate */
isinsets(g, c)
register struct re_guts *g;
int c;
isinsets(register struct re_guts *g,
int c)
{
register uch *col;
register int i;
@ -1377,10 +1356,9 @@ int c;
== static int samesets(register struct re_guts *g, int c1, int c2);
*/
static int /* predicate */
samesets(g, c1, c2)
register struct re_guts *g;
int c1;
int c2;
samesets(register struct re_guts *g,
int c1,
int c2)
{
register uch *col;
register int i;
@ -1399,9 +1377,8 @@ int c2;
== static void categorize(struct parse *p, register struct re_guts *g);
*/
static void
categorize(p, g)
struct parse *p;
register struct re_guts *g;
categorize(struct parse *p,
register struct re_guts *g)
{
register cat_t *cats = g->categories;
register int c;
@ -1427,10 +1404,9 @@ register struct re_guts *g;
== static sopno dupl(register struct parse *p, sopno start, sopno finish);
*/
static sopno /* start of duplicate */
dupl(p, start, finish)
register struct parse *p;
sopno start; /* from here */
sopno finish; /* to this less one */
dupl(register struct parse *p,
sopno start, /* from here */
sopno finish) /* to this less one */
{
register sopno ret = HERE();
register sopno len = finish - start;
@ -1455,10 +1431,9 @@ sopno finish; /* to this less one */
* some changes to the data structures. Maybe later.
*/
static void
doemit(p, op, opnd)
register struct parse *p;
sop op;
size_t opnd;
doemit(register struct parse *p,
sop op,
size_t opnd)
{
/* avoid making error situations worse */
if (p->error != 0)
@ -1481,11 +1456,10 @@ size_t opnd;
== static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos);
*/
static void
doinsert(p, op, opnd, pos)
register struct parse *p;
sop op;
size_t opnd;
sopno pos;
doinsert(register struct parse *p,
sop op,
size_t opnd,
sopno pos)
{
register sopno sn;
register sop s;
@ -1521,10 +1495,9 @@ sopno pos;
== static void dofwd(register struct parse *p, sopno pos, sop value);
*/
static void
dofwd(p, pos, value)
register struct parse *p;
register sopno pos;
sop value;
dofwd(register struct parse *p,
register sopno pos,
sop value)
{
/* avoid making error situations worse */
if (p->error != 0)
@ -1539,9 +1512,8 @@ sop value;
== static void enlarge(register struct parse *p, sopno size);
*/
static void
enlarge(p, size)
register struct parse *p;
register sopno size;
enlarge(register struct parse *p,
register sopno size)
{
register sop *sp;
@ -1562,9 +1534,8 @@ register sopno size;
== static void stripsnug(register struct parse *p, register struct re_guts *g);
*/
static void
stripsnug(p, g)
register struct parse *p;
register struct re_guts *g;
stripsnug(register struct parse *p,
register struct re_guts *g)
{
g->nstates = p->slen;
g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop));
@ -1585,9 +1556,8 @@ register struct re_guts *g;
* Note that must and mlen got initialized during setup.
*/
static void
findmust(p, g)
struct parse *p;
register struct re_guts *g;
findmust(struct parse *p,
register struct re_guts *g)
{
register sop *scan;
sop *start;
@ -1666,9 +1636,8 @@ register struct re_guts *g;
== static sopno pluscount(register struct parse *p, register struct re_guts *g);
*/
static sopno /* nesting depth */
pluscount(p, g)
struct parse *p;
register struct re_guts *g;
pluscount(struct parse *p,
register struct re_guts *g)
{
register sop *scan;
register sop s;

View File

@ -35,8 +35,14 @@
* SUCH DAMAGE.
*
* @(#)regerror.c 8.4 (Berkeley) 3/20/94
*
* $Id: regerror.c,v 1.2 1997/10/08 07:07:50 gdr Exp $
*/
#ifdef __ORCAC__
segment "regex_1___";
#endif
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
@ -113,11 +119,10 @@ static struct rerr {
*/
/* ARGSUSED */
size_t
regerror(errcode, preg, errbuf, errbuf_size)
int errcode;
const regex_t *preg;
char *errbuf;
size_t errbuf_size;
regerror(int errcode,
const regex_t *preg,
char *errbuf,
size_t errbuf_size)
{
register struct rerr *r;
register size_t len;
@ -161,9 +166,8 @@ size_t errbuf_size;
== static char *regatoi(const regex_t *preg, char *localbuf);
*/
static char *
regatoi(preg, localbuf)
const regex_t *preg;
char *localbuf;
regatoi(const regex_t *preg,
char *localbuf)
{
register struct rerr *r;
register size_t siz;

View File

@ -35,8 +35,14 @@
* SUCH DAMAGE.
*
* @(#)regexec.c 8.3 (Berkeley) 3/20/94
*
* $Id: regexec.c,v 1.2 1997/10/08 07:07:50 gdr Exp $
*/
#ifdef __ORCAC__
segment "regex_1___";
#endif
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
@ -153,12 +159,11 @@ static int nope = 0; /* for use in asserts; shuts lint up */
* have been prototyped.
*/
int /* 0 success, REG_NOMATCH failure */
regexec(preg, string, nmatch, pmatch, eflags)
const regex_t *preg;
const char *string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
regexec(const regex_t *preg,
const char *string,
size_t nmatch,
regmatch_t pmatch[],
int eflags)
{
register struct re_guts *g = preg->re_g;
#ifdef REDEBUG

View File

@ -35,8 +35,14 @@
* SUCH DAMAGE.
*
* @(#)regfree.c 8.3 (Berkeley) 3/20/94
*
* $Id: regfree.c,v 1.2 1997/10/08 07:07:51 gdr Exp $
*/
#ifdef __ORCAC__
segment "regex_1___";
#endif
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
@ -54,8 +60,7 @@ static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
= extern void regfree(regex_t *);
*/
void
regfree(preg)
regex_t *preg;
regfree(regex_t *preg)
{
register struct re_guts *g;

View File

@ -35,6 +35,8 @@
* SUCH DAMAGE.
*
* @(#)utils.h 8.3 (Berkeley) 3/20/94
*
* $Id: utils.h,v 1.2 1997/10/08 07:07:51 gdr Exp $
*/
/* utility definitions */