summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex
diff options
context:
space:
mode:
authordcs <dcs@FreeBSD.org>2000-07-07 07:46:36 +0000
committerdcs <dcs@FreeBSD.org>2000-07-07 07:46:36 +0000
commit88593e5a993ce0a65b73111dbfbeafda775878e6 (patch)
tree5cbd0ce0d84cc805324f2ad32fc58780ab35f177 /lib/libc/regex
parentf5198f88cf58e1d0eafa9a3b8ea70511589ea363 (diff)
downloadFreeBSD-src-88593e5a993ce0a65b73111dbfbeafda775878e6.zip
FreeBSD-src-88593e5a993ce0a65b73111dbfbeafda775878e6.tar.gz
Deal with the signed/unsigned chars issue in a more proper manner. We
use a CHAR_MIN-based array, like elsewhere in the code. Remove a number of unused variables (some due to the above change, one that was left after a number of optimizing steps through the source). Brucified by: bde
Diffstat (limited to 'lib/libc/regex')
-rw-r--r--lib/libc/regex/engine.c30
-rw-r--r--lib/libc/regex/regcomp.c8
2 files changed, 17 insertions, 21 deletions
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c
index 8bc3de8..a12538f 100644
--- a/lib/libc/regex/engine.c
+++ b/lib/libc/regex/engine.c
@@ -155,15 +155,12 @@ int eflags;
char *start;
char *stop;
/* Boyer-Moore algorithms variables */
- register unsigned char *pp;
+ register char *pp;
int cj, mj;
- register unsigned char *mustfirst;
- register unsigned char *mustlast;
- register int mustlen;
+ register char *mustfirst;
+ register char *mustlast;
register int *matchjump;
register int *charjump;
- register unsigned char *bmp;
- register unsigned char *bmps;
/* simplify the situation where possible */
if (g->cflags&REG_NOSUB)
@@ -181,39 +178,36 @@ int eflags;
/* prescreening; this does wonders for this rather slow code */
if (g->must != NULL) {
if (g->charjump != NULL && g->matchjump != NULL) {
- mustlen = -g->mlen;
mustfirst = g->must;
mustlast = g->must + g->mlen - 1;
charjump = g->charjump;
matchjump = g->matchjump;
- bmps = stop;
pp = mustlast;
- for (bmp = start+g->mlen-1; bmp < bmps;) {
+ for (dp = start+g->mlen-1; dp < stop;) {
/* Fast skip non-matches */
- while (bmp < bmps && charjump[*bmp])
- bmp += charjump[*bmp];
+ while (dp < stop && charjump[*dp])
+ dp += charjump[*dp];
- if (bmp >= bmps)
+ if (dp >= stop)
break;
/* Greedy matcher */
/* We depend on not being used for
* for strings of length 1
*/
- while (*--bmp == *--pp && pp != mustfirst);
+ while (*--dp == *--pp && pp != mustfirst);
- if (*bmp == *pp)
+ if (*dp == *pp)
break;
/* Jump to next possible match */
mj = matchjump[pp - mustfirst];
- cj = charjump[*bmp];
- bmp += (cj < mj ? mj : cj);
- pp = mustlast;
+ cj = charjump[*dp];
+ dp += (cj < mj ? mj : cj);
+ pp = mustlast;
}
if (pp != mustfirst)
return(REG_NOMATCH);
- dp = bmp;
} else {
for (dp = start; dp < stop; dp++)
if (*dp == g->must[0] &&
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index e943374..9664084 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -1942,14 +1942,16 @@ struct re_guts *g;
if (p->error != 0)
return;
- g->charjump = malloc((UCHAR_MAX+1) * sizeof(int));
+ g->charjump = malloc((NC + 1) * sizeof(int));
if (g->charjump == NULL) /* Not a fatal error */
return;
+ /* Adjust for signed chars, if necessary */
+ g->charjump = &g->charjump[-(CHAR_MIN)];
/* If the character does not exist in the pattern, the jump
* is equal to the number of characters in the pattern.
*/
- for (ch = 0; ch < (UCHAR_MAX+1); ch++)
+ for (ch = CHAR_MIN; ch < (CHAR_MAX + 1); ch++)
g->charjump[ch] = g->mlen;
/* If the character does exist, compute the jump that would
@@ -1958,7 +1960,7 @@ struct re_guts *g;
* is the first one that would be matched).
*/
for (mindex = 0; mindex < g->mlen; mindex++)
- g->charjump[(unsigned char)g->must[mindex]] = g->mlen - mindex - 1;
+ g->charjump[g->must[mindex]] = g->mlen - mindex - 1;
}
/*
OpenPOWER on IntegriCloud