diff options
-rw-r--r-- | lib/libc/regex/regcomp.c | 39 | ||||
-rw-r--r-- | lib/libc/regex/regex2.h | 9 | ||||
-rw-r--r-- | regress/lib/libc/regex/debug.c | 41 |
3 files changed, 5 insertions, 84 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 06b3a8c57f2..60ec1676ad6 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: regcomp.c,v 1.39 2020/12/31 17:16:38 millert Exp $ */ +/* $OpenBSD: regcomp.c,v 1.40 2020/12/31 17:20:19 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 @@ -92,7 +92,6 @@ static int firstch(struct parse *, cset *); static int nch(struct parse *, cset *); static int isinsets(struct re_guts *, int); static int samesets(struct re_guts *, int, int); -static void categorize(struct parse *, struct re_guts *); static sopno dupl(struct parse *, sopno, sopno); static void doemit(struct parse *, sop, size_t); static void doinsert(struct parse *, sop, size_t, sopno); @@ -198,9 +197,6 @@ regcomp(regex_t *preg, const char *pattern, int cflags) g->must = NULL; g->mlen = 0; g->nsub = 0; - g->ncategories = 1; /* category 0 is "everything else" */ - g->categories = &g->catspace[-(CHAR_MIN)]; - memset(g->catspace, 0, sizeof(g->catspace)); g->backrefs = 0; /* do it */ @@ -216,7 +212,6 @@ regcomp(regex_t *preg, const char *pattern, int cflags) g->laststate = THERE(); /* tidy up loose ends and fill things in */ - categorize(p, g); stripsnug(p, g); findmust(p, g); g->nplus = pluscount(p, g); @@ -883,15 +878,10 @@ bothcases(struct parse *p, int ch) static void ordinary(struct parse *p, int ch) { - cat_t *cap = p->g->categories; - if ((p->g->cflags®_ICASE) && isalpha((uch)ch) && othercase(ch) != ch) bothcases(p, ch); - else { + else EMIT(OCHAR, (uch)ch); - if (cap[ch] == 0) - cap[ch] = p->g->ncategories++; - } } /* @@ -1194,31 +1184,6 @@ samesets(struct re_guts *g, int c1, int c2) } /* - - categorize - sort out character categories - */ -static void -categorize(struct parse *p, struct re_guts *g) -{ - cat_t *cats = g->categories; - int c; - int c2; - cat_t cat; - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - for (c = CHAR_MIN; c <= CHAR_MAX; c++) - if (cats[c] == 0 && isinsets(g, c)) { - cat = g->ncategories++; - cats[c] = cat; - for (c2 = c+1; c2 <= CHAR_MAX; c2++) - if (cats[c2] == 0 && samesets(g, c, c2)) - cats[c2] = cat; - } -} - -/* - dupl - emit a duplicate of a bunch of sops */ static sopno /* start of duplicate */ diff --git a/lib/libc/regex/regex2.h b/lib/libc/regex/regex2.h index 4098c94a41b..7f8f73ad842 100644 --- a/lib/libc/regex/regex2.h +++ b/lib/libc/regex/regex2.h @@ -1,4 +1,4 @@ -/* $OpenBSD: regex2.h,v 1.9 2020/12/30 08:54:42 tb Exp $ */ +/* $OpenBSD: regex2.h,v 1.10 2020/12/31 17:20:19 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. @@ -112,9 +112,6 @@ typedef struct { #define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c)) #define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask) -/* stuff for character categories */ -typedef unsigned char cat_t; - /* * main compiled-expression structure */ @@ -136,15 +133,11 @@ struct re_guts { # define BAD 04 /* something wrong */ int nbol; /* number of ^ used */ int neol; /* number of $ used */ - int ncategories; /* how many character categories */ - cat_t *categories; /* ->catspace[-CHAR_MIN] */ char *must; /* match must contain this string */ int mlen; /* length of must */ size_t nsub; /* copy of re_nsub */ int backrefs; /* does it use back references? */ sopno nplus; /* how deep does it nest +s? */ - /* catspace must be last */ - cat_t catspace[NC]; /* actually [NC] */ }; /* misc utilities */ diff --git a/regress/lib/libc/regex/debug.c b/regress/lib/libc/regex/debug.c index 11129e7249d..7044a2a185a 100644 --- a/regress/lib/libc/regex/debug.c +++ b/regress/lib/libc/regex/debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ +/* $OpenBSD: debug.c,v 1.5 2020/12/31 17:20:19 millert Exp $ */ /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ #include <stdio.h> @@ -26,10 +26,8 @@ FILE *d; register int i; register int c; register int last; - int nincat[NC]; - fprintf(d, "%ld states, %d categories", (long)g->nstates, - g->ncategories); + fprintf(d, "%ld states", (long)g->nstates); fprintf(d, ", first %ld last %ld", (long)g->firststate, (long)g->laststate); if (g->iflags&USEBOL) @@ -49,41 +47,6 @@ FILE *d; fprintf(d, ", nplus %ld", (long)g->nplus); fprintf(d, "\n"); s_print(g, d); - for (i = 0; i < g->ncategories; i++) { - nincat[i] = 0; - for (c = CHAR_MIN; c <= CHAR_MAX; c++) - if (g->categories[c] == i) - nincat[i]++; - } - fprintf(d, "cc0#%d", nincat[0]); - for (i = 1; i < g->ncategories; i++) - if (nincat[i] == 1) { - for (c = CHAR_MIN; c <= CHAR_MAX; c++) - if (g->categories[c] == i) - break; - fprintf(d, ", %d=%s", i, regchar(c)); - } - fprintf(d, "\n"); - for (i = 1; i < g->ncategories; i++) - if (nincat[i] != 1) { - fprintf(d, "cc%d\t", i); - last = -1; - for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */ - if (c <= CHAR_MAX && g->categories[c] == i) { - if (last < 0) { - fprintf(d, "%s", regchar(c)); - last = c; - } - } else { - if (last >= 0) { - if (last != c-1) - fprintf(d, "-%s", - regchar(c-1)); - last = -1; - } - } - fprintf(d, "\n"); - } } /* |