alpha3.3
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 17 Mar 1994 04:43:04 +0000 (20:43 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 17 Mar 1994 04:43:04 +0000 (20:43 -0800)
SCCS-vsn: lib/libc/regex/WHATSNEW 8.2
SCCS-vsn: lib/libc/regex/cclass.h 8.2
SCCS-vsn: lib/libc/regex/cname.h 8.2
SCCS-vsn: lib/libc/regex/engine.c 8.3
SCCS-vsn: lib/libc/regex/re_format.7 8.2
SCCS-vsn: lib/libc/regex/regcomp.c 8.2
SCCS-vsn: lib/libc/regex/regerror.c 8.2
SCCS-vsn: lib/libc/regex/regex.3 8.2
SCCS-vsn: lib/libc/regex/regex2.h 8.3
SCCS-vsn: lib/libc/regex/regexec.c 8.2
SCCS-vsn: lib/libc/regex/regfree.c 8.2
SCCS-vsn: lib/libc/regex/utils.h 8.2

12 files changed:
usr/src/lib/libc/regex/WHATSNEW
usr/src/lib/libc/regex/cclass.h
usr/src/lib/libc/regex/cname.h
usr/src/lib/libc/regex/engine.c
usr/src/lib/libc/regex/re_format.7
usr/src/lib/libc/regex/regcomp.c
usr/src/lib/libc/regex/regerror.c
usr/src/lib/libc/regex/regex.3
usr/src/lib/libc/regex/regex2.h
usr/src/lib/libc/regex/regexec.c
usr/src/lib/libc/regex/regfree.c
usr/src/lib/libc/regex/utils.h

index b2cb012..7bf2b48 100644 (file)
@@ -1,4 +1,31 @@
-# @(#)WHATSNEW 8.1 (Berkeley) %G%
+# @(#)WHATSNEW 8.2 (Berkeley) %G%
+
+New in alpha3.3:  The definition of word boundaries has been altered
+slightly, to more closely match the usual programming notion that "_"
+is an alphabetic.  Stuff used for pre-ANSI systems is now in a subdir,
+and the makefile no longer alludes to it in mysterious ways.  The
+makefile has generally been cleaned up some.  Fixes have been made
+(again!) so that the regression test will run without -DREDEBUG, at
+the cost of weaker checking.  A workaround for a bug in some folks'
+<assert.h> has been added.  And some more things have been added to
+tests, including a couple right at the end which are commented out
+because the code currently flunks them (complex bug; fix coming).
+Plus the usual minor cleanup.
+
+New in alpha3.2:  Assorted bits of cleanup and portability improvement
+(the development base is now a BSDI system using GCC instead of an ancient
+Sun system, and the newer compiler exposed some glitches).  Fix for a
+serious bug that affected REs using many [] (including REG_ICASE REs
+because of the way they are implemented), *sometimes*, depending on
+memory-allocation patterns.  The header-file prototypes no longer name
+the parameters, avoiding possible name conflicts.  The possibility that
+some clot has defined CHAR_MIN as (say) `-128' instead of `(-128)' is
+now handled gracefully.  "uchar" is no longer used as an internal type
+name (too many people have the same idea).  Still the same old lousy
+performance, alas.
+
+New in alpha3.1:  Basically nothing, this release is just a bookkeeping
+convenience.  Stay tuned.
 
 New in alpha3.0:  Performance is no better, alas, but some fixes have been
 made and some functionality has been added.  (This is basically the "get
 
 New in alpha3.0:  Performance is no better, alas, but some fixes have been
 made and some functionality has been added.  (This is basically the "get
index cfdb7b7..9a1cc1d 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)cclass.h    8.1 (Berkeley) %G%
+ *     @(#)cclass.h    8.2 (Berkeley) %G%
  */
 
 /* character-class table */
  */
 
 /* character-class table */
index a33118a..864d0b9 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)cname.h     8.1 (Berkeley) %G%
+ *     @(#)cname.h     8.2 (Berkeley) %G%
  */
 
 /* character-name table */
  */
 
 /* character-name table */
index 9acd31c..d9e1336 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)engine.c    8.2 (Berkeley) %G%
+ *     @(#)engine.c    8.3 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -58,12 +58,18 @@ struct match {
        states empty;           /* empty set of states */
 };
 
        states empty;           /* empty set of states */
 };
 
-static int matcher(/*register struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags*/);
-static char *dissect(/*register struct match *m, char *start, char *stop, sopno startst, sopno stopst*/);
-static char *backref(/*register struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev*/);
-static char *fast(/*register struct match *m, char *start, char *stop, sopno startst, sopno stopst*/);
-static char *slow(/*register struct match *m, char *start, char *stop, sopno startst, sopno stopst*/);
-static states step(/*register struct re_guts *g, int start, int stop, register states bef, int ch, register states aft*/);
+/* ========= begin header generated by ./mkh ========= */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* === engine.c === */
+static int matcher(register struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
+static char *dissect(register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
+static char *backref(register struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev);
+static char *fast(register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
+static char *slow(register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
+static states step(register struct re_guts *g, sopno start, sopno stop, register states bef, int ch, register states aft);
 #define        BOL     (OUT+1)
 #define        EOL     (BOL+1)
 #define        BOLEOL  (BOL+2)
 #define        BOL     (OUT+1)
 #define        EOL     (BOL+1)
 #define        BOLEOL  (BOL+2)
@@ -74,14 +80,19 @@ static states step(/*register struct re_guts *g, int start, int stop, register s
 #define        NONCHAR(c)      ((c) > CHAR_MAX)
 #define        NNONCHAR        (CODEMAX-CHAR_MAX)
 #ifdef REDEBUG
 #define        NONCHAR(c)      ((c) > CHAR_MAX)
 #define        NNONCHAR        (CODEMAX-CHAR_MAX)
 #ifdef REDEBUG
-static void print(/*struct match *m, char *caption, states st, int ch, FILE *d*/);
+static void print(struct match *m, char *caption, states st, int ch, FILE *d);
 #endif
 #ifdef REDEBUG
 #endif
 #ifdef REDEBUG
-static void at(/*struct match *m, char *title, char *start, char *stop, sopno startst, stopno stopst*/);
+static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst);
 #endif
 #ifdef REDEBUG
 #endif
 #ifdef REDEBUG
-static char *pchar(/*int ch*/);
+static char *pchar(int ch);
+#endif
+
+#ifdef __cplusplus
+}
 #endif
 #endif
+/* ========= end header generated by ./mkh ========= */
 
 #ifdef REDEBUG
 #define        SP(t, s, c)     print(m, t, s, c, stdout)
 
 #ifdef REDEBUG
 #define        SP(t, s, c)     print(m, t, s, c, stdout)
@@ -429,10 +440,12 @@ sopno stopst;
                        break;
                case OLPAREN:
                        i = OPND(m->g->strip[ss]);
                        break;
                case OLPAREN:
                        i = OPND(m->g->strip[ss]);
+                       assert(0 < i && i <= m->g->nsub);
                        m->pmatch[i].rm_so = sp - m->offp;
                        break;
                case ORPAREN:
                        i = OPND(m->g->strip[ss]);
                        m->pmatch[i].rm_so = sp - m->offp;
                        break;
                case ORPAREN:
                        i = OPND(m->g->strip[ss]);
+                       assert(0 < i && i <= m->g->nsub);
                        m->pmatch[i].rm_eo = sp - m->offp;
                        break;
                default:                /* uh oh */
                        m->pmatch[i].rm_eo = sp - m->offp;
                        break;
                default:                /* uh oh */
@@ -558,6 +571,7 @@ sopno lev;                  /* PLUS nesting level */
        switch (OP(s)) {
        case OBACK_:            /* the vilest depths */
                i = OPND(s);
        switch (OP(s)) {
        case OBACK_:            /* the vilest depths */
                i = OPND(s);
+               assert(0 < i && i <= m->g->nsub);
                if (m->pmatch[i].rm_eo == -1)
                        return(NULL);
                assert(m->pmatch[i].rm_so != -1);
                if (m->pmatch[i].rm_eo == -1)
                        return(NULL);
                assert(m->pmatch[i].rm_so != -1);
@@ -618,6 +632,7 @@ sopno lev;                  /* PLUS nesting level */
                break;
        case OLPAREN:           /* must undo assignment if rest fails */
                i = OPND(s);
                break;
        case OLPAREN:           /* must undo assignment if rest fails */
                i = OPND(s);
+               assert(0 < i && i <= m->g->nsub);
                offsave = m->pmatch[i].rm_so;
                m->pmatch[i].rm_so = sp - m->offp;
                dp = backref(m, sp, stop, ss+1, stopst, lev);
                offsave = m->pmatch[i].rm_so;
                m->pmatch[i].rm_so = sp - m->offp;
                dp = backref(m, sp, stop, ss+1, stopst, lev);
@@ -628,6 +643,7 @@ sopno lev;                  /* PLUS nesting level */
                break;
        case ORPAREN:           /* must undo assignment if rest fails */
                i = OPND(s);
                break;
        case ORPAREN:           /* must undo assignment if rest fails */
                i = OPND(s);
+               assert(0 < i && i <= m->g->nsub);
                offsave = m->pmatch[i].rm_eo;
                m->pmatch[i].rm_eo = sp - m->offp;
                dp = backref(m, sp, stop, ss+1, stopst, lev);
                offsave = m->pmatch[i].rm_eo;
                m->pmatch[i].rm_eo = sp - m->offp;
                dp = backref(m, sp, stop, ss+1, stopst, lev);
@@ -826,7 +842,7 @@ sopno stopst;
 
 /*
  - step - map set of states reachable before char to set reachable after
 
 /*
  - step - map set of states reachable before char to set reachable after
- == static states step(register struct re_guts *g, int start, int stop, \
+ == static states step(register struct re_guts *g, sopno start, sopno stop, \
  ==    register states bef, int ch, register states aft);
  == #define    BOL     (OUT+1)
  == #define    EOL     (BOL+1)
  ==    register states bef, int ch, register states aft);
  == #define    BOL     (OUT+1)
  == #define    EOL     (BOL+1)
@@ -841,8 +857,8 @@ sopno stopst;
 static states
 step(g, start, stop, bef, ch, aft)
 register struct re_guts *g;
 static states
 step(g, start, stop, bef, ch, aft)
 register struct re_guts *g;
-int start;                     /* start state within strip */
-int stop;                      /* state after stop state within strip */
+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 states bef;           /* states reachable before */
 int ch;                                /* character or NONCHAR code */
 register states aft;           /* states already known reachable after */
@@ -990,7 +1006,7 @@ FILE *d;
  - at - print current situation
  == #ifdef REDEBUG
  == static void at(struct match *m, char *title, char *start, char *stop, \
  - at - print current situation
  == #ifdef REDEBUG
  == static void at(struct match *m, char *title, char *start, char *stop, \
- ==                                            sopno startst, stopno stopst);
+ ==                                            sopno startst, sopno stopst);
  == #endif
  */
 static void
  == #endif
  */
 static void
index 31bdde1..3368503 100644 (file)
@@ -1,5 +1,5 @@
-.\" Copyright (c) 1992 Henry Spencer.
-.\" Copyright (c) 1992, 1993
+.\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
+.\" Copyright (c) 1992, 1993, 1994
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" This code is derived from software contributed to Berkeley by
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" This code is derived from software contributed to Berkeley by
@@ -7,7 +7,7 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"    @(#)re_format.7 8.1 (Berkeley) %G%
+.\"    @(#)re_format.7 8.2 (Berkeley) %G%
 .\"
 .TH RE_FORMAT 7 ""
 .SH NAME
 .\"
 .TH RE_FORMAT 7 ""
 .SH NAME
@@ -143,12 +143,14 @@ There are two special cases\(dg of bracket expressions:
 the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at
 the beginning and end of a word respectively.
 A word is defined as a sequence of
 the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at
 the beginning and end of a word respectively.
 A word is defined as a sequence of
-.I alnum
-characters (as defined by
-.IR ctype (3))
+word characters
 which is neither preceded nor followed by
 which is neither preceded nor followed by
+word characters.
+A word character is an
 .I alnum
 .I alnum
-characters.
+character (as defined by
+.IR ctype (3))
+or an underscore.
 This is an extension,
 compatible with but not specified by POSIX 1003.2,
 and should be used with
 This is an extension,
 compatible with but not specified by POSIX 1003.2,
 and should be used with
@@ -237,3 +239,5 @@ Avoid using them.
 1003.2's specification of case-independent matching is vague.
 The ``one case implies all cases'' definition given above
 is current consensus among implementors as to the right interpretation.
 1003.2's specification of case-independent matching is vague.
 The ``one case implies all cases'' definition given above
 is current consensus among implementors as to the right interpretation.
+.PP
+The syntax for word boundaries is incredibly ugly.
index 38aea8f..58f7f08 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,11 +8,11 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)regcomp.c   8.1 (Berkeley) %G%
+ *     @(#)regcomp.c   8.2 (Berkeley) %G%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)regcomp.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)regcomp.c  8.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -47,47 +47,57 @@ struct parse {
        sopno pend[NPAREN];     /* -> ) ([0] unused) */
 };
 
        sopno pend[NPAREN];     /* -> ) ([0] unused) */
 };
 
+/* ========= begin header generated by ./mkh ========= */
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 
-static void p_ere(/*register struct parse *p, int stop*/);
-static void p_ere_exp(/*register struct parse *p*/);
-static void p_str(/*register struct parse *p*/);
-static void p_bre(/*register struct parse *p, register int end1, register int end2*/);
-static int p_simp_re(/*register struct parse *p, int starordinary*/);
-static int p_count(/*register struct parse *p*/);
-static void p_bracket(/*register struct parse *p*/);
-static void p_b_term(/*register struct parse *p, register cset *cs*/);
-static void p_b_cclass(/*register struct parse *p, register cset *cs*/);
-static void p_b_eclass(/*register struct parse *p, register cset *cs*/);
-static char p_b_symbol(/*register struct parse *p*/);
-static char p_b_coll_elem(/*register struct parse *p, int endc*/);
-static char othercase(/*int ch*/);
-static void bothcases(/*register struct parse *p, int ch*/);
-static void ordinary(/*register struct parse *p, register int ch*/);
-static void nonnewline(/*register struct parse *p*/);
-static void repeat(/*register struct parse *p, sopno start, int from, int to*/);
-static int seterr(/*register struct parse *p, int e*/);
-static cset *allocset(/*register struct parse *p*/);
-static void freeset(/*register struct parse *p, register cset *cs*/);
-static int freezeset(/*register struct parse *p, register cset *cs*/);
-static int firstch(/*register struct parse *p, register cset *cs*/);
-static int nch(/*register struct parse *p, register cset *cs*/);
-static void mcadd(/*register struct parse *p, register cset *cs, register char *cp*/);
-static void mcsub(/*register cset *cs, register char *cp*/);
-static int mcin(/*register cset *cs, register char *cp*/);
-static char *mcfind(/*register cset *cs, register char *cp*/);
-static void mcinvert(/*register cset *cs*/);
-static void mccase(/*register cset *cs*/);
-static int isinsets(/*register struct re_guts *g, int c*/);
-static int samesets(/*register struct re_guts *g, int c1, int c2*/);
-static void categorize(/*struct parse *p, register struct re_guts *g*/);
-static sopno dupl(/*register struct parse *p, sopno start, sopno finish*/);
-static void doemit(/*register struct parse *p, sop op, size_t opnd*/);
-static void doinsert(/*register struct parse *p, sop op, size_t opnd, sopno pos*/);
-static void dofwd(/*register struct parse *p, sopno pos, sop value*/);
-static void enlarge(/*register struct parse *p, sopno size*/);
-static void stripsnug(/*register struct parse *p, register struct re_guts *g*/);
-static void findmust(/*register struct parse *p, register struct re_guts *g*/);
-static sopno pluscount(/*register struct parse *p, register struct re_guts *g*/);
+/* === regcomp.c === */
+static void p_ere(register struct parse *p, int stop);
+static void p_ere_exp(register struct parse *p);
+static void p_str(register struct parse *p);
+static void p_bre(register struct parse *p, register int end1, register int end2);
+static int p_simp_re(register struct parse *p, int starordinary);
+static int p_count(register struct parse *p);
+static void p_bracket(register struct parse *p);
+static void p_b_term(register struct parse *p, register cset *cs);
+static void p_b_cclass(register struct parse *p, register cset *cs);
+static void p_b_eclass(register struct parse *p, register cset *cs);
+static char p_b_symbol(register struct parse *p);
+static char p_b_coll_elem(register struct parse *p, int endc);
+static char othercase(int ch);
+static void bothcases(register struct parse *p, int ch);
+static void ordinary(register struct parse *p, register int ch);
+static void nonnewline(register struct parse *p);
+static void repeat(register struct parse *p, sopno start, int from, int to);
+static int seterr(register struct parse *p, int e);
+static cset *allocset(register struct parse *p);
+static void freeset(register struct parse *p, register cset *cs);
+static int freezeset(register struct parse *p, register cset *cs);
+static int firstch(register struct parse *p, register cset *cs);
+static int nch(register struct parse *p, register cset *cs);
+static void mcadd(register struct parse *p, register cset *cs, register char *cp);
+static void mcsub(register cset *cs, register char *cp);
+static int mcin(register cset *cs, register char *cp);
+static char *mcfind(register cset *cs, register char *cp);
+static void mcinvert(register struct parse *p, register cset *cs);
+static void mccase(register struct parse *p, register cset *cs);
+static int isinsets(register struct re_guts *g, int c);
+static int samesets(register struct re_guts *g, int c1, int c2);
+static void categorize(struct parse *p, register struct re_guts *g);
+static sopno dupl(register struct parse *p, sopno start, sopno finish);
+static void doemit(register struct parse *p, sop op, size_t opnd);
+static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos);
+static void dofwd(register struct parse *p, sopno pos, sop value);
+static void enlarge(register struct parse *p, sopno size);
+static void stripsnug(register struct parse *p, register struct re_guts *g);
+static void findmust(register struct parse *p, register struct re_guts *g);
+static sopno pluscount(register struct parse *p, register struct re_guts *g);
+
+#ifdef __cplusplus
+}
+#endif
+/* ========= end header generated by ./mkh ========= */
 
 static char nuls[10];          /* place to point scanner in event of error */
 
 
 static char nuls[10];          /* place to point scanner in event of error */
 
@@ -112,8 +122,8 @@ static char nuls[10];               /* place to point scanner in event of error */
 #define        MUSTSEE(c, e)   (REQUIRE(MORE() && PEEK() == (c), e))
 #define        MUSTEAT(c, e)   (REQUIRE(MORE() && GETNEXT() == (c), e))
 #define        MUSTNOTSEE(c, e)        (REQUIRE(!MORE() || PEEK() != (c), e))
 #define        MUSTSEE(c, e)   (REQUIRE(MORE() && PEEK() == (c), e))
 #define        MUSTEAT(c, e)   (REQUIRE(MORE() && GETNEXT() == (c), e))
 #define        MUSTNOTSEE(c, e)        (REQUIRE(!MORE() || PEEK() != (c), e))
-#define        EMIT(sop, sopnd)        doemit(p, sop, (size_t)(sopnd))
-#define        INSERT(sop, pos)        doinsert(p, sop, HERE()-(pos)+1, pos)
+#define        EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
+#define        INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
 #define        AHEAD(pos)              dofwd(p, pos, HERE()-(pos))
 #define        ASTERN(sop, pos)        EMIT(sop, HERE()-pos)
 #define        HERE()          (p->slen)
 #define        AHEAD(pos)              dofwd(p, pos, HERE()-(pos))
 #define        ASTERN(sop, pos)        EMIT(sop, HERE()-pos)
 #define        HERE()          (p->slen)
@@ -122,11 +132,13 @@ static char nuls[10];             /* place to point scanner in event of error */
 
 #ifndef NDEBUG
 static int never = 0;          /* for use in asserts; shuts lint up */
 
 #ifndef NDEBUG
 static int never = 0;          /* for use in asserts; shuts lint up */
+#else
+#define        never   0               /* some <assert.h>s have bugs too */
 #endif
 
 /*
  - regcomp - interface for parser and compilation
 #endif
 
 /*
  - regcomp - interface for parser and compilation
- = extern int regcomp(regex_t *preg, const char *pattern, int cflags);
+ = extern int regcomp(regex_t *, const char *, int);
  = #define     REG_BASIC       0000
  = #define     REG_EXTENDED    0001
  = #define     REG_ICASE       0002
  = #define     REG_BASIC       0000
  = #define     REG_EXTENDED    0001
  = #define     REG_ICASE       0002
@@ -147,7 +159,13 @@ int cflags;
        register struct parse *p = &pa;
        register int i;
        register size_t len;
        register struct parse *p = &pa;
        register int i;
        register size_t len;
+#ifdef REDEBUG
+#      define  GOODFLAGS(f)    (f)
+#else
+#      define  GOODFLAGS(f)    ((f)&~REG_DUMP)
+#endif
 
 
+       cflags = GOODFLAGS(cflags);
        if ((cflags&REG_EXTENDED) && (cflags&REG_NOSPEC))
                return(REG_INVARG);
 
        if ((cflags&REG_EXTENDED) && (cflags&REG_NOSPEC))
                return(REG_INVARG);
 
@@ -785,7 +803,7 @@ register cset *cs;
        while ((c = *u++) != '\0')
                CHadd(cs, c);
        for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
        while ((c = *u++) != '\0')
                CHadd(cs, c);
        for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
-               MCadd(cs, u);
+               MCadd(p, cs, u);
 }
 
 /*
 }
 
 /*
@@ -1037,6 +1055,7 @@ register struct parse *p;
        register size_t nbytes;
        register cset *cs;
        register size_t css = (size_t)p->g->csetsize;
        register size_t nbytes;
        register cset *cs;
        register size_t css = (size_t)p->g->csetsize;
+       register int i;
 
        if (no >= p->ncsalloc) {        /* need another column of space */
                p->ncsalloc += CHAR_BIT;
 
        if (no >= p->ncsalloc) {        /* need another column of space */
                p->ncsalloc += CHAR_BIT;
@@ -1049,10 +1068,14 @@ register struct parse *p;
                        p->g->sets = (cset *)realloc((char *)p->g->sets,
                                                        nc * sizeof(cset));
                if (p->g->setbits == NULL)
                        p->g->sets = (cset *)realloc((char *)p->g->sets,
                                                        nc * sizeof(cset));
                if (p->g->setbits == NULL)
-                       p->g->setbits = (uchar *)malloc(nbytes);
-               else
-                       p->g->setbits = (uchar *)realloc((char *)p->g->setbits,
+                       p->g->setbits = (uch *)malloc(nbytes);
+               else {
+                       p->g->setbits = (uch *)realloc((char *)p->g->setbits,
                                                                nbytes);
                                                                nbytes);
+                       /* xxx this isn't right if setbits is now NULL */
+                       for (i = 0; i < no; i++)
+                               p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT);
+               }
                if (p->g->sets != NULL && p->g->setbits != NULL)
                        (void) memset((char *)p->g->setbits + (nbytes - css),
                                                                0, css);
                if (p->g->sets != NULL && p->g->setbits != NULL)
                        (void) memset((char *)p->g->setbits + (nbytes - css),
                                                                0, css);
@@ -1108,7 +1131,7 @@ freezeset(p, cs)
 register struct parse *p;
 register cset *cs;
 {
 register struct parse *p;
 register cset *cs;
 {
-       register uchar h = cs->hash;
+       register uch h = cs->hash;
        register int i;
        register cset *top = &p->g->sets[p->g->ncsets];
        register cset *cs2;
        register int i;
        register cset *top = &p->g->sets[p->g->ncsets];
        register cset *cs2;
@@ -1258,13 +1281,14 @@ register char *cp;
 
 /*
  - mcinvert - invert the list of collating elements in a cset
 
 /*
  - mcinvert - invert the list of collating elements in a cset
- == static void mcinvert(register cset *cs);
+ == static void mcinvert(register struct parse *p, register cset *cs);
  *
  * This would have to know the set of possibilities.  Implementation
  * is deferred.
  */
 static void
  *
  * This would have to know the set of possibilities.  Implementation
  * is deferred.
  */
 static void
-mcinvert(cs)
+mcinvert(p, cs)
+register struct parse *p;
 register cset *cs;
 {
        assert(cs->multis == NULL);     /* xxx */
 register cset *cs;
 {
        assert(cs->multis == NULL);     /* xxx */
@@ -1272,13 +1296,14 @@ register cset *cs;
 
 /*
  - mccase - add case counterparts of the list of collating elements in a cset
 
 /*
  - mccase - add case counterparts of the list of collating elements in a cset
- == static void mccase(register cset *cs);
+ == static void mccase(register struct parse *p, register cset *cs);
  *
  * This would have to know the set of possibilities.  Implementation
  * is deferred.
  */
 static void
  *
  * This would have to know the set of possibilities.  Implementation
  * is deferred.
  */
 static void
-mccase(cs)
+mccase(p, cs)
+register struct parse *p;
 register cset *cs;
 {
        assert(cs->multis == NULL);     /* xxx */
 register cset *cs;
 {
        assert(cs->multis == NULL);     /* xxx */
@@ -1293,7 +1318,7 @@ isinsets(g, c)
 register struct re_guts *g;
 int c;
 {
 register struct re_guts *g;
 int c;
 {
-       register uchar *col;
+       register uch *col;
        register int i;
        register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
        register unsigned uc = (unsigned char)c;
        register int i;
        register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
        register unsigned uc = (unsigned char)c;
@@ -1314,7 +1339,7 @@ register struct re_guts *g;
 int c1;
 int c2;
 {
 int c1;
 int c2;
 {
-       register uchar *col;
+       register uch *col;
        register int i;
        register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
        register unsigned uc1 = (unsigned char)c1;
        register int i;
        register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
        register unsigned uc1 = (unsigned char)c1;
@@ -1499,7 +1524,7 @@ register struct parse *p;
 register struct re_guts *g;
 {
        g->nstates = p->slen;
 register struct re_guts *g;
 {
        g->nstates = p->slen;
-       g->strip = (sop *)realloc((sop *)p->strip, p->slen * sizeof(sop));
+       g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop));
        if (g->strip == NULL) {
                SETERROR(REG_ESPACE);
                g->strip = p->strip;
        if (g->strip == NULL) {
                SETERROR(REG_ESPACE);
                g->strip = p->strip;
@@ -1586,8 +1611,10 @@ register struct re_guts *g;
        for (i = g->mlen; i > 0; i--) {
                while (OP(s = *scan++) != OCHAR)
                        continue;
        for (i = g->mlen; i > 0; i--) {
                while (OP(s = *scan++) != OCHAR)
                        continue;
+               assert(cp < g->must + g->mlen);
                *cp++ = (char)OPND(s);
        }
                *cp++ = (char)OPND(s);
        }
+       assert(cp == g->must + g->mlen);
        *cp++ = '\0';           /* just on general principles */
 }
 
        *cp++ = '\0';           /* just on general principles */
 }
 
index c11c3f3..c7c9f55 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,11 +8,11 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)regerror.c  8.1 (Berkeley) %G%
+ *     @(#)regerror.c  8.2 (Berkeley) %G%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)regerror.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)regerror.c 8.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -25,8 +25,18 @@ static char sccsid[] = "@(#)regerror.c       8.1 (Berkeley) %G%";
 
 #include "utils.h"
 
 
 #include "utils.h"
 
-static char *regatoi __P((const regex_t *, char *));
+/* ========= begin header generated by ./mkh ========= */
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 
+/* === regerror.c === */
+static char *regatoi(const regex_t *preg, char *localbuf);
+
+#ifdef __cplusplus
+}
+#endif
+/* ========= end header generated by ./mkh ========= */
 /*
  = #define     REG_NOMATCH      1
  = #define     REG_BADPAT       2
 /*
  = #define     REG_NOMATCH      1
  = #define     REG_BADPAT       2
@@ -73,8 +83,7 @@ static struct rerr {
 
 /*
  - regerror - the interface to error numbers
 
 /*
  - regerror - the interface to error numbers
- = extern size_t regerror(int errcode, const regex_t *preg, char *errbuf, \
- =                                                     size_t errbuf_size);
+ = extern size_t regerror(int, const regex_t *, char *, size_t);
  */
 /* ARGSUSED */
 size_t
  */
 /* ARGSUSED */
 size_t
@@ -123,7 +132,7 @@ size_t errbuf_size;
 
 /*
  - regatoi - internal routine to implement REG_ATOI
 
 /*
  - regatoi - internal routine to implement REG_ATOI
- = static char *regatoi(const regex_t *preg, char *localbuf);
+ == static char *regatoi(const regex_t *preg, char *localbuf);
  */
 static char *
 regatoi(preg, localbuf)
  */
 static char *
 regatoi(preg, localbuf)
index e24ee3a..654a722 100644 (file)
@@ -1,5 +1,5 @@
-.\" Copyright (c) 1992 Henry Spencer.
-.\" Copyright (c) 1992, 1993
+.\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
+.\" Copyright (c) 1992, 1993, 1994
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" This code is derived from software contributed to Berkeley by
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" This code is derived from software contributed to Berkeley by
@@ -7,13 +7,13 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"    @(#)regex.3     8.1 (Berkeley) %G%
+.\"    @(#)regex.3     8.2 (Berkeley) %G%
 .\"
 .\"
+.TH REGEX 3 ""
 .de ZR
 .\" one other place knows this name:  the SEE ALSO section
 .IR re_format (7) \\$1
 ..
 .de ZR
 .\" one other place knows this name:  the SEE ALSO section
 .IR re_format (7) \\$1
 ..
-.TH REGEX 3 ""
 .SH NAME
 regcomp, regexec, regerror, regfree \- regular-expression library
 .SH SYNOPSIS
 .SH NAME
 regcomp, regexec, regerror, regfree \- regular-expression library
 .SH SYNOPSIS
@@ -456,8 +456,8 @@ REG_ASSERT  ``can't happen''\(emyou found a bug
 REG_INVARG     invalid argument, e.g. negative-length string
 .fi
 .SH HISTORY
 REG_INVARG     invalid argument, e.g. negative-length string
 .fi
 .SH HISTORY
-Written by Henry Spencer at University of Toronto,
-henry@zoo.toronto.edu.
+Originally written by Henry Spencer at University of Toronto.
+Altered for inclusion in the 4.4BSD distribution.
 .SH BUGS
 This is an alpha release with known defects.
 Please report problems.
 .SH BUGS
 This is an alpha release with known defects.
 Please report problems.
index 877631a..4d61ab0 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)regex2.h    8.2 (Berkeley) %G%
+ *     @(#)regex2.h    8.3 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -17,7 +17,7 @@
  = typedef struct {
  =     int re_magic;
  =     size_t re_nsub;         // number of parenthesized subexpressions
  = typedef struct {
  =     int re_magic;
  =     size_t re_nsub;         // number of parenthesized subexpressions
- =     const char *re_endp;    // end pointer for REG_PEND
+ =     const char *re_endp;    // end pointer for REG_PEND
  =     struct re_guts *re_g;   // none of your business :-)
  = } regex_t;
  = typedef struct {
  =     struct re_guts *re_g;   // none of your business :-)
  = } regex_t;
  = typedef struct {
@@ -93,19 +93,19 @@ typedef long sopno;
  * vectors at run time.
  */
 typedef struct {
  * vectors at run time.
  */
 typedef struct {
-       uchar *ptr;             /* -> uchar [csetsize] */
-       uchar mask;             /* bit within array */
-       uchar hash;             /* hash code */
+       uch *ptr;               /* -> uch [csetsize] */
+       uch mask;               /* bit within array */
+       uch hash;               /* hash code */
        size_t smultis;
        char *multis;           /* -> char[smulti]  ab\0cd\0ef\0\0 */
 } cset;
 /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
        size_t smultis;
        char *multis;           /* -> char[smulti]  ab\0cd\0ef\0\0 */
 } cset;
 /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#define        CHadd(cs, c)    ((cs)->ptr[(uchar)(c)] |= (cs)->mask, (cs)->hash += (c))
-#define        CHsub(cs, c)    ((cs)->ptr[(uchar)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
-#define        CHIN(cs, c)     ((cs)->ptr[(uchar)(c)] & (cs)->mask)
-#define        MCadd(cs, cp)   mcadd(cs, cp)   /* regcomp() internal fns */
-#define        MCsub(cs, cp)   mcsub(cs, cp)
-#define        MCin(cs, cp)    mcin(cs, cp)
+#define        CHadd(cs, c)    ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
+#define        CHsub(cs, c)    ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
+#define        CHIN(cs, c)     ((cs)->ptr[(uch)(c)] & (cs)->mask)
+#define        MCadd(p, cs, cp)        mcadd(p, cs, cp)        /* regcomp() internal fns */
+#define        MCsub(p, cs, cp)        mcsub(p, cs, cp)
+#define        MCin(p, cs, cp) mcin(p, cs, cp)
 
 /* stuff for character categories */
 typedef unsigned char cat_t;
 
 /* stuff for character categories */
 typedef unsigned char cat_t;
@@ -120,7 +120,7 @@ struct re_guts {
        int csetsize;           /* number of bits in a cset vector */
        int ncsets;             /* number of csets in use */
        cset *sets;             /* -> cset [ncsets] */
        int csetsize;           /* number of bits in a cset vector */
        int ncsets;             /* number of csets in use */
        cset *sets;             /* -> cset [ncsets] */
-       uchar *setbits;         /* -> uchar[csetsize][ncsets/CHAR_BIT] */
+       uch *setbits;           /* -> uch[csetsize][ncsets/CHAR_BIT] */
        int cflags;             /* copy of regcomp() cflags argument */
        sopno nstates;          /* = number of sops */
        sopno firststate;       /* the initial OEND (normally 0) */
        int cflags;             /* copy of regcomp() cflags argument */
        sopno nstates;          /* = number of sops */
        sopno firststate;       /* the initial OEND (normally 0) */
index 30c99da..5fa5cd5 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,11 +8,11 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)regexec.c   8.1 (Berkeley) %G%
+ *     @(#)regexec.c   8.2 (Berkeley) %G%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)regexec.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)regexec.c  8.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -113,8 +113,8 @@ static int nope = 0;                /* for use in asserts; shuts lint up */
 
 /*
  - regexec - interface for matching
 
 /*
  - regexec - interface for matching
- = extern int regexec(const regex_t *preg, const char *string, size_t nmatch, \
- =                                     regmatch_t pmatch[], int eflags);
+ = extern int regexec(const regex_t *, const char *, size_t, \
+ =                                     regmatch_t [], int);
  = #define     REG_NOTBOL      00001
  = #define     REG_NOTEOL      00002
  = #define     REG_STARTEND    00004
  = #define     REG_NOTBOL      00001
  = #define     REG_NOTEOL      00002
  = #define     REG_STARTEND    00004
@@ -146,8 +146,7 @@ int eflags;
        assert(!(g->iflags&BAD));
        if (g->iflags&BAD)              /* backstop for no-debug case */
                return(REG_BADPAT);
        assert(!(g->iflags&BAD));
        if (g->iflags&BAD)              /* backstop for no-debug case */
                return(REG_BADPAT);
-       if (eflags != GOODFLAGS(eflags))
-               return(REG_INVARG);
+       eflags = GOODFLAGS(eflags);
 
        if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
                return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
 
        if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
                return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
index baea780..fba5af6 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,11 +8,11 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)regfree.c   8.1 (Berkeley) %G%
+ *     @(#)regfree.c   8.2 (Berkeley) %G%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)regfree.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)regfree.c  8.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -25,7 +25,7 @@ static char sccsid[] = "@(#)regfree.c 8.1 (Berkeley) %G%";
 
 /*
  - regfree - free everything
 
 /*
  - regfree - free everything
- = extern void regfree(regex_t *preg);
+ = extern void regfree(regex_t *);
  */
 void
 regfree(preg)
  */
 void
 regfree(preg)
index 3ad767e..b81e2dc 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1992 Henry Spencer.
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994 Henry Spencer.
+ * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -8,19 +8,24 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)utils.h     8.1 (Berkeley) %G%
+ *     @(#)utils.h     8.2 (Berkeley) %G%
  */
 
 /* utility definitions */
 #define        DUPMAX          _POSIX2_RE_DUP_MAX      /* xxx is this right? */
  */
 
 /* utility definitions */
 #define        DUPMAX          _POSIX2_RE_DUP_MAX      /* xxx is this right? */
-#define        INFINITY        (DUPMAX+1)
-#define        NC              ((CHAR_MAX)-(CHAR_MIN)+1)
-
-typedef unsigned char uchar;
+#define        INFINITY        (DUPMAX + 1)
+#define        NC              (CHAR_MAX - CHAR_MIN + 1)
+typedef unsigned char uch;
 
 
+/* switch off assertions (if not already off) if no REDEBUG */
 #ifndef REDEBUG
 #ifndef NDEBUG
 #define        NDEBUG  /* no assertions please */
 #endif
 #endif
 #include <assert.h>
 #ifndef REDEBUG
 #ifndef NDEBUG
 #define        NDEBUG  /* no assertions please */
 #endif
 #endif
 #include <assert.h>
+
+/* for old systems with bcopy() but no memmove() */
+#ifdef USEBCOPY
+#define        memmove(d, s, c)        bcopy(s, d, c)
+#endif