mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
libast: regex: re-backport robustness improvements from 93v- beta
That intermittent regression test failure in types.sh seems to be gone. So let's reimport the regex changes into the 1.0 branch to subject them to wider testing and make sure any failures stay gone. (re:48568476
,38aab428
,1aa8f771
) [Original commit message from1aa8f771
follows] There are two main changes: 1. The regex code now creates and uses its own stack (env->mst) instead of using the shared standard stack (stkstd). That seems likely to be a good thing. 2. Missing mbinit() calls were inserted. The 93v- code uses a completely different multibyte characters API, so these needed to be translated back to the older API. But, as mbinit() is no longer a no-op as of300cd199
, these calls do stop things from breaking if a previous operation is interrupted mid-character. I think there might be a couple of off-by-one errors fixed as well, as there are two instances of this change: - while ((index += skip[buf[index]]) < mid); + while (index < mid) + index += skip[buf[index]];
This commit is contained in:
parent
4032050249
commit
de511cfbc2
8 changed files with 89 additions and 60 deletions
|
@ -55,6 +55,7 @@ regcollate(register const char* s, char** e, char* buf, size_t size, wchar_t* wc
|
|||
if (size < 2 || (term = *s) != '.' && term != '=' || !*++s || *s == term && *(s + 1) == ']')
|
||||
goto nope;
|
||||
t = s;
|
||||
mbinit();
|
||||
w = mbchar(s);
|
||||
if ((r = (s - t)) > 1)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
||||
* Copyright (c) 1985-2013 AT&T Intellectual Property *
|
||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
|
@ -1082,6 +1082,7 @@ col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, in
|
|||
if (cc > 0)
|
||||
{
|
||||
cc = -1;
|
||||
mbinit();
|
||||
k += mbconv((char*)k, c);
|
||||
}
|
||||
else
|
||||
|
@ -1092,6 +1093,7 @@ col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, in
|
|||
if (ep)
|
||||
{
|
||||
k = key;
|
||||
mbinit();
|
||||
c = mbchar(k);
|
||||
if (iswupper(c))
|
||||
bt = COLL_range_uc;
|
||||
|
@ -1123,6 +1125,7 @@ col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, in
|
|||
s = (char*)ep;
|
||||
if (ic)
|
||||
{
|
||||
mbinit();
|
||||
c = mbchar(s);
|
||||
if (iswupper(c))
|
||||
{
|
||||
|
@ -1138,6 +1141,7 @@ col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, in
|
|||
if (cc > 0)
|
||||
{
|
||||
cc = -1;
|
||||
mbinit();
|
||||
k += mbconv((char*)k, c);
|
||||
}
|
||||
else
|
||||
|
@ -1146,6 +1150,7 @@ col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, in
|
|||
*k = 0;
|
||||
mbxfrm(ce->end, key, COLL_KEY_MAX);
|
||||
k = key;
|
||||
mbinit();
|
||||
c = mbchar(k);
|
||||
if (iswupper(c))
|
||||
et = COLL_range_uc;
|
||||
|
@ -1515,6 +1520,7 @@ bra(Cenv_t* env)
|
|||
if (env->token.len > 1 || w >= 0 && w < T_META)
|
||||
{
|
||||
c = w;
|
||||
mbinit();
|
||||
w = mbconv(mbc, c);
|
||||
pp = (unsigned char*)mbc;
|
||||
env->cursor += env->token.len;
|
||||
|
@ -1613,6 +1619,7 @@ bra(Cenv_t* env)
|
|||
if (iswupper(wc))
|
||||
{
|
||||
wc = towlower(wc);
|
||||
mbinit();
|
||||
rw = mbconv((char*)pp, wc);
|
||||
c = 'u';
|
||||
}
|
||||
|
@ -1666,6 +1673,7 @@ bra(Cenv_t* env)
|
|||
wc = towupper(wc);
|
||||
c = 'U';
|
||||
}
|
||||
mbinit();
|
||||
rw = mbconv((char*)pp, wc);
|
||||
i = 0;
|
||||
}
|
||||
|
@ -2097,7 +2105,7 @@ grp(Cenv_t* env, int parno)
|
|||
switch (c)
|
||||
{
|
||||
case ')':
|
||||
if (!(env->flags & REG_LITERAL))
|
||||
if (!(env->flags & (REG_LITERAL|REG_SHELL)))
|
||||
{
|
||||
env->error = REG_BADRPT;
|
||||
return 0;
|
||||
|
@ -2530,7 +2538,7 @@ grp(Cenv_t* env, int parno)
|
|||
}
|
||||
c = token(env);
|
||||
env->parnest--;
|
||||
if (c != T_CLOSE && (!(env->flags & REG_LITERAL) || c != ')'))
|
||||
if (c != T_CLOSE && (c != ')' || !(env->flags & (REG_LITERAL|REG_SHELL))))
|
||||
{
|
||||
env->error = REG_EPAREN;
|
||||
goto nope;
|
||||
|
@ -2616,6 +2624,7 @@ seq(Cenv_t* env)
|
|||
c = towupper(c);
|
||||
if ((&buf[sizeof(buf)] - s) < MB_CUR_MAX)
|
||||
break;
|
||||
mbinit();
|
||||
if ((n = mbconv((char*)s, c)) < 0)
|
||||
*s++ = c;
|
||||
else if (n)
|
||||
|
@ -3269,6 +3278,8 @@ regcomp(regex_t* p, const char* pattern, regflags_t flags)
|
|||
if (!(p->env = (Env_t*)alloc(disc, 0, sizeof(Env_t))))
|
||||
return fatal(disc, REG_ESPACE, pattern);
|
||||
memset(p->env, 0, sizeof(*p->env));
|
||||
if (!(p->env->mst = stkopen(STK_SMALL|STK_NULL)))
|
||||
return fatal(disc, REG_ESPACE, pattern);
|
||||
memset(&env, 0, sizeof(env));
|
||||
env.regex = p;
|
||||
env.flags = flags;
|
||||
|
@ -3391,7 +3402,7 @@ regcomp(regex_t* p, const char* pattern, regflags_t flags)
|
|||
p->re_nsub /= 2;
|
||||
if (env.flags & REG_DELIMITED)
|
||||
{
|
||||
p->re_npat = env.cursor - env.pattern + 1;
|
||||
p->re_npat = env.cursor - (unsigned char*)pattern + 1;
|
||||
if (*env.cursor == env.delimiter)
|
||||
p->re_npat++;
|
||||
else if (env.flags & REG_MUSTDELIM)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1985-2011 AT&T Intellectual Property *
|
||||
* Copyright (c) 1985-2013 AT&T Intellectual Property *
|
||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
|
@ -69,7 +69,7 @@ detrie(Trie_node_t* x, Sfio_t* sp, char* b, char* p, char* e, int delimiter)
|
|||
}
|
||||
|
||||
static int
|
||||
decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
||||
decomp(register Rex_t* e, Rex_t* parent, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
||||
{
|
||||
Rex_t* q;
|
||||
unsigned char* s;
|
||||
|
@ -91,10 +91,10 @@ decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
|||
switch (e->type)
|
||||
{
|
||||
case REX_ALT:
|
||||
if (decomp(e->re.group.expr.binary.left, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.binary.left, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
sfputc(sp, '|');
|
||||
if (e->re.group.expr.binary.right && decomp(e->re.group.expr.binary.right, sp, type, delimiter, flags))
|
||||
if (e->re.group.expr.binary.right && decomp(e->re.group.expr.binary.right, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
break;
|
||||
case REX_BACK:
|
||||
|
@ -140,11 +140,13 @@ decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
|||
sfputc(sp, '?');
|
||||
else
|
||||
c = 0;
|
||||
if (e->re.group.expr.rex && e->re.group.expr.rex->type == REX_GROUP)
|
||||
c = 0;
|
||||
}
|
||||
switch (e->type)
|
||||
{
|
||||
case REX_REP:
|
||||
if (decomp(e->re.group.expr.rex, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.rex, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
break;
|
||||
case REX_CLASS:
|
||||
|
@ -321,7 +323,7 @@ decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
|||
case REX_NEG:
|
||||
if (type >= SRE)
|
||||
sfprintf(sp, "!(");
|
||||
if (decomp(e->re.group.expr.rex, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.rex, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
if (type >= SRE)
|
||||
sfputc(sp, ')');
|
||||
|
@ -329,17 +331,17 @@ decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
|||
sfputc(sp, '!');
|
||||
break;
|
||||
case REX_CONJ:
|
||||
if (decomp(e->re.group.expr.binary.left, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.binary.left, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
sfputc(sp, '&');
|
||||
if (decomp(e->re.group.expr.binary.right, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.binary.right, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
break;
|
||||
case REX_GROUP:
|
||||
if (type >= SRE)
|
||||
if (type >= SRE && parent->type != REX_REP)
|
||||
sfputc(sp, '@');
|
||||
meta(sp, '(', type, 1, delimiter);
|
||||
if (decomp(e->re.group.expr.rex, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.rex, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
meta(sp, ')', type, 1, delimiter);
|
||||
break;
|
||||
|
@ -349,22 +351,22 @@ decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
|||
case REX_GROUP_BEHIND_NOT:
|
||||
meta(sp, '(', type, 1, delimiter);
|
||||
sfputc(sp, '?');
|
||||
if (decomp(e->re.group.expr.rex, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.rex, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
meta(sp, ')', type, 1, delimiter);
|
||||
break;
|
||||
case REX_GROUP_COND:
|
||||
meta(sp, '(', type, 1, delimiter);
|
||||
sfputc(sp, '?');
|
||||
if (e->re.group.expr.binary.left && decomp(e->re.group.expr.binary.left, sp, type, delimiter, flags))
|
||||
if (e->re.group.expr.binary.left && decomp(e->re.group.expr.binary.left, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
if (q = e->re.group.expr.binary.right)
|
||||
{
|
||||
sfputc(sp, ':');
|
||||
if (q->re.group.expr.binary.left && decomp(q->re.group.expr.binary.left, sp, type, delimiter, flags))
|
||||
if (q->re.group.expr.binary.left && decomp(q->re.group.expr.binary.left, q, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
sfputc(sp, ':');
|
||||
if (q->re.group.expr.binary.right && decomp(q->re.group.expr.binary.right, sp, type, delimiter, flags))
|
||||
if (q->re.group.expr.binary.right && decomp(q->re.group.expr.binary.right, q, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
}
|
||||
meta(sp, ')', type, 1, delimiter);
|
||||
|
@ -372,7 +374,7 @@ decomp(register Rex_t* e, Sfio_t* sp, int type, int delimiter, regflags_t flags)
|
|||
case REX_GROUP_CUT:
|
||||
meta(sp, '(', type, 1, delimiter);
|
||||
sfputc(sp, '?');
|
||||
if (decomp(e->re.group.expr.rex, sp, type, delimiter, flags))
|
||||
if (decomp(e->re.group.expr.rex, e, sp, type, delimiter, flags))
|
||||
return 1;
|
||||
meta(sp, ')', type, 1, delimiter);
|
||||
break;
|
||||
|
@ -429,7 +431,7 @@ regdecomp(regex_t* p, regflags_t flags, char* buf, size_t n)
|
|||
}
|
||||
else
|
||||
delimiter = -1;
|
||||
if (decomp(p->env->rex, sp, type, delimiter, flags))
|
||||
if (decomp(p->env->rex, p->env->rex, sp, type, delimiter, flags))
|
||||
r = 0;
|
||||
else
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* POSIX regex error message handler
|
||||
*/
|
||||
|
||||
static const char id[] = "\n@(#)$Id: regex (AT&T Research) 2012-05-31 $\0\n";
|
||||
static const char id[] = "\n@(#)$Id: regex (AT&T Research) 2012-09-27 $\0\n";
|
||||
|
||||
#include "reglib.h"
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
|
||||
int
|
||||
regexec(const regex_t* p, const char* s, size_t nmatch, regmatch_t* match, regflags_t flags)
|
||||
regexec_20120528(const regex_t* p, const char* s, size_t nmatch, regmatch_t* match, regflags_t flags)
|
||||
{
|
||||
if (flags & REG_STARTEND)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
||||
* Copyright (c) 1985-2013 AT&T Intellectual Property *
|
||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
|
@ -172,9 +172,9 @@ typedef struct regsubop_s
|
|||
|
||||
#define HIT SSIZE_MAX
|
||||
|
||||
#define bitclr(p,c) ((p)[((c)>>3)&037]&=(~(1<<((c)&07))))
|
||||
#define bitset(p,c) ((p)[((c)>>3)&037]|=(1<<((c)&07)))
|
||||
#define bittst(p,c) ((p)[((c)>>3)&037]&(1<<((c)&07)))
|
||||
#define bitclr(p,c) ((p)[(c)>>3]&=(~(1<<((c)&07))))
|
||||
#define bitset(p,c) ((p)[(c)>>3]|=(1<<((c)&07)))
|
||||
#define bittst(p,c) ((p)[(c)>>3]&(1<<((c)&07)))
|
||||
|
||||
#define setadd(p,c) bitset((p)->bits,c)
|
||||
#define setclr(p,c) bitclr((p)->bits,c)
|
||||
|
@ -536,6 +536,7 @@ typedef struct reglib_s /* library private regex_t info */
|
|||
Vector_t* bestpos; /* ditto for best match */
|
||||
regmatch_t* match; /* subexrs in current match */
|
||||
regmatch_t* best; /* ditto in best match yet */
|
||||
Stk_t* mst; /* match stack */
|
||||
Stk_pos_t stk; /* exec stack pos */
|
||||
size_t min; /* minimum match length */
|
||||
size_t nsub; /* internal re_nsub */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
||||
* Copyright (c) 1985-2013 AT&T Intellectual Property *
|
||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
|
@ -235,8 +235,8 @@ typedef struct
|
|||
} Match_frame_t;
|
||||
|
||||
#define matchpush(e,x) ((x)->re.group.number?_matchpush(e,x):0)
|
||||
#define matchcopy(e,x) do if ((x)->re.group.number) { Match_frame_t* fp = (void*)stkframe(stkstd)->data; memcpy(fp->match, fp->save, fp->size); } while (0)
|
||||
#define matchpop(e,x) do if ((x)->re.group.number) { Match_frame_t* fp = (void*)stkframe(stkstd)->data; memcpy(fp->match, fp->save, fp->size); stkpop(stkstd); } while (0)
|
||||
#define matchcopy(e,x) do if ((x)->re.group.number) { Match_frame_t* fp = (void*)stkframe(e->mst)->data; memcpy(fp->match, fp->save, fp->size); } while (0)
|
||||
#define matchpop(e,x) do if ((x)->re.group.number) { Match_frame_t* fp = (void*)stkframe(e->mst)->data; memcpy(fp->match, fp->save, fp->size); stkpop(e->mst); } while (0)
|
||||
|
||||
#define pospop(e) (--(e)->pos->cur)
|
||||
|
||||
|
@ -255,7 +255,7 @@ _matchpush(Env_t* env, Rex_t* rex)
|
|||
|
||||
if (rex->re.group.number <= 0 || (num = rex->re.group.last - rex->re.group.number + 1) <= 0)
|
||||
num = 0;
|
||||
if (!(f = (Match_frame_t*)stkpush(stkstd, sizeof(Match_frame_t) + (num - 1) * sizeof(regmatch_t))))
|
||||
if (!(f = (Match_frame_t*)stkpush(env->mst, sizeof(Match_frame_t) + (num - 1) * sizeof(regmatch_t))))
|
||||
{
|
||||
env->error = REG_ESPACE;
|
||||
return 1;
|
||||
|
@ -627,6 +627,7 @@ collic(register Celt_t* ce, char* key, register char* nxt, int c, int x)
|
|||
c = towlower(c);
|
||||
else
|
||||
return 0;
|
||||
mbinit();
|
||||
x = mbconv(key, c);
|
||||
key[x] = 0;
|
||||
return collelt(ce, key, c, 0);
|
||||
|
@ -879,6 +880,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI
|
|||
}
|
||||
else
|
||||
{
|
||||
mbinit();
|
||||
while (s < e)
|
||||
{
|
||||
c = mbchar(s);
|
||||
|
@ -961,7 +963,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI
|
|||
e = env->end;
|
||||
if (!(rex->flags & REG_MINIMAL))
|
||||
{
|
||||
if (!(b = (unsigned char*)stkpush(stkstd, n)))
|
||||
if (!(b = (unsigned char*)stkpush(env->mst, n)))
|
||||
{
|
||||
env->error = REG_ESPACE;
|
||||
return BAD;
|
||||
|
@ -975,19 +977,19 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI
|
|||
switch (follow(env, rex, cont, s))
|
||||
{
|
||||
case BAD:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return BAD;
|
||||
case CUT:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return CUT;
|
||||
case BEST:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return BEST;
|
||||
case GOOD:
|
||||
r = GOOD;
|
||||
break;
|
||||
}
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1107,7 +1109,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!(b = (unsigned char*)stkpush(stkstd, n)))
|
||||
if (!(b = (unsigned char*)stkpush(env->mst, n)))
|
||||
{
|
||||
env->error = REG_ESPACE;
|
||||
return BAD;
|
||||
|
@ -1119,19 +1121,19 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI
|
|||
switch (follow(env, rex, cont, s))
|
||||
{
|
||||
case BAD:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return BAD;
|
||||
case CUT:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return CUT;
|
||||
case BEST:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return BEST;
|
||||
case GOOD:
|
||||
r = GOOD;
|
||||
break;
|
||||
}
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1419,7 +1421,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
n = ((i + 7) >> 3) + 1;
|
||||
catcher.type = REX_NEG_CATCH;
|
||||
catcher.re.neg_catch.beg = s;
|
||||
if (!(p = (unsigned char*)stkpush(stkstd, n)))
|
||||
if (!(p = (unsigned char*)stkpush(env->mst, n)))
|
||||
return BAD;
|
||||
memset(catcher.re.neg_catch.index = p, 0, n);
|
||||
catcher.next = rex->next;
|
||||
|
@ -1451,7 +1453,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
break;
|
||||
}
|
||||
}
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return r;
|
||||
case REX_NEG_CATCH:
|
||||
bitset(rex->re.neg_catch.index, s - rex->re.neg_catch.beg);
|
||||
|
@ -1518,7 +1520,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!(b = (unsigned char*)stkpush(stkstd, n)))
|
||||
if (!(b = (unsigned char*)stkpush(env->mst, n)))
|
||||
{
|
||||
env->error = REG_ESPACE;
|
||||
return BAD;
|
||||
|
@ -1529,6 +1531,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
for (i = 0; s < e && i < n; i++, s = t)
|
||||
{
|
||||
t = s;
|
||||
mbinit();
|
||||
if (mbchar(t) != c)
|
||||
break;
|
||||
b[i] = t - s;
|
||||
|
@ -1539,6 +1542,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
for (i = 0; s < e && i < n; i++, s = t)
|
||||
{
|
||||
t = s;
|
||||
mbinit();
|
||||
if (towupper(mbchar(t)) != c)
|
||||
break;
|
||||
b[i] = t - s;
|
||||
|
@ -1548,19 +1552,19 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
switch (follow(env, rex, cont, s))
|
||||
{
|
||||
case BAD:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return BAD;
|
||||
case BEST:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return BEST;
|
||||
case CUT:
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
return CUT;
|
||||
case GOOD:
|
||||
r = GOOD;
|
||||
break;
|
||||
}
|
||||
stkpop(stkstd);
|
||||
stkpop(env->mst);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1621,6 +1625,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
for (i = 0; i < m && s < e; i++, s = t)
|
||||
{
|
||||
t = s;
|
||||
mbinit();
|
||||
if (mbchar(t) != c)
|
||||
return r;
|
||||
}
|
||||
|
@ -1636,7 +1641,10 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
case GOOD:
|
||||
return BEST;
|
||||
}
|
||||
if (s >= e || mbchar(s) != c)
|
||||
if (s >= e)
|
||||
break;
|
||||
mbinit();
|
||||
if (mbchar(s) != c)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1645,6 +1653,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
for (i = 0; i < m && s < e; i++, s = t)
|
||||
{
|
||||
t = s;
|
||||
mbinit();
|
||||
if (towupper(mbchar(t)) != c)
|
||||
return r;
|
||||
}
|
||||
|
@ -1660,7 +1669,10 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _
|
|||
case GOOD:
|
||||
return BEST;
|
||||
}
|
||||
if (s >= e || towupper(mbchar(s)) != c)
|
||||
if (s >= e)
|
||||
break;
|
||||
mbinit();
|
||||
if (towupper(mbchar(s)) != c)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1843,7 +1855,7 @@ list(Env_t* env, Rex_t* rex)
|
|||
*/
|
||||
|
||||
int
|
||||
regnexec(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t* match, regflags_t flags)
|
||||
regnexec_20120528(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t* match, regflags_t flags)
|
||||
{
|
||||
register ssize_t n;
|
||||
register int i;
|
||||
|
@ -1868,14 +1880,14 @@ regnexec(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t*
|
|||
env->regex = p;
|
||||
env->beg = (unsigned char*)s;
|
||||
env->end = env->beg + len;
|
||||
stknew(stkstd, &env->stk);
|
||||
env->flags &= ~REG_EXEC;
|
||||
env->flags |= (flags & REG_EXEC);
|
||||
advance = 0;
|
||||
stknew(env->mst, &env->stk);
|
||||
if (env->stack = env->hard || !(env->flags & REG_NOSUB) && nmatch)
|
||||
{
|
||||
n = env->nsub;
|
||||
if (!(env->match = (regmatch_t*)stkpush(stkstd, 2 * (n + 1) * sizeof(regmatch_t))) ||
|
||||
if (!(env->match = (regmatch_t*)stkpush(env->mst, 2 * (n + 1) * sizeof(regmatch_t))) ||
|
||||
!env->pos && !(env->pos = vecopen(16, sizeof(Pos_t))) ||
|
||||
!env->bestpos && !(env->bestpos = vecopen(16, sizeof(Pos_t))))
|
||||
{
|
||||
|
@ -1915,7 +1927,8 @@ regnexec(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t*
|
|||
DEBUG_TEST(0x0080,(sfprintf(sfstdout, "AHA#%04d REX_BM len=%d right=%d left=%d size=%d %d %d\n", __LINE__, len, e->re.bm.right, e->re.bm.left, e->re.bm.size, index, mid)),(0));
|
||||
for (;;)
|
||||
{
|
||||
while ((index += skip[buf[index]]) < mid);
|
||||
while (index < mid)
|
||||
index += skip[buf[index]];
|
||||
if (index < HIT)
|
||||
{
|
||||
DEBUG_TEST(0x0080,(sfprintf(sfstdout, "AHA#%04d REG_NOMATCH %d %d\n", __LINE__, index, HIT)),(0));
|
||||
|
@ -2009,7 +2022,7 @@ regnexec(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t*
|
|||
}
|
||||
k = 0;
|
||||
done:
|
||||
stkold(stkstd, &env->stk);
|
||||
stkold(env->mst, &env->stk);
|
||||
env->stk.base = 0;
|
||||
if (k > REG_NOMATCH)
|
||||
fatal(p->env->disc, k, NiL);
|
||||
|
@ -2038,8 +2051,8 @@ regfree(regex_t* p)
|
|||
vecclose(env->pos);
|
||||
if (env->bestpos)
|
||||
vecclose(env->bestpos);
|
||||
if (env->stk.base)
|
||||
stkold(stkstd, &env->stk);
|
||||
if (env->mst)
|
||||
stkclose(env->mst);
|
||||
alloc(env->disc, env, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
||||
* Copyright (c) 1985-2013 AT&T Intellectual Property *
|
||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
|
@ -33,9 +33,9 @@
|
|||
*/
|
||||
|
||||
int
|
||||
regrexec(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t* match, regflags_t flags, int sep, void* handle, regrecord_t record)
|
||||
regrexec_20120528(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t* match, regflags_t flags, int sep, void* handle, regrecord_t record)
|
||||
{
|
||||
register unsigned char* buf = (unsigned char*)s;
|
||||
register unsigned char* buf;
|
||||
register unsigned char* beg;
|
||||
register unsigned char* l;
|
||||
register unsigned char* r;
|
||||
|
@ -72,7 +72,8 @@ regrexec(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t*
|
|||
index = leftlen++;
|
||||
for (;;)
|
||||
{
|
||||
while ((index += skip[buf[index]]) < mid);
|
||||
while (index < mid)
|
||||
index += skip[buf[index]];
|
||||
if (index < HIT)
|
||||
goto impossible;
|
||||
index -= HIT;
|
||||
|
|
Loading…
Reference in a new issue