mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
libast: regex: backport robustness improvements from 93v- beta
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 of 300cd199
, 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
7c30a59e25
commit
1aa8f771d8
8 changed files with 89 additions and 60 deletions
|
@ -56,6 +56,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 *
|
||||
|
@ -1083,6 +1083,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
|
||||
|
@ -1093,6 +1094,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;
|
||||
|
@ -1124,6 +1126,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))
|
||||
{
|
||||
|
@ -1139,6 +1142,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
|
||||
|
@ -1147,6 +1151,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;
|
||||
|
@ -1516,6 +1521,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;
|
||||
|
@ -1614,6 +1620,7 @@ bra(Cenv_t* env)
|
|||
if (iswupper(wc))
|
||||
{
|
||||
wc = towlower(wc);
|
||||
mbinit();
|
||||
rw = mbconv((char*)pp, wc);
|
||||
c = 'u';
|
||||
}
|
||||
|
@ -1667,6 +1674,7 @@ bra(Cenv_t* env)
|
|||
wc = towupper(wc);
|
||||
c = 'U';
|
||||
}
|
||||
mbinit();
|
||||
rw = mbconv((char*)pp, wc);
|
||||
i = 0;
|
||||
}
|
||||
|
@ -2098,7 +2106,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;
|
||||
|
@ -2531,7 +2539,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;
|
||||
|
@ -2617,6 +2625,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)
|
||||
|
@ -3270,6 +3279,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;
|
||||
|
@ -3392,7 +3403,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 *
|
||||
|
@ -70,7 +70,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;
|
||||
|
@ -92,10 +92,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:
|
||||
|
@ -141,11 +141,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:
|
||||
|
@ -322,7 +324,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, ')');
|
||||
|
@ -330,17 +332,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;
|
||||
|
@ -350,22 +352,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);
|
||||
|
@ -373,7 +375,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;
|
||||
|
@ -430,7 +432,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
|
||||
{
|
||||
|
|
|
@ -26,7 +26,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"
|
||||
|
||||
|
|
|
@ -34,7 +34,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 *
|
||||
|
@ -173,9 +173,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)
|
||||
|
@ -537,6 +537,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 *
|
||||
|
@ -236,8 +236,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)
|
||||
|
||||
|
@ -256,7 +256,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;
|
||||
|
@ -628,6 +628,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);
|
||||
|
@ -880,6 +881,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI
|
|||
}
|
||||
else
|
||||
{
|
||||
mbinit();
|
||||
while (s < e)
|
||||
{
|
||||
c = mbchar(s);
|
||||
|
@ -962,7 +964,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;
|
||||
|
@ -976,19 +978,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
|
||||
{
|
||||
|
@ -1108,7 +1110,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;
|
||||
|
@ -1120,19 +1122,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
|
||||
|
@ -1420,7 +1422,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;
|
||||
|
@ -1452,7 +1454,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);
|
||||
|
@ -1519,7 +1521,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;
|
||||
|
@ -1530,6 +1532,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;
|
||||
|
@ -1540,6 +1543,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;
|
||||
|
@ -1549,19 +1553,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
|
||||
|
@ -1622,6 +1626,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;
|
||||
}
|
||||
|
@ -1637,7 +1642,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;
|
||||
}
|
||||
}
|
||||
|
@ -1646,6 +1654,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;
|
||||
}
|
||||
|
@ -1661,7 +1670,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;
|
||||
}
|
||||
}
|
||||
|
@ -1844,7 +1856,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;
|
||||
|
@ -1869,14 +1881,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))))
|
||||
{
|
||||
|
@ -1916,7 +1928,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));
|
||||
|
@ -2010,7 +2023,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);
|
||||
|
@ -2039,8 +2052,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 *
|
||||
|
@ -34,9 +34,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;
|
||||
|
@ -73,7 +73,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…
Add table
Add a link
Reference in a new issue