mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-13 23:31:08 +02:00
zsh-workers/7823
This commit is contained in:
parent
08e9506f2f
commit
a854d7cd13
1 changed files with 75 additions and 18 deletions
|
@ -1946,7 +1946,7 @@ get_cline(char *l, int ll, char *w, int wl, char *o, int ol, int fl)
|
||||||
{
|
{
|
||||||
Cline r;
|
Cline r;
|
||||||
|
|
||||||
/* Preverably take it from the buffer list (freecl), if there
|
/* Prefer to take it from the buffer list (freecl), if there
|
||||||
* is none, allocate a new one. */
|
* is none, allocate a new one. */
|
||||||
|
|
||||||
if ((r = freecl))
|
if ((r = freecl))
|
||||||
|
@ -1981,6 +1981,28 @@ free_cline(Cline l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy a cline list. */
|
||||||
|
|
||||||
|
static Cline
|
||||||
|
cp_cline(Cline l)
|
||||||
|
{
|
||||||
|
Cline r = NULL, *p = &r, t;
|
||||||
|
|
||||||
|
while (l) {
|
||||||
|
if ((t = freecl))
|
||||||
|
freecl = t->next;
|
||||||
|
else
|
||||||
|
t = (Cline) zhalloc(sizeof(*t));
|
||||||
|
memcpy(t, l, sizeof(*t));
|
||||||
|
*p = t;
|
||||||
|
p = &(t->next);
|
||||||
|
l = l->next;
|
||||||
|
}
|
||||||
|
*p = NULL;
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/* This reverts the order of the elements of the given cline list and
|
/* This reverts the order of the elements of the given cline list and
|
||||||
* returns a pointer to the new head. */
|
* returns a pointer to the new head. */
|
||||||
|
|
||||||
|
@ -3365,6 +3387,50 @@ join_mid(Cline o, Cline n)
|
||||||
n->suffix = NULL;
|
n->suffix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This turns the sequence of anchor cline structs from b to e into a
|
||||||
|
* prefix sequence, puts it before the prefix of e and then tries to
|
||||||
|
* join that with the prefix of a.
|
||||||
|
* This is needed if some matches had a anchor match spec and others
|
||||||
|
* didn't. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
sub_join(Cline a, Cline b, Cline e, int anew)
|
||||||
|
{
|
||||||
|
if (!e->suffix && a->prefix) {
|
||||||
|
Cline op = e->prefix, n = NULL, *p = &n, t, ca;
|
||||||
|
|
||||||
|
for (; b != e; b = b->next) {
|
||||||
|
if ((*p = t = b->prefix)) {
|
||||||
|
while (t->next)
|
||||||
|
t = t->next;
|
||||||
|
p = &(t->next);
|
||||||
|
}
|
||||||
|
b->suffix = b->prefix = NULL;
|
||||||
|
b->flags &= ~CLF_SUF;
|
||||||
|
*p = b;
|
||||||
|
p = &(b->next);
|
||||||
|
}
|
||||||
|
*p = e->prefix;
|
||||||
|
ca = a->prefix;
|
||||||
|
|
||||||
|
while (n != op) {
|
||||||
|
e->prefix = cp_cline(n);
|
||||||
|
a->prefix = cp_cline(ca);
|
||||||
|
|
||||||
|
if (anew) {
|
||||||
|
join_psfx(e, a, NULL, NULL, 0);
|
||||||
|
if (e->prefix)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
join_psfx(e, a, NULL, NULL, 0);
|
||||||
|
if (a->prefix)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
n = n->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* This simplifies the cline list given as the first argument so that
|
/* This simplifies the cline list given as the first argument so that
|
||||||
* it also matches the second list. */
|
* it also matches the second list. */
|
||||||
|
|
||||||
|
@ -3388,11 +3454,7 @@ join_clines(Cline o, Cline n)
|
||||||
|
|
||||||
for (t = o; (tn = t->next) && (tn->flags & CLF_NEW); t = tn);
|
for (t = o; (tn = t->next) && (tn->flags & CLF_NEW); t = tn);
|
||||||
if (tn && cmp_anchors(tn, n, 0)) {
|
if (tn && cmp_anchors(tn, n, 0)) {
|
||||||
Cline tmp;
|
sub_join(n, o, tn, 1);
|
||||||
|
|
||||||
tmp = o->prefix;
|
|
||||||
o->prefix = tn->prefix;
|
|
||||||
tn->prefix = tmp;
|
|
||||||
|
|
||||||
if (po)
|
if (po)
|
||||||
po->next = tn;
|
po->next = tn;
|
||||||
|
@ -3410,11 +3472,7 @@ join_clines(Cline o, Cline n)
|
||||||
|
|
||||||
for (t = n; (tn = t->next) && (tn->flags & CLF_NEW); t = tn);
|
for (t = n; (tn = t->next) && (tn->flags & CLF_NEW); t = tn);
|
||||||
if (tn && cmp_anchors(o, tn, 0)) {
|
if (tn && cmp_anchors(o, tn, 0)) {
|
||||||
Cline tmp;
|
sub_join(o, n, tn, 0);
|
||||||
|
|
||||||
tmp = n->prefix;
|
|
||||||
n->prefix = tn->prefix;
|
|
||||||
tn->prefix = tmp;
|
|
||||||
|
|
||||||
n = tn;
|
n = tn;
|
||||||
o->flags |= CLF_MISS;
|
o->flags |= CLF_MISS;
|
||||||
|
@ -3433,10 +3491,8 @@ join_clines(Cline o, Cline n)
|
||||||
(o->flags & (CLF_SUF | CLF_MID));
|
(o->flags & (CLF_SUF | CLF_MID));
|
||||||
t = tn);
|
t = tn);
|
||||||
if (tn && cmp_anchors(o, tn, 1)) {
|
if (tn && cmp_anchors(o, tn, 1)) {
|
||||||
Cline t;
|
sub_join(o, n, tn, 0);
|
||||||
|
|
||||||
t = tn->prefix; tn->prefix = n->prefix; n->prefix = t;
|
|
||||||
t = tn->suffix; tn->suffix = n->suffix; n->suffix = t;
|
|
||||||
n = tn;
|
n = tn;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3446,6 +3502,7 @@ join_clines(Cline o, Cline n)
|
||||||
(n->flags & (CLF_SUF | CLF_MID));
|
(n->flags & (CLF_SUF | CLF_MID));
|
||||||
t = tn);
|
t = tn);
|
||||||
if (tn && cmp_anchors(tn, n, 1)) {
|
if (tn && cmp_anchors(tn, n, 1)) {
|
||||||
|
sub_join(n, o, tn, 1);
|
||||||
if (po)
|
if (po)
|
||||||
po->next = tn;
|
po->next = tn;
|
||||||
else
|
else
|
||||||
|
@ -3474,8 +3531,8 @@ join_clines(Cline o, Cline n)
|
||||||
for (t = n; (tn = t->next) && !cmp_anchors(o, tn, 1); t = tn);
|
for (t = n; (tn = t->next) && !cmp_anchors(o, tn, 1); t = tn);
|
||||||
|
|
||||||
if (tn) {
|
if (tn) {
|
||||||
t = tn->prefix; tn->prefix = n->prefix; n->prefix = t;
|
sub_join(o, n, tn, 0);
|
||||||
t = tn->suffix; tn->suffix = n->suffix; n->suffix = t;
|
|
||||||
n = tn;
|
n = tn;
|
||||||
o->flags |= CLF_MISS;
|
o->flags |= CLF_MISS;
|
||||||
continue;
|
continue;
|
||||||
|
@ -3484,8 +3541,8 @@ join_clines(Cline o, Cline n)
|
||||||
t = tn);
|
t = tn);
|
||||||
|
|
||||||
if (tn) {
|
if (tn) {
|
||||||
t = tn->prefix; tn->prefix = o->prefix; o->prefix = t;
|
sub_join(n, o, tn, 1);
|
||||||
t = tn->suffix; tn->suffix = o->suffix; o->suffix = t;
|
|
||||||
if (po)
|
if (po)
|
||||||
po->next = tn;
|
po->next = tn;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue