diff options
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | generic/regexec.c | 79 | ||||
-rw-r--r-- | tests/reg.test | 6 |
3 files changed, 77 insertions, 28 deletions
@@ -1,3 +1,23 @@ +1999-06-25 <stanton@scriptics.com> + + * tests/reg.test: + * generic/regexec.c: Fixed bugs in non-greedy quantifiers. + +1999-06-23 <stanton@scriptics.com> + + * unix/Makefile.in: Changed install-doc to install-man. + + * tools/uniParse.tcl: + * tools/uniClass.tcl: + * tools/README: + * tests/string.test: + * generic/regc_locale.c: + * generic/tclUniData.c: + * generic/tclUtf.c: + * doc/string.n: Updated Unicode character tables to reflect latest + Unicode 2.1 data. Also rationalized "regexp" and "string is" + definitions of character classes. + 1999-06-21 <stanton@scriptics.com> * unix/tclUnixThrd.c (TclpThreadCreate): Fixed memory leak where diff --git a/generic/regexec.c b/generic/regexec.c index bac019d..ab9dc21 100644 --- a/generic/regexec.c +++ b/generic/regexec.c @@ -124,6 +124,7 @@ struct smalldfa { int exec _ANSI_ARGS_((regex_t *, CONST chr *, size_t, rm_detail_t *, size_t, regmatch_t [], int)); static int find _ANSI_ARGS_((struct vars *, struct cnfa *, struct colormap *)); static int cfind _ANSI_ARGS_((struct vars *, struct cnfa *, struct colormap *)); +static int cfindloop _ANSI_ARGS_((struct vars *, struct cnfa *, struct colormap *, struct dfa *, struct dfa *, chr **)); static VOID zapsubs _ANSI_ARGS_((regmatch_t *, size_t)); static VOID zapmem _ANSI_ARGS_((struct vars *, struct subre *)); static VOID subset _ANSI_ARGS_((struct vars *, struct subre *, chr *, chr *)); @@ -265,7 +266,7 @@ struct colormap *cm; struct smalldfa sa; struct dfa *s = newdfa(v, &v->g->search, cm, &sa); chr *begin; - chr *end = NULL; /* needed to eliminate gcc warning */ + chr *end = NULL; chr *cold; chr *open; /* open and close of range of possible starts */ chr *close; @@ -353,6 +354,47 @@ struct colormap *cm; struct dfa *d = newdfa(v, cnfa, cm, &da); struct smalldfa sa; struct dfa *s = newdfa(v, &v->g->search, cm, &sa); + chr *cold; + int ret; + + if (d == NULL) + return v->err; + if (s == NULL) { + freedfa(d); + return v->err; + } + + ret = cfindloop(v, cnfa, cm, d, s, &cold); + + freedfa(d); + freedfa(s); + if (ISERR()) + return v->err; + if (v->g->cflags®_EXPECT) { + assert(v->details != NULL); + if (cold != NULL) + v->details->rm_extend.rm_so = OFF(cold); + else + v->details->rm_extend.rm_so = OFF(v->stop); + v->details->rm_extend.rm_eo = OFF(v->stop); /* unknown */ + } + return ret; +} + +/* + - cfindloop - the heart of cfind + ^ static int cfindloop(struct vars *, struct cnfa *, struct colormap *, + ^ struct dfa *, struct dfa *, chr **); + */ +static int +cfindloop(v, cnfa, cm, d, s, coldp) +struct vars *v; +struct cnfa *cnfa; +struct colormap *cm; +struct dfa *d; +struct dfa *s; +chr **coldp; /* where to put coldstart pointer */ +{ chr *begin; chr *end; chr *cold; @@ -362,16 +404,9 @@ struct colormap *cm; chr *estop; int er; int shorter = v->g->tree->flags&SHORTER; - int ret = REG_NOMATCH; int hitend; - if (d == NULL) - return v->err; - if (s == NULL) { - freedfa(d); - return v->err; - } - + assert(d != NULL && s != NULL); cold = NULL; close = v->start; do { @@ -407,16 +442,17 @@ struct colormap *cm; v->pmatch[0].rm_so = OFF(begin); v->pmatch[0].rm_eo = OFF(end); } - ret = REG_OKAY; - break; /* NOTE BREAK OUT */ + *coldp = cold; + return REG_OKAY; } if (er != REG_NOMATCH) { ERR(er); - break; /* NOTE BREAK OUT */ + return er; } if ((shorter) ? end == estop : end == begin) { /* no point in trying again */ - break; /* NOTE BREAK OUT */ + *coldp = cold; + return REG_NOMATCH; } /* go around and try again */ if (shorter) @@ -427,19 +463,8 @@ struct colormap *cm; } } while (close < v->stop); - freedfa(d); - freedfa(s); - if (ISERR()) - return v->err; - if (v->g->cflags®_EXPECT) { - assert(v->details != NULL); - if (cold != NULL) - v->details->rm_extend.rm_so = OFF(cold); - else - v->details->rm_extend.rm_so = OFF(v->stop); - v->details->rm_extend.rm_eo = OFF(v->stop); /* unknown */ - } - return ret; + *coldp = cold; + return REG_NOMATCH; } /* @@ -670,7 +695,7 @@ chr *end; /* end of same */ int er; assert(t != NULL); - MDEBUG(("cdissect %ld-%ld\n", LOFF(begin), LOFF(end))); + MDEBUG(("cdissect %ld-%ld %c\n", LOFF(begin), LOFF(end), t->op)); switch (t->op) { case '=': /* terminal node */ diff --git a/tests/reg.test b/tests/reg.test index 4b51248..503c3bc 100644 --- a/tests/reg.test +++ b/tests/reg.test @@ -6,7 +6,7 @@ # # Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. # -# RCS: @(#) $Id: reg.test,v 1.4 1999/06/17 19:30:26 stanton Exp $ +# RCS: @(#) $Id: reg.test,v 1.5 1999/06/25 18:42:14 stanton Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -850,6 +850,10 @@ m 5 P ab?? ab a m 6 P ab??c abc abc m 7 PQ "ab{2,4}?" abbbb abb m 8 PQ "ab{2,4}?c" abbbbc abbbbc +m 9 - 3z* 123zzzz456 3zzzz +m 10 P 3z*? 123zzzz456 3 +m 11 - z*4 123zzzz456 zzzz4 +m 12 P z*?4 123zzzz456 zzzz4 |