mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-30 19:20:53 +02:00
Split tokenize() into shtokenize() and zshtokenize()
to improve SH_GLOB handling, particularly in completion
This commit is contained in:
parent
b7aa69cb7d
commit
cefd2de2e1
3 changed files with 22 additions and 8 deletions
|
@ -2797,7 +2797,7 @@ readoutput(int in, int qt)
|
||||||
|
|
||||||
while (*words) {
|
while (*words) {
|
||||||
if (isset(GLOBSUBST))
|
if (isset(GLOBSUBST))
|
||||||
tokenize(*words);
|
shtokenize(*words);
|
||||||
addlinknode(ret, *words++);
|
addlinknode(ret, *words++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
Src/glob.c
18
Src/glob.c
|
@ -2447,6 +2447,20 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr)
|
||||||
/**/
|
/**/
|
||||||
mod_export void
|
mod_export void
|
||||||
tokenize(char *s)
|
tokenize(char *s)
|
||||||
|
{
|
||||||
|
zshtokenize(s, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
mod_export void
|
||||||
|
shtokenize(char *s)
|
||||||
|
{
|
||||||
|
zshtokenize(s, isset(SHGLOB));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
static void
|
||||||
|
zshtokenize(char *s, int shglob)
|
||||||
{
|
{
|
||||||
char *t;
|
char *t;
|
||||||
int bslash = 0;
|
int bslash = 0;
|
||||||
|
@ -2463,7 +2477,7 @@ tokenize(char *s)
|
||||||
bslash = 1;
|
bslash = 1;
|
||||||
continue;
|
continue;
|
||||||
case '<':
|
case '<':
|
||||||
if (isset(SHGLOB))
|
if (shglob)
|
||||||
break;
|
break;
|
||||||
if (bslash) {
|
if (bslash) {
|
||||||
s[-1] = Bnull;
|
s[-1] = Bnull;
|
||||||
|
@ -2482,7 +2496,7 @@ tokenize(char *s)
|
||||||
case '(':
|
case '(':
|
||||||
case '|':
|
case '|':
|
||||||
case ')':
|
case ')':
|
||||||
if (isset(SHGLOB))
|
if (shglob)
|
||||||
break;
|
break;
|
||||||
case '>':
|
case '>':
|
||||||
case '^':
|
case '^':
|
||||||
|
|
10
Src/subst.c
10
Src/subst.c
|
@ -197,7 +197,7 @@ stringsubst(LinkList list, LinkNode node, int ssub, int asssub)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!qt && ssub && isset(GLOBSUBST))
|
if (!qt && ssub && isset(GLOBSUBST))
|
||||||
tokenize(s);
|
shtokenize(s);
|
||||||
l1 = str2 - str3;
|
l1 = str2 - str3;
|
||||||
l2 = strlen(s);
|
l2 = strlen(s);
|
||||||
if (nonempty(pl)) {
|
if (nonempty(pl)) {
|
||||||
|
@ -450,14 +450,14 @@ strcatsub(char **d, char *pb, char *pe, char *src, int l, char *s, int glbsub,
|
||||||
if (!pl && (!s || !*s)) {
|
if (!pl && (!s || !*s)) {
|
||||||
*d = dest = (copied ? src : dupstring(src));
|
*d = dest = (copied ? src : dupstring(src));
|
||||||
if (glbsub)
|
if (glbsub)
|
||||||
tokenize(dest);
|
shtokenize(dest);
|
||||||
} else {
|
} else {
|
||||||
*d = dest = hcalloc(pl + l + (s ? strlen(s) : 0) + 1);
|
*d = dest = hcalloc(pl + l + (s ? strlen(s) : 0) + 1);
|
||||||
strncpy(dest, pb, pl);
|
strncpy(dest, pb, pl);
|
||||||
dest += pl;
|
dest += pl;
|
||||||
strcpy(dest, src);
|
strcpy(dest, src);
|
||||||
if (glbsub)
|
if (glbsub)
|
||||||
tokenize(dest);
|
shtokenize(dest);
|
||||||
dest += l;
|
dest += l;
|
||||||
if (s)
|
if (s)
|
||||||
strcpy(dest, s);
|
strcpy(dest, s);
|
||||||
|
@ -1595,7 +1595,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
|
||||||
if (!quoteerr) {
|
if (!quoteerr) {
|
||||||
errflag = oef;
|
errflag = oef;
|
||||||
if (haserr)
|
if (haserr)
|
||||||
tokenize(s);
|
shtokenize(s);
|
||||||
} else if (haserr || errflag) {
|
} else if (haserr || errflag) {
|
||||||
zerr("parse error in ${...%c...} substitution",
|
zerr("parse error in ${...%c...} substitution",
|
||||||
NULL, s[-1]);
|
NULL, s[-1]);
|
||||||
|
@ -2063,7 +2063,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
|
||||||
else {
|
else {
|
||||||
y = dupstring(x);
|
y = dupstring(x);
|
||||||
if (globsubst)
|
if (globsubst)
|
||||||
tokenize(y);
|
shtokenize(y);
|
||||||
}
|
}
|
||||||
insertlinknode(l, n, (void *) y), incnode(n);
|
insertlinknode(l, n, (void *) y), incnode(n);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue