From 05d3c175a5f9d1eb7bd8ed5f9c36ff5838ee6b8e Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Wed, 17 May 2000 11:59:32 +0000 Subject: add Felix' completion matching test; some fixes for bugs shown by it (11439) --- Src/Zle/comp.h | 1 + Src/Zle/compcore.c | 90 +++++++++++++++++++++++++++-------------------------- Src/Zle/compmatch.c | 20 +++++++----- 3 files changed, 59 insertions(+), 52 deletions(-) (limited to 'Src') diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index 3b49b2c25..bd0401800 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -196,6 +196,7 @@ struct cline { #define CLF_LINE 32 #define CLF_JOIN 64 #define CLF_MATCHED 128 +#define CLF_SKIP 256 /* Information for ambiguous completions. One for fignore ignored and * * one for normal completion. */ diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 60f73c635..1b16870d1 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1740,55 +1740,57 @@ addmatches(Cadata dat, char **argv) llpl -= gfl; } } - s = dat->ppre ? dat->ppre : dupstring(""); - if ((ml = match_str(lpre, s, &bpl, 0, NULL, 0, 0, 1)) >= 0) { - if (matchsubs) { - Cline tmp = get_cline(NULL, 0, NULL, 0, NULL, 0, 0); - - tmp->prefix = matchsubs; - if (matchlastpart) - matchlastpart->next = tmp; + if ((s = dat->ppre)) { + if ((ml = match_str(lpre, s, &bpl, 0, NULL, 0, 0, 1)) >= 0) { + if (matchsubs) { + Cline tmp = get_cline(NULL, 0, NULL, 0, NULL, 0, 0); + + tmp->prefix = matchsubs; + if (matchlastpart) + matchlastpart->next = tmp; + else + matchparts = tmp; + } + pline = matchparts; + lpre += ml; + llpl -= ml; + bcp = ml; + bpadd = strlen(s) - ml; + } else { + if (llpl <= lpl && strpfx(lpre, s)) + lpre = dupstring(""); + else if (llpl > lpl && strpfx(s, lpre)) + lpre += lpl; else - matchparts = tmp; + *argv = NULL; + bcp = lpl; } - pline = matchparts; - lpre += ml; - llpl -= ml; - bcp = ml; - bpadd = strlen(s) - ml; - } else { - if (llpl <= lpl && strpfx(lpre, s)) - lpre = dupstring(""); - else if (llpl > lpl && strpfx(s, lpre)) - lpre += lpl; - else - *argv = NULL; - bcp = lpl; } - s = dat->psuf ? dat->psuf : dupstring(""); - if ((ml = match_str(lsuf, s, &bsl, 0, NULL, 1, 0, 1)) >= 0) { - if (matchsubs) { - Cline tmp = get_cline(NULL, 0, NULL, 0, NULL, 0, CLF_SUF); - - tmp->suffix = matchsubs; - if (matchlastpart) - matchlastpart->next = tmp; + if ((s = dat->psuf)) { + if ((ml = match_str(lsuf, s, &bsl, 0, NULL, 1, 0, 1)) >= 0) { + if (matchsubs) { + Cline tmp = get_cline(NULL, 0, NULL, 0, NULL, 0, CLF_SUF); + + tmp->suffix = matchsubs; + if (matchlastpart) + matchlastpart->next = tmp; + else + matchparts = tmp; + } + sline = revert_cline(matchparts); + lsuf[llsl - ml] = '\0'; + llsl -= ml; + bcs = ml; + bsadd = strlen(s) - ml; + } else { + if (llsl <= lsl && strsfx(lsuf, s)) + lsuf = dupstring(""); + else if (llsl > lsl && strsfx(s, lsuf)) + lsuf[llsl - lsl] = '\0'; else - matchparts = tmp; + *argv = NULL; + bcs = lsl; } - sline = revert_cline(matchparts); - lsuf[llsl - ml] = '\0'; - llsl -= ml; - bcs = ml; - bsadd = strlen(s) - ml; - } else { - if (llsl <= lsl && strsfx(lsuf, s)) - lsuf = dupstring(""); - else if (llsl > lsl && strsfx(s, lsuf)) - lsuf[llsl - lsl] = '\0'; - else - *argv = NULL; - bcs = lsl; } if (comppatmatch && *comppatmatch) { int is = (*comppatmatch == '*'); diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c index 3a9ea6a40..884946b97 100644 --- a/Src/Zle/compmatch.c +++ b/Src/Zle/compmatch.c @@ -411,7 +411,8 @@ add_match_sub(Cmatcher m, char *l, int ll, char *w, int wl) /* And add the cline. */ if (wl || ll) { - n = get_cline(l, ll, w, wl, NULL, 0, flags); + n = get_cline(l, ll, w, wl, NULL, 0, + flags | ((m && m->wlen == -2) ? CLF_SKIP : 0)); if (matchlastsub) matchlastsub->next = n; else @@ -1925,9 +1926,9 @@ join_clines(Cline o, Cline n) Cline t, tn, tt, to = NULL; for (t = n; (tn = t->next); t = tn) - if (!(tn->flags & CLF_NEW)) { + if (!(tn->flags & CLF_NEW) && (tn->flags & CLF_SKIP)) { for (tt = o; (to = tt->next); tt = to) - if (!(to->flags & CLF_NEW) && + if (!(to->flags & CLF_NEW) && (to->flags & CLF_SKIP) && cmp_anchors(tn, to, 1)) break; if (to) @@ -1953,8 +1954,9 @@ join_clines(Cline o, Cline n) n = n->next; continue; } else { - for (t = o; (to = t->next) && !cmp_anchors(n, to, 1); - t = to); + for (t = o; (to = t->next); t = to) + if ((to->flags & CLF_SKIP) && cmp_anchors(n, to, 1)) + break; if (to) { diff = sub_join(n, o, to, 1); @@ -1975,9 +1977,11 @@ join_clines(Cline o, Cline n) continue; } else { for (tt = NULL, t = n; (tn = t->next); t = tn) { - for (tt = o; - (to = tt->next) && - !cmp_anchors(tn, to, 1); tt = to); + if (tn->flags & CLF_SKIP) + for (tt = o; (to = tt->next); tt = to) + if ((to->flags & CLF_SKIP) && + cmp_anchors(tn, to, 1)) + break; if (to) break; } -- cgit 1.4.1