From 11ecfb4d94d6aa5dc42156a5e1c57b8d0bfc0223 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Tue, 14 Sep 1999 14:55:37 +0000 Subject: zsh-workers/7827 --- Src/Zle/comp.h | 18 +++++---- Src/Zle/compctl.c | 23 ++++++++--- Src/Zle/complist.c | 69 ++++++++++++++++++++++++++++----- Src/Zle/zle_tricky.c | 106 ++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 167 insertions(+), 49 deletions(-) (limited to 'Src/Zle') diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index 034410f3a..f27326a02 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -184,6 +184,7 @@ struct cmgroup { int mcount; /* number of matches */ Cmatch *matches; /* the matches */ int lcount; /* number of things to list here */ + int llcount; /* number of line-displays */ char **ylist; /* things to list */ int ecount; /* number of explanation string */ Cexpl *expls; /* explanation strings */ @@ -199,6 +200,7 @@ struct cmgroup { #define CGF_NOSORT 1 /* don't sort this group */ #define CGF_LINES 2 /* these are to be printed on different lines */ +#define CGF_HASDL 4 /* has disply strings printed on sseparate lines */ /* This is the struct used to hold matches. */ @@ -212,6 +214,7 @@ struct cmatch { char *prpre; /* path prefix for opendir */ char *pre; /* prefix string from -P */ char *suf; /* suffix string from -S */ + char *disp; /* string to display (compadd -d) */ char autoq; /* closing quote to add automatically */ int flags; /* see CMF_* below */ int brpl; /* the place where to put the brace prefix */ @@ -224,13 +227,13 @@ struct cmatch { int gnum; /* global number */ }; -#define CMF_FILE 1 /* this is a file */ -#define CMF_REMOVE 2 /* remove the suffix */ -#define CMF_ISPAR 4 /* is paramter expansion */ -#define CMF_PARBR 8 /* paramter expansion with a brace */ -#define CMF_PARNEST 16 /* nested paramter expansion */ -#define CMF_NOLIST 32 /* should not be listed */ - +#define CMF_FILE 1 /* this is a file */ +#define CMF_REMOVE 2 /* remove the suffix */ +#define CMF_ISPAR 4 /* is paramter expansion */ +#define CMF_PARBR 8 /* paramter expansion with a brace */ +#define CMF_PARNEST 16 /* nested paramter expansion */ +#define CMF_NOLIST 32 /* should not be listed */ +#define CMF_DISPLINE 64 /* display strings one per line */ /* Stuff for completion matcher control. */ @@ -315,6 +318,7 @@ struct cadata { char *apar; /* array to store matches in (-A) */ char *opar; /* array to store originals in (-O) */ char *dpar; /* array to delete non-matches in (-D) */ + char *disp; /* array with display lists (-d) */ }; /* Data given to hooks. */ diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 942a289f6..50cdadf26 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -230,18 +230,24 @@ parse_cmatcher(char *name, char *s) &err); if (err) return pcm_err; - if (!*s || !*++s) { - zwarnnam(name, ((fl & CMF_RIGHT) ? "missing right anchor" : "missing word pattern"), NULL, 0); - return pcm_err; + if ((fl & CMF_RIGHT) && (!*s || !*++s)) { + zwarnnam(name, "missing right anchor", NULL, 0); + } else if (!(fl & CMF_RIGHT)) { + if (!*s) { + zwarnnam(name, "missing word pattern", NULL, 0); + return pcm_err; + } + s++; } if (fl & CMF_RIGHT) { right = parse_pattern(name, &s, &ral, '=', &err); if (err) return pcm_err; - if (!*s || !*++s) { + if (!*s) { zwarnnam(name, "missing word pattern", NULL, 0); return pcm_err; } + s++; } else right = NULL; @@ -1726,7 +1732,7 @@ bin_compadd(char *name, char **argv, char *ops, int func) return 1; } dat.ipre = dat.isuf = dat.ppre = dat.psuf = dat.prpre = - dat.pre = dat.suf = dat.group = dat.rems = dat.remf = + dat.pre = dat.suf = dat.group = dat.rems = dat.remf = dat.disp = dat.ign = dat.exp = dat.apar = dat.opar = dat.dpar = dat.ylist = NULL; dat.match = NULL; dat.flags = 0; @@ -1840,6 +1846,13 @@ bin_compadd(char *name, char **argv, char *ops, int func) sp = &(dat.dpar); e = "parameter name expected after -%c"; break; + case 'd': + sp = &(dat.disp); + e = "parameter name expected after -%c"; + break; + case 'l': + dat.flags |= CMF_DISPLINE; + break; case '-': argv++; goto ca_args; diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index a1835655d..913a5e592 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -371,7 +371,14 @@ complistmatches(Hookdef dummy, Chdata dat) } } else { for (p = g->matches; (m = *p); p++) { - if (!(m->flags & CMF_NOLIST)) { + if (m->disp) { + if (m->flags & CMF_DISPLINE) { + nlines += 1 + printfmt(m->disp, 0, 0, 0); + g->flags |= CGF_HASDL; + } else if ((l = strlen(m->disp)) > longest) + longest = l; + nlist++; + } else if (!(m->flags & CMF_NOLIST)) { if ((l = niceztrlen(m->str)) > longest) longest = l; nlist++; @@ -382,7 +389,7 @@ complistmatches(Hookdef dummy, Chdata dat) if ((e = g->expls)) { while (*e) { if ((*e)->count) - nlines += 1 + printfmt((*e)->str, (*e)->count, 0); + nlines += 1 + printfmt((*e)->str, (*e)->count, 0, 1); e++; } } @@ -390,7 +397,7 @@ complistmatches(Hookdef dummy, Chdata dat) longest += 2 + of; if ((ncols = (columns + 1) / longest)) { for (g = amatches; g; g = g->next) - nlines += (g->lcount + ncols - 1) / ncols; + nlines += (g->lcount - g->llcount + ncols - 1) / ncols; } else { ncols = 1; opl = 1; @@ -406,7 +413,12 @@ complistmatches(Hookdef dummy, Chdata dat) } } else for (p = g->matches; (m = *p); p++) - if (!(m->flags & CMF_NOLIST)) + if (m->disp) { + if (m->flags & CMF_DISPLINE) + nlines += 1 + printfmt(m->disp, 0, 0, 0); + else + nlines += 1 + ((1 + niceztrlen(m->disp)) / columns); + } else if (!(m->flags & CMF_NOLIST)) nlines += 1 + ((1 + niceztrlen(m->str)) / columns); } } @@ -430,7 +442,7 @@ complistmatches(Hookdef dummy, Chdata dat) (!complistmax && nlines >= lines))) { int qup; zsetterm(); - qup = printfmt("zsh: do you wish to see all %n possibilities? ", nlist, 1); + qup = printfmt("zsh: do you wish to see all %n possibilities? ", nlist, 1, 1); fflush(shout); if (getzlequery() != 'y') { if (clearflag) { @@ -496,7 +508,7 @@ complistmatches(Hookdef dummy, Chdata dat) tcout(TCCLEAREOD); } } - l = printfmt((*e)->str, (*e)->count, 1); + l = printfmt((*e)->str, (*e)->count, 1, 1); ml += l; if (cl >= 0 && (cl -= l) <= 1) { cl = -1; @@ -558,10 +570,47 @@ complistmatches(Hookdef dummy, Chdata dat) } } } else if (g->lcount) { - int n = g->lcount, nl = (n + ncols - 1) / ncols, nc = nl, i, j, a = 0; + int n = g->lcount - g->llcount, nl = (n + ncols - 1) / ncols; + int nc = nl, i, j, a = 0; int zt; Cmatch *q; + if (g->flags & CGF_HASDL) { + for (p = g->matches; (m = *p); p++) + if (m->disp && (m->flags & CMF_DISPLINE)) { + if (pnl) { + putc('\n', shout); + pnl = 0; + ml++; + if (cl >= 0 && --cl <= 1) { + cl = -1; + if (tccan(TCCLEAREOD)) + tcout(TCCLEAREOD); + } + } + hasm = 1; + if (mselect >= 0) { + for (i = 0; i < ncols; i++) { + mtab[i + (ncols * ml)] = p; + mgtab[i + (ncols * ml)] = g; + } + } + if (m->gnum == mselect) { + mline = ml; + mmatch = p; + mgroup = g; + cc = COL_MA; + } else + cc = COL_NO; + zcputs(&col, cc); + printfmt(m->disp, 0, 1, 0); + if (col.cols[COL_EC]) + tputs(col.cols[COL_EC], 1, putshout); + else + zcputs(&col, COL_NO); + pnl = 1; + } + } if (n && pnl) { putc('\n', shout); pnl = 0; @@ -601,7 +650,7 @@ complistmatches(Hookdef dummy, Chdata dat) cc = COL_MA; } else cc = -1; - if (m->flags & CMF_FILE) { + if (!m->disp && m->flags & CMF_FILE) { struct stat buf; char *pb; @@ -624,11 +673,11 @@ complistmatches(Hookdef dummy, Chdata dat) putc(file_type(buf.st_mode), shout); } else { zcputs(&col, cc >= 0 ? cc : COL_NO); - nicezputs(m->str, shout); + nicezputs((m->disp ? m->disp : m->str), shout); if (of) putc(' ', shout); } - a = longest - niceztrlen(m->str) - 2 - of; + a = longest - niceztrlen(m->disp ? m->disp : m->str) - 2 - of; while (a--) putc(' ', shout); if (col.cols[COL_EC]) diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 594ada91d..ecbfc123e 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -3778,7 +3778,7 @@ add_match_data(int alt, char *str, Cline line, cm->qipl = qipl; cm->qisl = qisl; cm->autoq = (autoq ? autoq : (inbackt ? '`' : '\0')); - cm->rems = cm->remf = NULL; + cm->rems = cm->remf = cm->disp = NULL; addlinknode((alt ? fmatches : matches), cm); /* One more match for this explanation. */ @@ -3853,7 +3853,7 @@ addmatches(Cadata dat, char **argv) { char *s, *ms, *lipre = NULL, *lisuf = NULL, *lpre = NULL, *lsuf = NULL; char **aign = NULL, **dparr = NULL, oaq = autoq, *oppre = dat->ppre; - char *oqp = qipre, *oqs = qisuf, qc; + char *oqp = qipre, *oqs = qisuf, qc, **disp = NULL; int lpl, lsl, pl, sl, bpl, bsl, llpl = 0, llsl = 0, nm = mnum; int oisalt = 0, isalt, isexact, doadd, ois = instring, oib = inbackt; Cline lc = NULL; @@ -3923,6 +3923,9 @@ addmatches(Cadata dat, char **argv) /* Get the suffixes to ignore. */ if (dat->ign) aign = get_user_var(dat->ign); + /* Get the display strings. */ + if (dat->disp) + disp = get_user_var(dat->disp) - 1; /* Get the contents of the completion variables if we have * to perform matching. */ if (dat->aflags & CAF_MATCH) { @@ -4041,6 +4044,10 @@ addmatches(Cadata dat, char **argv) } /* Walk through the matches given. */ for (; (s = *argv); argv++) { + if (disp) { + if (!*++disp) + disp = NULL; + } sl = strlen(s); bpl = brpl; bsl = brsl; @@ -4085,6 +4092,8 @@ addmatches(Cadata dat, char **argv) bpl, bsl, dat->flags, isexact); cm->rems = dat->rems; cm->remf = dat->remf; + if (disp) + cm->disp = dupstring(*disp); } else { if (dat->apar) addlinknode(aparl, ms); @@ -4647,7 +4656,7 @@ docompletion(char *s, int lst, int incmd) up++; putc('\n', shout); } - up += printfmt((*e)->str, (*e)->count, 1); + up += printfmt((*e)->str, (*e)->count, 1, 1); nn = 1; } e++; @@ -5076,7 +5085,7 @@ makecomplist(char *s, int incmd, int lst) if (amatches && !oldlist) amatches->ccs = (Compctl *) makearray(ccused, 0, - &(amatches->ccount), NULL); + &(amatches->ccount), NULL, NULL); else { LinkNode n; @@ -7001,6 +7010,14 @@ strbpcmp(char **aa, char **bb) static int matchcmp(Cmatch *a, Cmatch *b) { + if ((*a)->disp) { + if ((*b)->disp) + return strcmp((*a)->disp, (*b)->disp); + return -1; + } + if ((*b)->disp) + return 1; + return strbpcmp(&((*a)->str), &((*b)->str)); } @@ -7015,9 +7032,9 @@ matcheq(Cmatch a, Cmatch b) return matchstreq(a->ipre, b->ipre) && matchstreq(a->pre, b->pre) && matchstreq(a->ppre, b->ppre) && - matchstreq(a->str, b->str) && matchstreq(a->psuf, b->psuf) && - matchstreq(a->suf, b->suf); + matchstreq(a->suf, b->suf) && + !a->disp && !b->disp && matchstreq(a->str, b->str); } /* Make an array from a linked list. The second argument says whether * @@ -7027,11 +7044,11 @@ matcheq(Cmatch a, Cmatch b) /**/ static Cmatch * -makearray(LinkList l, int s, int *np, int *nlp) +makearray(LinkList l, int s, int *np, int *nlp, int *llp) { Cmatch *ap, *bp, *cp, *rp; LinkNode nod; - int n, nl = 0; + int n, nl = 0, ll = 0; /* Build an array for the matches. */ rp = ap = (Cmatch *) ncalloc(((n = countlinknodes(l)) + 1) * @@ -7067,21 +7084,30 @@ makearray(LinkList l, int s, int *np, int *nlp) for (bp = ap; bp[1] && matcheq(*ap, bp[1]); bp++, n--); ap = bp; /* Mark those, that would show the same string in the list. */ - for (; bp[1] && !strcmp((*ap)->str, (bp[1])->str); bp++) + for (; bp[1] && !(*ap)->disp && !(bp[1])->disp && + !strcmp((*ap)->str, (bp[1])->str); bp++) (bp[1])->flags |= CMF_NOLIST; } - for (ap = rp; *ap; ap++) + for (ap = rp; *ap; ap++) { + if ((*ap)->disp && ((*ap)->flags & CMF_DISPLINE)) + ll++; if ((*ap)->flags & CMF_NOLIST) nl++; + } *cp = NULL; } else - for (ap = rp; *ap; ap++) + for (ap = rp; *ap; ap++) { + if ((*ap)->disp && ((*ap)->flags & CMF_DISPLINE)) + ll++; if ((*ap)->flags & CMF_NOLIST) nl++; + } if (np) *np = n; if (nlp) *nlp = nl; + if (llp) + *llp = ll; return rp; } @@ -7111,7 +7137,7 @@ begcmgroup(char *n, int nu) } mgroup = (Cmgroup) zhalloc(sizeof(struct cmgroup)); mgroup->name = dupstring(n); - mgroup->flags = mgroup->lcount = mgroup->mcount = 0; + mgroup->flags = mgroup->lcount = mgroup->llcount = mgroup->mcount = 0; mgroup->matches = NULL; mgroup->ylist = NULL; mgroup->expls = NULL; @@ -7183,6 +7209,7 @@ dupmatch(Cmatch m) r->autoq = m->autoq; r->qipl = m->qipl; r->qisl = m->qisl; + r->disp = dupstring(m->disp); return r; } @@ -7197,7 +7224,7 @@ permmatches(void) Cmatch *p, *q; Cexpl *ep, *eq, e, o; Compctl *cp, *cq; - int nn, nl, fi = 0, gn = 1, mn = 1, rn; + int nn, nl, ll, fi = 0, gn = 1, mn = 1, rn; if (hasperm) freematches(); @@ -7217,15 +7244,17 @@ permmatches(void) g->matches = makearray(g->lmatches, ((g->flags & CGF_NOSORT) ? 0 : 2), - &nn, &nl); + &nn, &nl, &ll); g->mcount = nn; if ((g->lcount = nn - nl) < 0) g->lcount = 0; + g->llcount = ll; if (g->ylist) { g->lcount = arrlen(g->ylist); smatches = 2; } - g->expls = (Cexpl *) makearray(g->lexpls, 0, &(g->ecount), NULL); + g->expls = (Cexpl *) makearray(g->lexpls, 0, &(g->ecount), + NULL, NULL); g->ccount = 0; g->ccs = NULL; @@ -7254,6 +7283,7 @@ permmatches(void) *p = NULL; n->lcount = g->lcount; + n->llcount = g->llcount; if (g->ylist) n->ylist = arrdup(g->ylist); else @@ -7312,6 +7342,7 @@ freematch(Cmatch m) zsfree(m->prpre); zsfree(m->rems); zsfree(m->remf); + zsfree(m->disp); zfree(m, sizeof(m)); } @@ -8094,14 +8125,14 @@ sfxlen(char *s, char *t) /**/ int -printfmt(char *fmt, int n, int dopr) +printfmt(char *fmt, int n, int dopr, int doesc) { char *p = fmt, nc[DIGBUFSIZE]; int l = 0, cc = 0, b = 0, s = 0, u = 0, m; for (; *p; p++) { /* Handle the `%' stuff (%% == %, %n == ). */ - if (*p == '%') { + if (doesc && *p == '%') { if (*++p) { m = 0; switch (*p) { @@ -8180,7 +8211,8 @@ printfmt(char *fmt, int n, int dopr) Cmatch * skipnolist(Cmatch *p) { - while (*p && ((*p)->flags & CMF_NOLIST)) + while (*p && (((*p)->flags & CMF_NOLIST) || + ((*p)->disp && ((*p)->flags & CMF_DISPLINE)))) p++; return p; @@ -8255,7 +8287,14 @@ ilistmatches(Hookdef dummy, Chdata dat) } } else { for (p = g->matches; (m = *p); p++) { - if (!(m->flags & CMF_NOLIST)) { + if (m->disp) { + if (m->flags & CMF_DISPLINE) { + nlines += 1 + printfmt(m->disp, 0, 0, 0); + g->flags |= CGF_HASDL; + } else if ((l = strlen(m->disp)) > longest) + longest = l; + nlist++; + } else if (!(m->flags & CMF_NOLIST)) { if ((l = niceztrlen(m->str)) > longest) longest = l; nlist++; @@ -8265,7 +8304,7 @@ ilistmatches(Hookdef dummy, Chdata dat) if ((e = g->expls)) { while (*e) { if ((*e)->count) - nlines += 1 + printfmt((*e)->str, (*e)->count, 0); + nlines += 1 + printfmt((*e)->str, (*e)->count, 0, 1); e++; } } @@ -8310,7 +8349,8 @@ ilistmatches(Hookdef dummy, Chdata dat) (!complistmax && nlines >= lines))) { int qup; zsetterm(); - qup = printfmt("zsh: do you wish to see all %n possibilities? ", nlist, 1); + qup = printfmt("zsh: do you wish to see all %n possibilities? ", + nlist, 1, 1); fflush(shout); if (getzlequery() != 'y') { if (clearflag) { @@ -8349,7 +8389,7 @@ ilistmatches(Hookdef dummy, Chdata dat) putc('\n', shout); pnl = 0; } - printfmt((*e)->str, (*e)->count, 1); + printfmt((*e)->str, (*e)->count, 1, 1); pnl = 1; } e++; @@ -8391,9 +8431,21 @@ ilistmatches(Hookdef dummy, Chdata dat) } } } else if (g->lcount) { - int n = g->lcount, nl = (n + ncols - 1) / ncols, nc = nl, i, j, a = 0; + int n = g->lcount - g->llcount, nl = (n + ncols - 1) / ncols; + int nc = nl, i, j, a = 0; Cmatch *q; + if (g->flags & CGF_HASDL) { + for (p = g->matches; (m = *p); p++) + if (m->disp && (m->flags & CMF_DISPLINE)) { + if (pnl) { + putc('\n', shout); + pnl = 0; + } + printfmt(m->disp, 0, 1, 0); + pnl = 1; + } + } if (n && pnl) { putc('\n', shout); pnl = 0; @@ -8404,11 +8456,11 @@ ilistmatches(Hookdef dummy, Chdata dat) while (n && i--) { if (!(m = *q)) break; - nicezputs(m->str, shout); + nicezputs((m->disp ? m->disp : m->str), shout); if (i) - a = longest - niceztrlen(m->str); + a = longest - niceztrlen(m->disp ? m->disp : m->str); - if (of && m->flags & CMF_FILE) { + if (of && !m->disp && m->flags & CMF_FILE) { struct stat buf; char *pb; @@ -8475,7 +8527,7 @@ listlist(LinkList l) smatches = 1; validlist = 1; memset(&dg, 0, sizeof(struct cmgroup)); - dg.ylist = (char **) makearray(l, 1, &(dg.lcount), NULL); + dg.ylist = (char **) makearray(l, 1, &(dg.lcount), NULL, NULL); amatches = &dg; ilistmatches(NULL, NULL); amatches = am; -- cgit 1.4.1