about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/Zle/comp.h6
-rw-r--r--Src/Zle/compcore.c26
-rw-r--r--Src/Zle/compctl.c2
-rw-r--r--Src/Zle/complist.c36
-rw-r--r--Src/Zle/compresult.c87
6 files changed, 80 insertions, 82 deletions
diff --git a/ChangeLog b/ChangeLog
index 76a4d6d8e..985095b1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2002-05-21  Sven Wischnowsky  <wischnow@zsh.org>
 
+	* 17195: Src/Zle/comp.h, Src/Zle/compcore.c, Src/Zle/compctl.c,
+	Src/Zle/complist.c, Src/Zle/compresult.c: fix for
+	file-type-tests in nested quotes and don't count space
+	file-type-character
+
 	* 17194: Src/Zle/computil.c: improve calculation of used
 	columns for match-max-length
 
diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h
index 20bfb0f99..5e25cdeb6 100644
--- a/Src/Zle/comp.h
+++ b/Src/Zle/comp.h
@@ -92,6 +92,7 @@ struct cmgroup {
 
 struct cmatch {
     char *str;			/* the match itself */
+    char *orig;                 /* the match string unquoted */
     char *ipre;			/* ignored prefix, has to be re-inserted */
     char *ripre;		/* ignored prefix, unquoted */
     char *isuf;			/* ignored suffix */
@@ -111,6 +112,8 @@ struct cmatch {
     int qisl;			/* length of quote-suffix */
     int rnum;			/* group relative number */
     int gnum;			/* global number */
+    mode_t mode;                /* mode field of a stat */
+    char modec;                 /* LIST_TYPE-character for mode or nul */
 };
 
 #define CMF_FILE     (1<< 0)	/* this is a file */
@@ -286,8 +289,7 @@ struct cldata {
     int showall;		/* != 0 if hidden matches should be shown */
 };
 
-typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int,
-			    char *, struct stat *);
+typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int);
 
 /* Flags for fromcomp. */
 
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 851ef0ef5..0f15a4a88 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -2104,7 +2104,7 @@ addmatches(Cadata dat, char **argv)
 		for (bp = obsl; bp; bp = bp->next)
 		    bp->curpos += bsadd;
 
-		if ((cm = add_match_data(0, ms, lc, dat->ipre, NULL,
+		if ((cm = add_match_data(0, ms, s, lc, dat->ipre, NULL,
 					 dat->isuf, dat->pre, dat->prpre,
 					 dat->ppre, pline,
 					 dat->psuf, sline,
@@ -2184,7 +2184,7 @@ addmatches(Cadata dat, char **argv)
 
 /**/
 mod_export Cmatch
-add_match_data(int alt, char *str, Cline line,
+add_match_data(int alt, char *str, char *orig, Cline line,
 	       char *ipre, char *ripre, char *isuf,
 	       char *pre, char *prpre,
 	       char *ppre, Cline pline,
@@ -2412,6 +2412,7 @@ add_match_data(int alt, char *str, Cline line,
     /* Allocate and fill the match structure. */
     cm = (Cmatch) zhalloc(sizeof(struct cmatch));
     cm->str = str;
+    cm->orig = dupstring(orig);
     cm->ppre = (ppre && *ppre ? ppre : NULL);
     cm->psuf = (psuf && *psuf ? psuf : NULL);
     cm->prpre = ((flags & CMF_FILE) && prpre && *prpre ? prpre : NULL);
@@ -2430,7 +2431,22 @@ add_match_data(int alt, char *str, Cline line,
 		 (complist ?
 		  ((strstr(complist, "packed") ? CMF_PACKED : 0) |
 		   (strstr(complist, "rows")   ? CMF_ROWS   : 0)) : 0));
-
+    cm->mode = 0;
+    cm->modec = '\0';
+    if ((flags & CMF_FILE) && orig[0] && orig[strlen(orig) - 1] != '/') {
+        struct stat buf;
+        char *pb;
+
+        pb = (char *) zhalloc((cm->prpre ? strlen(cm->prpre) : 0) +
+                              3 + strlen(orig));
+        sprintf(pb, "%s%s", (cm->prpre ? cm->prpre : "./"), orig);
+
+        if (!ztat(pb, &buf, 1)) {
+            cm->mode = buf.st_mode;
+            if ((cm->modec = file_type(buf.st_mode)) == ' ')
+                cm->modec = '\0';
+        }
+    }
     if ((*compqstack == '\\' && compqstack[1]) ||
 	(autoq && *compqstack && compqstack[1] == '\\'))
 	cm->flags |= CMF_NOSPACE;
@@ -2803,6 +2819,7 @@ dupmatch(Cmatch m, int nbeg, int nend)
     r = (Cmatch) zcalloc(sizeof(struct cmatch));
 
     r->str = ztrdup(m->str);
+    r->orig = ztrdup(m->orig);
     r->ipre = ztrdup(m->ipre);
     r->ripre = ztrdup(m->ripre);
     r->isuf = ztrdup(m->isuf);
@@ -2836,6 +2853,8 @@ dupmatch(Cmatch m, int nbeg, int nend)
     r->qipl = m->qipl;
     r->qisl = m->qisl;
     r->disp = ztrdup(m->disp);
+    r->mode = m->mode;
+    r->modec = m->modec;
 
     return r;
 }
@@ -2994,6 +3013,7 @@ freematch(Cmatch m, int nbeg, int nend)
     if (!m) return;
 
     zsfree(m->str);
+    zsfree(m->orig);
     zsfree(m->ipre);
     zsfree(m->ripre);
     zsfree(m->isuf);
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index cc0aebf04..a84f604cc 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -2025,7 +2025,7 @@ addmatch(char *s, char *t)
     }
     if (!ms)
 	return;
-    add_match_data(isalt, ms, lc, ipre, ripre, isuf, 
+    add_match_data(isalt, ms, s, lc, ipre, ripre, isuf, 
 		   (incompfunc ? dupstring(curcc->prefix) : curcc->prefix),
 		   prpre, 
 		   (isfile ? lppre : NULL), NULL,
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index e38ffe33b..0278f5c44 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -1199,7 +1199,7 @@ compprintlist(int showall)
 			    mfirstl = ml;
 			if (dolist(ml))
 			    printed++;
-			if (clprintm(g, p, 0, ml, 1, 0, NULL, NULL))
+			if (clprintm(g, p, 0, ml, 1, 0))
 			    goto end;
 			ml += mlprinted;
 			if (dolistcl(ml) && (cl -= mlprinted) <= 1) {
@@ -1250,26 +1250,12 @@ compprintlist(int showall)
 		while (n && i--) {
 		    wid = (g->widths ? g->widths[mc] : g->width);
 		    if (!(m = *q)) {
-			if (clprintm(g, NULL, mc, ml, (!i), wid, NULL, NULL))
+			if (clprintm(g, NULL, mc, ml, (!i), wid))
 			    goto end;
 			break;
 		    }
-		    if (!m->disp && (m->flags & CMF_FILE) &&
-			m->str[0] && m->str[strlen(m->str) - 1] != '/') {
-			struct stat buf;
-			char *pb;
-
-			pb = (char *) zhalloc((m->prpre ? strlen(m->prpre) : 0) +
-					     3 + strlen(m->str));
-			sprintf(pb, "%s%s", (m->prpre ? m->prpre : "./"),
-				m->str);
-
-			if (ztat(pb, &buf, 1) ?
-			    clprintm(g, q, mc, ml, (!i), wid, NULL, NULL) :
-			    clprintm(g, q, mc, ml, (!i), wid, pb, &buf))
-			    goto end;
-		    } else if (clprintm(g, q, mc, ml, (!i), wid, NULL, NULL))
-			goto end;
+                    if (clprintm(g, q, mc, ml, (!i), wid))
+                        goto end;
 
 		    if (dolist(ml))
 			printed++;
@@ -1290,8 +1276,7 @@ compprintlist(int showall)
 		}
 		while (i-- > 0) {
 		    if (clprintm(g, NULL, mc, ml, (!i),
-				 (g->widths ? g->widths[mc] : g->width),
-				 NULL, NULL))
+				 (g->widths ? g->widths[mc] : g->width)))
 			goto end;
 		    mc++;
 		}
@@ -1366,8 +1351,7 @@ compprintlist(int showall)
 
 /**/
 static int
-clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
-	 char *path, struct stat *buf)
+clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
 {
     Cmatch m;
     int len, subcols = 0, stop = 0, ret = 0;
@@ -1467,8 +1451,8 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
 	    zcputs(&mcolors, g->name, COL_HI);
 	else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT)))
 	    zcputs(&mcolors, g->name, COL_DU);
-	else if (buf)
-	    subcols = putfilecol(&mcolors, g->name, m->str, buf->st_mode);
+	else if (m->mode)
+	    subcols = putfilecol(&mcolors, g->name, m->str, m->mode);
 	else
 	    subcols = putmatchcol(&mcolors, g->name, (m->disp ? m->disp : m->str));
 
@@ -1483,12 +1467,12 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
 	len = niceztrlen(m->disp ? m->disp : m->str);
 	mlprinted = len / columns;
 
-	if ((g->flags & CGF_FILES) && buf) {
+	if ((g->flags & CGF_FILES) && m->modec) {
 	    if (m->gnum != mselect) {
 		zcoff();
 		zcputs(&mcolors, g->name, COL_TC);
 	    }
-	    putc(file_type(buf->st_mode), shout);
+	    putc(m->modec, shout);
 	    len++;
         }
 	if ((len = width - len - 2) > 0) {
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 44a40f0fb..5d06538ac 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -30,6 +30,10 @@
 #include "complete.mdh"
 #include "compresult.pro"
 
+/* The number of columns to leave empty between rows of matches. */
+
+#define CM_SPACE  2
+
 /* This counts how often the list of completions was invalidated.
  * Can be used to detect if we have a new list.  */
 
@@ -929,7 +933,7 @@ do_single(Cmatch m)
     int l, sr = 0, scs;
     int havesuff = 0;
     int partest = (m->ripre || ((m->flags & CMF_ISPAR) && parpre));
-    char *str = m->str, *ppre = m->ppre, *psuf = m->psuf, *prpre = m->prpre;
+    char *str = m->orig, *ppre = m->ppre, *psuf = m->psuf, *prpre = m->prpre;
 
     if (!prpre) prpre = "";
     if (!ppre) ppre = "";
@@ -1380,7 +1384,7 @@ calclist(int showall)
     Cmgroup g;
     Cmatch *p, m;
     Cexpl *e;
-    int hidden = 0, nlist = 0, nlines = 0, add;
+    int hidden = 0, nlist = 0, nlines = 0;
     int max = 0, i;
     VARARR(int, mlens, nmatches + 1);
 
@@ -1474,7 +1478,7 @@ calclist(int showall)
                         if (!(m->flags & CMF_ROWS))
                             g->flags &= ~CGF_ROWS;
                     } else {
-                        l = niceztrlen(m->str);
+                        l = niceztrlen(m->str) + !!m->modec;
                         ndisp++;
                         if (l > glong)
                             glong = l;
@@ -1503,19 +1507,16 @@ calclist(int showall)
 		e++;
 	    }
 	}
-        if (isset(LISTTYPES) && hasf) {
+        if (isset(LISTTYPES) && hasf)
             g->flags |= CGF_FILES;
-            add = 3;
-        } else
-            add = 2;
-	g->totl = totl + (ndisp * add);
+	g->totl = totl + (ndisp * CM_SPACE);
 	g->dcount = ndisp;
-	g->width = glong + add;
-	g->shortest = gshort + add;
+	g->width = glong + CM_SPACE;
+	g->shortest = gshort + CM_SPACE;
 	if ((g->cols = columns / g->width) > g->dcount)
 	    g->cols = g->dcount;
 	if (g->cols) {
-	    i = g->cols * g->width - add;
+	    i = g->cols * g->width - CM_SPACE;
 	    if (i > max)
 		max = i;
 	}
@@ -1525,7 +1526,6 @@ calclist(int showall)
 	int *ws, tlines, tcols, width, glines;
 
 	for (g = amatches; g; g = g->next) {
-            add = 2 + !!(g->flags & CGF_FILES);
 	    glines = 0;
 
 	    zfree(g->widths, 0);
@@ -1536,7 +1536,8 @@ calclist(int showall)
 		    if (g->cols) {
 			glines += (arrlen(pp) + g->cols - 1) / g->cols;
 			if (g->cols > 1)
-			    g->width += ((max - (g->width * g->cols - add)) /
+			    g->width += ((max - (g->width * g->cols -
+                                                 CM_SPACE)) /
                                          g->cols);
 		    } else {
 			g->cols = 1;
@@ -1550,7 +1551,8 @@ calclist(int showall)
 		if (g->cols) {
 		    glines += (g->dcount + g->cols - 1) / g->cols;
 		    if (g->cols > 1)
-			g->width += (max - (g->width * g->cols - add)) / g->cols;
+			g->width += ((max - (g->width * g->cols - CM_SPACE)) /
+                                     g->cols);
 		} else if (!(g->flags & CGF_LINES)) {
 		    g->cols = 1;
 		    g->width = 0;
@@ -1573,8 +1575,6 @@ calclist(int showall)
 	    if (!(g->flags & CGF_PACKED))
 		continue;
 
-            add = 2 + !!(g->flags & CGF_FILES);
-
 	    ws = g->widths = (int *) zalloc(columns * sizeof(int));
 	    memset(ws, 0, columns * sizeof(int));
 	    tlines = g->lins;
@@ -1587,12 +1587,13 @@ calclist(int showall)
 		    VARARR(int, ylens, yl);
 
 		    for (i = 0; *pp; i++, pp++)
-			ylens[i] = ztrlen(*pp) + add;
+			ylens[i] = ztrlen(*pp) + CM_SPACE;
 
 		    if (g->flags & CGF_ROWS) {
                         int nth, tcol, len;
 
-                        for (tcols = columns / (g->shortest + add); tcols > g->cols;
+                        for (tcols = columns / (g->shortest + CM_SPACE);
+                             tcols > g->cols;
                              tcols--) {
 
                             memset(ws, 0, tcols * sizeof(int));
@@ -1620,7 +1621,8 @@ calclist(int showall)
 		    } else {
                         int nth, tcol, tline, len;
 
-                        for (tcols = columns / (g->shortest + add); tcols > g->cols;
+                        for (tcols = columns / (g->shortest + CM_SPACE);
+                             tcols > g->cols;
                              tcols--) {
 
                             if ((tlines = (g->dcount + tcols - 1) / tcols) <= 0)
@@ -1658,7 +1660,8 @@ calclist(int showall)
 		if (g->flags & CGF_ROWS) {
                     int nth, tcol, len;
 
-                    for (tcols = columns / (g->shortest + add); tcols > g->cols;
+                    for (tcols = columns / (g->shortest + CM_SPACE);
+                         tcols > g->cols;
                          tcols--) {
 
                         memset(ws, 0, tcols * sizeof(int));
@@ -1675,7 +1678,7 @@ calclist(int showall)
                                 tlines++;
                             }
                             len = (mlens[m->gnum] +
-                                   (tcol == tcols - 1 ? 0 : add));
+                                   (tcol == tcols - 1 ? 0 : CM_SPACE));
 
                             if (len > ws[tcol]) {
                                 width += len - ws[tcol];
@@ -1688,7 +1691,8 @@ calclist(int showall)
 		} else {
                     int nth, tcol, tline, len;
 
-                    for (tcols = columns / (g->shortest + add); tcols > g->cols;
+                    for (tcols = columns / (g->shortest + CM_SPACE);
+                         tcols > g->cols;
                          tcols--) {
 
                         if ((tlines = (g->dcount + tcols - 1) / tcols) <= 0)
@@ -1712,7 +1716,7 @@ calclist(int showall)
                                 tlines++;
                             }
                             len = (mlens[m->gnum] +
-                                   (tcol == tcols - 1 ? 0 : add));
+                                   (tcol == tcols - 1 ? 0 : CM_SPACE));
 
                             if (len > ws[tcol]) {
                                 width += len - ws[tcol];
@@ -1737,20 +1741,19 @@ calclist(int showall)
 		g->lins = tlines;
 		g->cols = tcols;
 		g->totl = width;
-		width -= add;
+		width -= CM_SPACE;
 		if (width > max)
 		    max = width;
 	    }
 	}
 	for (g = amatches; g; g = g->next) {
-            add = 2 + !!(g->flags & CGF_FILES);
 	    if (g->widths) {
-		int *p, a = (max - g->totl + add) / g->cols;
+		int *p, a = (max - g->totl + CM_SPACE) / g->cols;
 
 		for (i = g->cols, p = g->widths; i; i--, p++)
 		    *p += a;
 	    } else if (g->width && g->cols > 1)
-		g->width += (max - (g->width * g->cols - add)) / g->cols;
+		g->width += (max - (g->width * g->cols - CM_SPACE)) / g->cols;
 	}
     }
     listdat.valid = 1;
@@ -1949,7 +1952,7 @@ printlist(int over, CLPrintFunc printm, int showall)
 			    }
 			}
 			printed++;
-			printm(g, p, 0, ml, 1, 0, NULL, NULL);
+			printm(g, p, 0, ml, 1, 0);
 			pnl = 1;
 		    }
 	    }
@@ -1970,25 +1973,10 @@ printlist(int over, CLPrintFunc printm, int showall)
 		while (n && i--) {
 		    wid = (g->widths ? g->widths[mc] : g->width);
 		    if (!(m = *q)) {
-			printm(g, NULL, mc, ml, (!i), wid, NULL, NULL);
+			printm(g, NULL, mc, ml, (!i), wid);
 			break;
 		    }
-		    if (!m->disp && (m->flags & CMF_FILE) &&
-			m->str[0] && m->str[strlen(m->str) - 1] != '/') {
-			struct stat buf;
-			char *pb;
-
-			pb = (char *) zhalloc((m->prpre ? strlen(m->prpre) : 0) +
-					     3 + strlen(m->str));
-			sprintf(pb, "%s%s", (m->prpre ? m->prpre : "./"),
-				m->str);
-
-			if (ztat(pb, &buf, 1))
-			    printm(g, q, mc, ml, (!i), wid, NULL, NULL);
-			else
-			    printm(g, q, mc, ml, (!i), wid, pb, &buf);
-		    } else
-			printm(g, q, mc, ml, (!i), wid, NULL, NULL);
+                    printm(g, q, mc, ml, (!i), wid);
 
 		    printed++;
 
@@ -2000,7 +1988,7 @@ printlist(int over, CLPrintFunc printm, int showall)
 		}
 		while (i-- > 0) {
 		    printm(g, NULL, mc, ml, (!i),
-			   (g->widths ? g->widths[mc] : g->width), NULL, NULL);
+			   (g->widths ? g->widths[mc] : g->width));
 		    mc++;
 		}
 		if (n) {
@@ -2091,8 +2079,7 @@ bld_all_str(Cmatch all)
 
 /**/
 static void
-iprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
-	char *path, struct stat *buf)
+iprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
 {
     Cmatch m;
     int len = 0;
@@ -2114,8 +2101,8 @@ iprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
 	nicezputs(m->str, shout);
 	len = niceztrlen(m->str);
 
-	if ((g->flags & CGF_FILES) && buf) {
-	    putc(file_type(buf->st_mode), shout);
+	if ((g->flags & CGF_FILES) && m->modec) {
+	    putc(m->modec, shout);
 	    len++;
 	}
     }