zsh-workers
 help / color / mirror / code / Atom feed
* Re: Completion of files with spaces in
@ 1999-03-29  8:39 Sven Wischnowsky
  0 siblings, 0 replies; 8+ messages in thread
From: Sven Wischnowsky @ 1999-03-29  8:39 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> Yep. The patch below should fix this, but it still has one problem:
> braces are not re-inserted in the right place if there were characters
> that needed quoting before them. I don't see a simple enough solution
> for this now, I'll have to think about this some more.

The patch below fixes that. Again, it looks big (removing the extra
argument to inststrlen() again).

Bye
 Sven

diff -u oos/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- oos/Zle/zle_tricky.c	Mon Mar 29 10:27:58 1999
+++ Src/Zle/zle_tricky.c	Mon Mar 29 10:30:08 1999
@@ -61,7 +61,7 @@
 #endif
 
 
-#define inststr(X) inststrlen((X),1,-1,0)
+#define inststr(X) inststrlen((X),1,-1)
 
 /* wb and we hold the beginning/end position of the word we are completing. */
 
@@ -105,12 +105,12 @@
 
 /* This is for completion inside a brace expansion. brbeg and brend hold  *
  * strings that were temporarily removed from the string to complete.     *
- * brpl and brsl, brbsl hold the offset of these strings.                 *
+ * brpl and brsl, hold the offset of these strings.                 *
  * brpcs and brscs hold the positions of the re-inserted string in the    *
  * line.                                                                  */
 
 static char *brbeg = NULL, *brend = NULL;
-static int brpl, brsl, brbsl, brpcs, brscs;
+static int brpl, brsl, brpcs, brscs, qbrpl, qbrsl, hasunqu;
 
 /* The list of matches.  fmatches contains the matches we first ignore *
  * because of fignore.                                                 */
@@ -161,6 +161,7 @@
 static char *fpre, *fsuf;
 static char *ipre, *ripre;
 static char *isuf;
+static char *qfpre, *qfsuf, *qrpre, *qrsuf, *qlpre, *qlsuf;
 static int lpl, lsl, rpl, rsl, fpl, fsl, lppl, lpsl;
 static int noreal;
 
@@ -515,7 +516,7 @@
 	cs = menupos + menulen + menuinsc;
 	iremovesuffix(' ', 1);
 
-	inststrlen(" ", 1, 1, 0);
+	inststrlen(" ", 1, 1);
 	menuinsc = menulen = 0;
 	menupos = cs;
 	menuwe = 1;
@@ -1506,11 +1507,13 @@
 
 	    if (tt && tt < s + myoffs) {
 		/* Braces are go:  delete opening brace */
-		char *com = NULL;
+		char *com = NULL, *tmp;
 		int pl, sl;
 
 		brbeg = dupstring(tt);
 		brpl = tt - s;
+		tmp = dupstrpfx(s, tt - s);
+		qbrpl = strlen(quotename(tmp, NULL));
 		pl = 1;
 		sl = 0;
 		chuck(tt);
@@ -1543,8 +1546,8 @@
 		    if (*p == Outbrace)
 			chuck(p);
 		    brsl = strlen(s) - (p - s);
-		    brbsl = p - s;
 		    brend[sl] = '\0';
+		    qbrsl = strlen(quotename(p, NULL));
 		}
 		/* we are still waiting for an outbrace and maybe commas */
 		if (brbeg)
@@ -2052,7 +2055,7 @@
 match_str(char *l, char *w, int *bp, int *rwlp, int sfx, int test)
 {
     int ll = strlen(l), lw = strlen(w), oll = ll, olw = lw;
-    int il = 0, iw = 0, t, ind, add, bc;
+    int il = 0, iw = 0, t, ind, add, bc = (bp ? *bp : 0);
     VARARR(unsigned char, ea, ll + 1);
     char *ow;
     Cmlist ms;
@@ -2066,9 +2069,9 @@
 
     if (sfx) {
 	l += ll; w += lw;
-	ind = -1; add = -1; bc = brsl;
+	ind = -1; add = -1;
     } else {
-	ind = 0; add = 1; bc = brpl;
+	ind = 0; add = 1;
     }
     /* ow will always point to the beginning (or end) of that sub-string
      * in w that wasn't put in the match-variables yet. */
@@ -2418,14 +2421,19 @@
 	wl = strlen(w);
 	*clp = bld_parts(w, wl, wl, NULL);
 	*exact = 0;
+	*bpl = (qu ? qbrpl : brpl);
+	*bsl = (qu ? qbrsl : brsl);
     } else {
 	Cline pli, plil;
 	int mpl, rpl, wl;
 
+	w = (qu ? quotename(w, NULL) : dupstring(w));
+
 	wl = strlen(w);
 
 	/* Always try to match the prefix. */
 
+	*bpl = (qu ? qbrpl : brpl);
 	if ((mpl = match_str(pfx, w, bpl, &rpl, 0, 0)) < 0)
 	    return NULL;
 
@@ -2450,6 +2458,7 @@
 	    plil = matchlastpart;
 
 	    /* The try to match the suffix. */
+	    *bsl = (qu ? qbrsl : brsl);
 	    if ((msl = match_str(sfx, w + mpl, bsl, &rsl, 1, 0)) < 0) {
 		free_cline(pli);
 
@@ -2488,8 +2497,6 @@
 	    pli = matchparts;
 	}
 	r = dupstring(matchbuf);
-	if (qu)
-	    r = quotename(r, NULL);
 
 	*clp = pli;
 
@@ -2501,6 +2508,9 @@
 	} else
 	    *exact = !strcmp(pfx, w);
     }
+    if (!qu)
+	hasunqu = 1;
+
     return r;
 }
 
@@ -3560,9 +3570,17 @@
 		    rems = NULL;
 		} else if (rems)
 		    rems = dupstring(rems);
+
+		/* Probably quote the prefix and suffix for testing. */
+		if (!cp && !(aflags & CAF_QUOTE)) {
+		    lpre = quotename(lpre, NULL);
+		    lsuf = quotename(lsuf, NULL);
+		    llpl = strlen(lpre);
+		    llsl = strlen(lsuf);
+		}
 	    }
 	    /* Walk through the matches given. */
-	    for (; (s = dupstring(*argv)); argv++) {
+	    for (; (s = *argv); argv++) {
 		sl = strlen(s);
 		bpl = brpl;
 		bsl = brsl;
@@ -3579,16 +3597,16 @@
 			    isalt = 1;
 		}
 		if (!(aflags & CAF_MATCH)) {
-		    ms = s;
-		    lc = bld_parts(s, sl, -1, NULL);
+		    ms = dupstring(s);
+		    lc = bld_parts(ms, sl, -1, NULL);
 		    isexact = 0;
 		} else if (!(ms = comp_match(lpre, lsuf, s, cp, &lc,
 					     !(aflags & CAF_QUOTE),
 					     &bpl, &bsl, &isexact)))
 		    continue;
 
-		cm = add_match_data(isalt, ms, lc, ipre, ipre, isuf, pre, prpre,
-				    ppre, psuf, suf, bpl, bsl,
+		cm = add_match_data(isalt, ms, lc, ipre, ipre, isuf, pre, 
+				    prpre, ppre, psuf, suf, bpl, bsl,
 				    flags, isexact);
 		cm->rems = rems;
 		cm->remf = remf;
@@ -3641,9 +3659,6 @@
     hn = (HashNode) t;
     pm = (Param) t;
 
-    if (incompfunc)
-	s = dupstring(s);
-
     if (addwhat == -1 || addwhat == -5 || addwhat == -6 ||
 	addwhat == CC_FILES || addwhat == -7 || addwhat == -8) {
 	if ((addwhat == CC_FILES ||
@@ -3657,10 +3672,13 @@
 		    !strcmp(*pt, s + sl - filell))
 		    isalt = 1;
 	}
-	if (!(ms = comp_match(fpre, fsuf, s, filecomp, &lc,
-			      (addwhat == CC_FILES || addwhat == -6 ||
-			       addwhat == -5 || addwhat == -8),
-			      &bpl, &bsl, &isexact)))
+	ms = ((addwhat == CC_FILES || addwhat == -6 ||
+	       addwhat == -5 || addwhat == -8) ? 
+	      comp_match(qfpre, qfsuf, s, filecomp, &lc, 1,
+			 &bpl, &bsl, &isexact) :
+	      comp_match(fpre, fsuf, s, filecomp, &lc, 0,
+			 &bpl, &bsl, &isexact));
+	if (!ms)
 	    return;
 
 	if (addwhat == -7 && !findcmd(s, 0))
@@ -3690,10 +3708,19 @@
 		 (((addwhat & CC_DISCMDS) && (hn->flags & DISABLED)) ||
 		  ((addwhat & CC_EXCMDS)  && !(hn->flags & DISABLED)))) ||
 		((addwhat & CC_BINDINGS) && !(hn->flags & DISABLED))))) {
-	if (!(ms = comp_match(rpre, rsuf, s, patcomp, &lc,
+	char *p1, *s1, *p2, *s2;
+
+	if (addwhat == CC_QUOTEFLAG) {
+	    p1 = qrpre; s1 = qrsuf;
+	    p2 = rpre;  s2 = rsuf;
+	} else {
+	    p1 = qlpre; s1 = qlsuf;
+	    p2 = lpre;  s2 = lsuf;
+	}
+	if (!(ms = comp_match(p1, s1, s, patcomp, &lc,
 			      (addwhat == CC_QUOTEFLAG),
 			      &bpl, &bsl, &isexact)) &&
-	    !(ms = comp_match(lpre, lsuf, s, NULL, &lc,
+	    !(ms = comp_match(p2, s2, s, NULL, &lc,
 			      (addwhat == CC_QUOTEFLAG),
 			      &bpl, &bsl, &isexact)))
 	    return;
@@ -4014,6 +4041,7 @@
 	ainfo = fainfo = NULL;
 	matchers = newlinklist();
 
+	hasunqu = 0;
 	useline = (lst != COMP_LIST_COMPLETE);
 	useexact = (isset(RECEXACT) && usemenu != 1);
 	uselist = (useline ?
@@ -5027,8 +5055,9 @@
     usemenu = um;
     patcomp = filecomp = NULL;
     menucur = NULL;
-    rpre = rsuf = lpre = lsuf = ppre = psuf = lppre = lpsuf = prpre =
-	fpre = fsuf = ipre = ripre = prpre = NULL;
+    rpre = rsuf = lpre = lsuf = ppre = psuf = lppre = lpsuf =
+	fpre = fsuf = ipre = ripre = prpre = 
+	qfpre = qfsuf = qrpre = qrsuf = qlpre = qlsuf = NULL;
 
     curcc = cc;
 
@@ -5136,8 +5165,10 @@
     lpre = zhalloc(lpl + 1);
     memcpy(lpre, s, lpl);
     lpre[lpl] = '\0';
+    qlpre = quotename(lpre, NULL);
     lsuf = dupstring(s + offs);
     lsl = strlen(lsuf);
+    qlsuf = quotename(lsuf, NULL);
 
     /* First check for ~.../... */
     if (ic == Tilde) {
@@ -5156,9 +5187,11 @@
     rpre = (*p || *lpre == Tilde || *lpre == Equals) ?
 	(noreal = 0, getreal(tt)) :
 	dupstring(tt);
+    qrpre = quotename(rpre, NULL);
 
     for (p = lsuf; *p && *p != String && *p != Tick; p++);
     rsuf = *p ? (noreal = 0, getreal(lsuf)) : dupstring(lsuf);
+    qrsuf = quotename(rsuf, NULL);
 
     /* Check if word is a pattern. */
 
@@ -5234,7 +5267,7 @@
 	    lppre = dupstring((char *) (line + wb));
 	    line[cs] = save;
 	    if (brbeg && *brbeg)
-		strcpy(lppre + brpl, lppre + brpl + strlen(brbeg));
+		strcpy(lppre + qbrpl, lppre + qbrpl + strlen(brbeg));
 	    if ((p = strrchr(lppre, '/'))) {
 		p[1] = '\0';
 		lppl = strlen(lppre);
@@ -5256,7 +5289,7 @@
 	    lpsuf = dupstring((char *) (line + cs));
 	    line[we] = save;
 	    if (brend && *brend) {
-		char *p = lpsuf + brsl - (cs - wb);
+		char *p = lpsuf + qbrsl - (cs - wb);
 
 		strcpy(p, p + strlen(brend));
 	    }
@@ -5271,8 +5304,10 @@
 	/* And get the file prefix. */
 	fpre = dupstring(((s1 == s || s1 == rpre || ic) &&
 			  (*s != '/' || cs == wb)) ? s1 : s1 + 1);
+	qfpre = quotename(fpre, NULL);
 	/* And the suffix. */
 	fsuf = dupstrpfx(rsuf, s2 - rsuf);
+	qfsuf = quotename(fsuf, NULL);
 
 	if (comppatmatch && *comppatmatch && (ispattern & 2)) {
 	    int t2;
@@ -5536,6 +5571,7 @@
 	 * that things starting with these characters will be added.   */
 	rpre = dyncat((ic == Tilde) ? "~" : "=", rpre);
 	rpl++;
+	qrpre = dyncat((ic == Tilde) ? "~" : "=", qrpre);
     }
     if (!ic && (cc->mask & CC_COMMPATH) && !*ppre && !*psuf) {
 	/* If we have to complete commands, add alias names, *
@@ -6320,19 +6356,12 @@
 
 /**/
 static int
-inststrlen(char *str, int move, int len, int qu)
+inststrlen(char *str, int move, int len)
 {
     if (!len || !str)
 	return 0;
     if (len == -1)
 	len = strlen(str);
-    if (qu) {
-	VARARR(char, b,  len + 1);
-	memcpy(b, str, len);
-	b[len] = '\0';
-	str = quotename(b, NULL);
-	len = strlen(str);
-    }
     spaceinline(len);
     strncpy((char *)(line + cs), str, len);
     if (move)
@@ -6358,17 +6387,18 @@
      * to re-insert. */
     if (ins) {
 	if ((hasp = (brbeg && *brbeg))) {
-	    plen = strlen(brbeg); pl = brpl;
+	    plen = strlen(brbeg); pl = (hasunqu ? brpl : qbrpl);
 	}
 	if ((hass = (brend && *brend))) {
-	    slen = strlen(brend); sl = we - wb - brsl - plen - slen + 1;
+	    slen = strlen(brend);
+	    sl = we - wb - (hasunqu ? brsl : qbrsl) - plen - slen + 1;
 	}
 	if (!pl) {
-	    inststrlen(brbeg, 1, -1, 0);
+	    inststrlen(brbeg, 1, -1);
 	    pl = -1; hasp = 0;
 	}
 	if (!sl) {
-	    inststrlen(brend, 1, -1, 0);
+	    inststrlen(brend, 1, -1);
 	    sl = -1; hass = 0;
 	}
     }
@@ -6380,7 +6410,7 @@
 	    spos = -1;
 	/* Insert the original string if no prefix. */
 	if (l->olen && !(l->flags & CLF_SUF) && !l->prefix) {
-	    inststrlen(l->orig, 1, l->olen, 1);
+	    inststrlen(l->orig, 1, l->olen);
 	    if (ins) {
 		li += l->olen;
 		if (pl >= 0 && li >= pl) {
@@ -6395,9 +6425,9 @@
 	    for (s = l->prefix; s; s = s->next) {
 		pcs = cs;
 		if (s->flags & CLF_LINE)
-		    inststrlen(s->line, 1, s->llen, 1);
+		    inststrlen(s->line, 1, s->llen);
 		else
-		    inststrlen(s->word, 1, s->wlen, 1);
+		    inststrlen(s->word, 1, s->wlen);
 		if (d < 0 && (s->flags & CLF_DIFF))
 		    d = cs;
 		if (ins) {
@@ -6418,9 +6448,9 @@
 	pcs = cs;
 	/* Insert the anchor. */
 	if (l->flags & CLF_LINE)
-	    inststrlen(l->line, 1, l->llen, 1);
+	    inststrlen(l->line, 1, l->llen);
 	else
-	    inststrlen(l->word, 1, l->wlen, 1);
+	    inststrlen(l->word, 1, l->wlen);
 	if (ins) {
 	    li += l->llen;
 	    if (pl >= 0 && li >= pl) {
@@ -6440,7 +6470,7 @@
 	/* And now insert the suffix or the original string. */
 	if (l->olen && (l->flags & CLF_SUF) && !l->suffix) {
 	    pcs = cs;
-	    inststrlen(l->orig, 1, l->olen, 1);
+	    inststrlen(l->orig, 1, l->olen);
 	    if (ins) {
 		li += l->olen;
 		if (pl >= 0 && li >= pl) {
@@ -6457,10 +6487,10 @@
 		if (j < 0 && (s->flags & CLF_DIFF))
 		    j = i;
 		if (s->flags & CLF_LINE) {
-		    inststrlen(s->line, 0, s->llen, 1);
+		    inststrlen(s->line, 0, s->llen);
 		    i += s->llen; pcs = cs + s->llen;
 		} else {
-		    inststrlen(s->word, 0, s->wlen, 1);
+		    inststrlen(s->word, 0, s->wlen);
 		    i += s->wlen; pcs = cs + s->wlen;
 		}
 		if (ins) {
@@ -6486,14 +6516,14 @@
 	    if (hasp && ppos >= 0) {
 		i = cs;
 		cs = ppos;
-		inststrlen(brbeg, 1, plen, 0);
+		inststrlen(brbeg, 1, plen);
 		cs = i + plen;
 		hasp = 0;
 	    }
 	    if (hass && spos >= 0) {
 		i = cs;
 		cs = spos;
-		inststrlen(brend, 1, slen, 0);
+		inststrlen(brend, 1, slen);
 		cs = i + slen;
 		hass = 0;
 	    }
@@ -6501,9 +6531,9 @@
 	l = l->next;
     }
     if (pl >= 0)
-	inststrlen(brbeg, 1, plen, 0);
+	inststrlen(brbeg, 1, plen);
     if (sl >= 0)
-	inststrlen(brend, 1, slen, 0);
+	inststrlen(brend, 1, slen);
 
     /* This calculates the new cursor position. If we had a mid cline
      * with missing characters, we take this, otherwise if we have a
@@ -6574,21 +6604,21 @@
 
     /* Ignored prefix. */
     if (m->ipre) {
-	inststrlen(m->ipre, 1, (l = strlen(m->ipre)), 0);
+	inststrlen(m->ipre, 1, (l = strlen(m->ipre)));
 	r += l;
     }
     /* -P prefix. */
     if (m->pre) {
-	inststrlen(m->pre, 1, (l = strlen(m->pre)), 0);
+	inststrlen(m->pre, 1, (l = strlen(m->pre)));
 	r += l;
     }
     /* Path prefix. */
     if (m->ppre) {
-	inststrlen(m->ppre, 1, (l = strlen(m->ppre)), 0);
+	inststrlen(m->ppre, 1, (l = strlen(m->ppre)));
 	r += l;
     }
     /* The string itself. */
-    inststrlen(m->str, 1, (l = strlen(m->str)), 0);
+    inststrlen(m->str, 1, (l = strlen(m->str)));
     r += l;
     ocs = cs;
     /* Re-insert the brace beginning, if any. */
@@ -6596,14 +6626,14 @@
 	cs = a + m->brpl + (m->pre ? strlen(m->pre) : 0);
 	l = strlen(brbeg);
 	brpcs = cs;
-	inststrlen(brbeg, 1, l, 0);
+	inststrlen(brbeg, 1, l);
 	r += l;
 	ocs += l;
 	cs = ocs;
     }
     /* Path suffix. */
     if (m->psuf) {
-	inststrlen(m->psuf, 1, (l = strlen(m->psuf)), 0);
+	inststrlen(m->psuf, 1, (l = strlen(m->psuf)));
 	r += l;
     }
     /* Re-insert the brace end. */
@@ -6612,19 +6642,19 @@
 	cs -= m->brsl;
 	ocs = brscs = cs;
 	l = strlen(brend);
-	inststrlen(brend, 1, l, 0);
+	inststrlen(brend, 1, l);
 	r += l;
 	cs = a + l;
     } else
 	brscs = -1;
     /* -S suffix */
     if (m->suf) {
-	inststrlen(m->suf, 1, (l = strlen(m->suf)), 0);
+	inststrlen(m->suf, 1, (l = strlen(m->suf)));
 	r += l;
     }
     /* ignored suffix */
     if (m->isuf) {
-	inststrlen(m->isuf, 1, (l = strlen(m->isuf)), 0);
+	inststrlen(m->isuf, 1, (l = strlen(m->isuf)));
 	r += l;
     }
     lastend = cs;
@@ -6802,7 +6832,7 @@
 	if (m->ripre && (m->flags & CMF_PARBR)) {
 	    /*{{*/
 	    /* Completing a parameter in braces.  Add a removable `}' suffix. */
-	    inststrlen("}", 1, 1, 0);
+	    inststrlen("}", 1, 1);
 	    menuinsc++;
 	    if (menuwe)
 		menuend++;
@@ -6823,7 +6853,7 @@
 	    if (!(sr = ztat(p, &buf, 0)) && S_ISDIR(buf.st_mode)) {
 		/* It is a directory, so add the slash. */
 		havesuff = 1;
-		inststrlen("/", 1, 1, 0);
+		inststrlen("/", 1, 1);
 		menuinsc++;
 		if (menuwe)
 		    menuend++;
@@ -6847,7 +6877,7 @@
 	    /* Otherwise, add a `,' suffix, and let `}' remove it. */
 	    cs = menuend;
 	    havesuff = 1;
-	    inststrlen(",", 1, 1, 0);
+	    inststrlen(",", 1, 1);
 	    menuinsc++;
 	    makesuffix(1);
 	    if ((!menucmp || menuwe) && isset(AUTOPARAMKEYS))
@@ -6857,7 +6887,7 @@
 	/* If we didn't add a suffix, add a space, unless we are *
 	 * doing menu completion or we are completing files and  *
 	 * the string doesn't name an existing file.             */
-	inststrlen(" ", 1, 1, 0);
+	inststrlen(" ", 1, 1);
 	menuinsc++;
 	if (menuwe)
 	    makesuffix(1);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of files with spaces in
  1999-03-26 13:37 Sven Wischnowsky
@ 1999-03-26 13:53 ` Bruce Stephens
  0 siblings, 0 replies; 8+ messages in thread
From: Bruce Stephens @ 1999-03-26 13:53 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Yes, I'm sorry. But quoting and completion has always been a
> terribly complicated matter and it's become worse with the new
> completion stuff.

I wasn't intending any criticism.  I'm just thinking ahead a few weeks
to the next stable release of zsh: it's OK for zsh to fail to get
obscure things right, but it's really important that it get the common
ones right, otherwise the shell just won't feel right, and people
won't want to upgrade (and so will miss out on all the important
improvements).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of files with spaces in
@ 1999-03-26 13:37 Sven Wischnowsky
  1999-03-26 13:53 ` Bruce Stephens
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 1999-03-26 13:37 UTC (permalink / raw)
  To: zsh-workers


Bruce Stephens wrote:

> Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> 
> > Yep. The patch below should fix this, but it still has one problem:
> > braces are not re-inserted in the right place if there were
> > characters that needed quoting before them. I don't see a simple
> > enough solution for this now, I'll have to think about this some
> > more.
> 
> Good, that fixes it.  I'm not so worried about the full general
> solution, but it's annoying where relatively common things don't work.

Yes, I'm sorry. But quoting and completion has always been a terribly
complicated matter and it's become worse with the new completion stuff.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of files with spaces in
  1999-03-26 12:45 Sven Wischnowsky
@ 1999-03-26 13:32 ` Bruce Stephens
  0 siblings, 0 replies; 8+ messages in thread
From: Bruce Stephens @ 1999-03-26 13:32 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Yep. The patch below should fix this, but it still has one problem:
> braces are not re-inserted in the right place if there were
> characters that needed quoting before them. I don't see a simple
> enough solution for this now, I'll have to think about this some
> more.

Good, that fixes it.  I'm not so worried about the full general
solution, but it's annoying where relatively common things don't work.

(Well, it's not common to have spaces in on most Unixes, I suppose,
but I happened to be looking at some Windows source, and I guess many
Linux and BSD people have VFAT partitions mounted, where filenames
with spaces in are common.)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of files with spaces in
@ 1999-03-26 12:45 Sven Wischnowsky
  1999-03-26 13:32 ` Bruce Stephens
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 1999-03-26 12:45 UTC (permalink / raw)
  To: zsh-workers


Bruce Stephens wrote:

> OK, that quotes the spaces, but I don't get completion after that.
> For example, if I have the file as above, and another one 
> "readme - yarrow.txt", then I get:
> 
>         % less readme\ -\ 
>                           ^ cursor here
> 
> as I'd expect, but <TAB> after that just beeps (I'd expect to be shown
> the possible completions).  And typing an extra "c" or "y" (to
> disambiguate) doesn't help: <TAB> just beeps.

Yep. The patch below should fix this, but it still has one problem:
braces are not re-inserted in the right place if there were characters
that needed quoting before them. I don't see a simple enough solution
for this now, I'll have to think about this some more.

The patch looks big but that's just a function getting one more
argument.


Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Fri Mar 26 11:50:01 1999
+++ Src/Zle/zle_tricky.c	Fri Mar 26 13:26:36 1999
@@ -61,7 +61,7 @@
 #endif
 
 
-#define inststr(X) inststrlen((X),1,-1)
+#define inststr(X) inststrlen((X),1,-1,0)
 
 /* wb and we hold the beginning/end position of the word we are completing. */
 
@@ -515,7 +515,7 @@
 	cs = menupos + menulen + menuinsc;
 	iremovesuffix(' ', 1);
 
-	inststrlen(" ", 1, 1);
+	inststrlen(" ", 1, 1, 0);
 	menuinsc = menulen = 0;
 	menupos = cs;
 	menuwe = 1;
@@ -2422,9 +2422,6 @@
 	Cline pli, plil;
 	int mpl, rpl, wl;
 
-	if (qu)
-	    w = quotename(w, NULL);
-
 	wl = strlen(w);
 
 	/* Always try to match the prefix. */
@@ -2491,6 +2488,9 @@
 	    pli = matchparts;
 	}
 	r = dupstring(matchbuf);
+	if (qu)
+	    r = quotename(r, NULL);
+
 	*clp = pli;
 
 	/* Test if the string built is equal to the one from the line. */
@@ -3583,7 +3583,7 @@
 		    lc = bld_parts(s, sl, -1, NULL);
 		    isexact = 0;
 		} else if (!(ms = comp_match(lpre, lsuf, s, cp, &lc,
-					     (aflags & CAF_QUOTE),
+					     !(aflags & CAF_QUOTE),
 					     &bpl, &bsl, &isexact)))
 		    continue;
 
@@ -4224,20 +4224,17 @@
 	zsfree(compprefix);
 	zsfree(compsuffix);
 	if (unset(COMPLETEINWORD)) {
-	    if (linwhat == IN_MATH)
-		tmp = s;
-	    else
-		tmp = quotename(s, NULL);
+	    /* Maybe we'll have to do quoting here some time. */
+	    tmp = dupstring(s);
 	    untokenize(tmp);
 	    compprefix = ztrdup(tmp);
 	    compsuffix = ztrdup("");
 	} else {
-	    char *ss = s + offs, sav;
+	    char *ss, sav;
 	    
-	    if (linwhat == IN_MATH)
-		tmp = s;
-	    else
-		tmp = quotename(s, &ss);
+	    tmp = dupstring(s);
+	    ss = tmp + offs;
+
 	    sav = *ss;
 	    *ss = '\0';
 	    untokenize(tmp);
@@ -6318,20 +6315,29 @@
 
 /* Insert the given string into the command line.  If move is non-zero, *
  * the cursor position is changed and len is the length of the string   *
- * to insert (if it is -1, the length is calculated here).              */
+ * to insert (if it is -1, the length is calculated here).              *
+ * The last argument says if we should quote the string.                */
 
 /**/
-static void
-inststrlen(char *str, int move, int len)
+static int
+inststrlen(char *str, int move, int len, int qu)
 {
     if (!len || !str)
-	return;
+	return 0;
     if (len == -1)
 	len = strlen(str);
+    if (qu) {
+	VARARR(char, b,  len + 1);
+	memcpy(b, str, len);
+	b[len] = '\0';
+	str = quotename(b, NULL);
+	len = strlen(str);
+    }
     spaceinline(len);
     strncpy((char *)(line + cs), str, len);
     if (move)
 	cs += len;
+    return len;
 }
 
 /* This builds the unambiguous string. If ins is non-zero, it is
@@ -6358,11 +6364,11 @@
 	    slen = strlen(brend); sl = we - wb - brsl - plen - slen + 1;
 	}
 	if (!pl) {
-	    inststrlen(brbeg, 1, -1);
+	    inststrlen(brbeg, 1, -1, 0);
 	    pl = -1; hasp = 0;
 	}
 	if (!sl) {
-	    inststrlen(brend, 1, -1);
+	    inststrlen(brend, 1, -1, 0);
 	    sl = -1; hass = 0;
 	}
     }
@@ -6374,7 +6380,7 @@
 	    spos = -1;
 	/* Insert the original string if no prefix. */
 	if (l->olen && !(l->flags & CLF_SUF) && !l->prefix) {
-	    inststrlen(l->orig, 1, l->olen);
+	    inststrlen(l->orig, 1, l->olen, 1);
 	    if (ins) {
 		li += l->olen;
 		if (pl >= 0 && li >= pl) {
@@ -6389,9 +6395,9 @@
 	    for (s = l->prefix; s; s = s->next) {
 		pcs = cs;
 		if (s->flags & CLF_LINE)
-		    inststrlen(s->line, 1, s->llen);
+		    inststrlen(s->line, 1, s->llen, 1);
 		else
-		    inststrlen(s->word, 1, s->wlen);
+		    inststrlen(s->word, 1, s->wlen, 1);
 		if (d < 0 && (s->flags & CLF_DIFF))
 		    d = cs;
 		if (ins) {
@@ -6412,9 +6418,9 @@
 	pcs = cs;
 	/* Insert the anchor. */
 	if (l->flags & CLF_LINE)
-	    inststrlen(l->line, 1, l->llen);
+	    inststrlen(l->line, 1, l->llen, 1);
 	else
-	    inststrlen(l->word, 1, l->wlen);
+	    inststrlen(l->word, 1, l->wlen, 1);
 	if (ins) {
 	    li += l->llen;
 	    if (pl >= 0 && li >= pl) {
@@ -6434,7 +6440,7 @@
 	/* And now insert the suffix or the original string. */
 	if (l->olen && (l->flags & CLF_SUF) && !l->suffix) {
 	    pcs = cs;
-	    inststrlen(l->orig, 1, l->olen);
+	    inststrlen(l->orig, 1, l->olen, 1);
 	    if (ins) {
 		li += l->olen;
 		if (pl >= 0 && li >= pl) {
@@ -6451,10 +6457,10 @@
 		if (j < 0 && (s->flags & CLF_DIFF))
 		    j = i;
 		if (s->flags & CLF_LINE) {
-		    inststrlen(s->line, 0, s->llen);
+		    inststrlen(s->line, 0, s->llen, 1);
 		    i += s->llen; pcs = cs + s->llen;
 		} else {
-		    inststrlen(s->word, 0, s->wlen);
+		    inststrlen(s->word, 0, s->wlen, 1);
 		    i += s->wlen; pcs = cs + s->wlen;
 		}
 		if (ins) {
@@ -6480,14 +6486,14 @@
 	    if (hasp && ppos >= 0) {
 		i = cs;
 		cs = ppos;
-		inststrlen(brbeg, 1, plen);
+		inststrlen(brbeg, 1, plen, 0);
 		cs = i + plen;
 		hasp = 0;
 	    }
 	    if (hass && spos >= 0) {
 		i = cs;
 		cs = spos;
-		inststrlen(brend, 1, slen);
+		inststrlen(brend, 1, slen, 0);
 		cs = i + slen;
 		hass = 0;
 	    }
@@ -6495,9 +6501,9 @@
 	l = l->next;
     }
     if (pl >= 0)
-	inststrlen(brbeg, 1, plen);
+	inststrlen(brbeg, 1, plen, 0);
     if (sl >= 0)
-	inststrlen(brend, 1, slen);
+	inststrlen(brend, 1, slen, 0);
 
     /* This calculates the new cursor position. If we had a mid cline
      * with missing characters, we take this, otherwise if we have a
@@ -6568,21 +6574,21 @@
 
     /* Ignored prefix. */
     if (m->ipre) {
-	inststrlen(m->ipre, 1, (l = strlen(m->ipre)));
+	inststrlen(m->ipre, 1, (l = strlen(m->ipre)), 0);
 	r += l;
     }
     /* -P prefix. */
     if (m->pre) {
-	inststrlen(m->pre, 1, (l = strlen(m->pre)));
+	inststrlen(m->pre, 1, (l = strlen(m->pre)), 0);
 	r += l;
     }
     /* Path prefix. */
     if (m->ppre) {
-	inststrlen(m->ppre, 1, (l = strlen(m->ppre)));
+	inststrlen(m->ppre, 1, (l = strlen(m->ppre)), 0);
 	r += l;
     }
     /* The string itself. */
-    inststrlen(m->str, 1, (l = strlen(m->str)));
+    inststrlen(m->str, 1, (l = strlen(m->str)), 0);
     r += l;
     ocs = cs;
     /* Re-insert the brace beginning, if any. */
@@ -6590,14 +6596,14 @@
 	cs = a + m->brpl + (m->pre ? strlen(m->pre) : 0);
 	l = strlen(brbeg);
 	brpcs = cs;
-	inststrlen(brbeg, 1, l);
+	inststrlen(brbeg, 1, l, 0);
 	r += l;
 	ocs += l;
 	cs = ocs;
     }
     /* Path suffix. */
     if (m->psuf) {
-	inststrlen(m->psuf, 1, (l = strlen(m->psuf)));
+	inststrlen(m->psuf, 1, (l = strlen(m->psuf)), 0);
 	r += l;
     }
     /* Re-insert the brace end. */
@@ -6606,19 +6612,19 @@
 	cs -= m->brsl;
 	ocs = brscs = cs;
 	l = strlen(brend);
-	inststrlen(brend, 1, l);
+	inststrlen(brend, 1, l, 0);
 	r += l;
 	cs = a + l;
     } else
 	brscs = -1;
     /* -S suffix */
     if (m->suf) {
-	inststrlen(m->suf, 1, (l = strlen(m->suf)));
+	inststrlen(m->suf, 1, (l = strlen(m->suf)), 0);
 	r += l;
     }
     /* ignored suffix */
     if (m->isuf) {
-	inststrlen(m->isuf, 1, (l = strlen(m->isuf)));
+	inststrlen(m->isuf, 1, (l = strlen(m->isuf)), 0);
 	r += l;
     }
     lastend = cs;
@@ -6796,7 +6802,7 @@
 	if (m->ripre && (m->flags & CMF_PARBR)) {
 	    /*{{*/
 	    /* Completing a parameter in braces.  Add a removable `}' suffix. */
-	    inststrlen("}", 1, 1);
+	    inststrlen("}", 1, 1, 0);
 	    menuinsc++;
 	    if (menuwe)
 		menuend++;
@@ -6817,7 +6823,7 @@
 	    if (!(sr = ztat(p, &buf, 0)) && S_ISDIR(buf.st_mode)) {
 		/* It is a directory, so add the slash. */
 		havesuff = 1;
-		inststrlen("/", 1, 1);
+		inststrlen("/", 1, 1, 0);
 		menuinsc++;
 		if (menuwe)
 		    menuend++;
@@ -6841,7 +6847,7 @@
 	    /* Otherwise, add a `,' suffix, and let `}' remove it. */
 	    cs = menuend;
 	    havesuff = 1;
-	    inststrlen(",", 1, 1);
+	    inststrlen(",", 1, 1, 0);
 	    menuinsc++;
 	    makesuffix(1);
 	    if ((!menucmp || menuwe) && isset(AUTOPARAMKEYS))
@@ -6851,7 +6857,7 @@
 	/* If we didn't add a suffix, add a space, unless we are *
 	 * doing menu completion or we are completing files and  *
 	 * the string doesn't name an existing file.             */
-	inststrlen(" ", 1, 1);
+	inststrlen(" ", 1, 1, 0);
 	menuinsc++;
 	if (menuwe)
 	    makesuffix(1);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of files with spaces in
  1999-03-25 16:29 Sven Wischnowsky
@ 1999-03-26 11:41 ` Bruce Stephens
  0 siblings, 0 replies; 8+ messages in thread
From: Bruce Stephens @ 1999-03-26 11:41 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Bruce Stephens wrote:
> 
> > With zsh-3.1.5-pws-13, zsh -f, files with spaces in don't seem to get
> > quoted properly.
> > 
> > So if I have the file "readme - corrections.txt", and I type:
> > 
> >         % less read<TAB>
> > 
> > I get 
> > 
> >         % less readme - 
> > 
> > I was expecting the spaces to be quoted with \.
> > 
> > I'm sure this worked once.  What's happened?
> 
> Me -- breaking up things (my favorite pastime).

OK, that quotes the spaces, but I don't get completion after that.
For example, if I have the file as above, and another one 
"readme - yarrow.txt", then I get:

        % less readme\ -\ 
                          ^ cursor here

as I'd expect, but <TAB> after that just beeps (I'd expect to be shown
the possible completions).  And typing an extra "c" or "y" (to
disambiguate) doesn't help: <TAB> just beeps.

(If "readme - corrections.txt" is the only such file, then <TAB>
correctly completes the whole thing.)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of files with spaces in
@ 1999-03-25 16:29 Sven Wischnowsky
  1999-03-26 11:41 ` Bruce Stephens
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 1999-03-25 16:29 UTC (permalink / raw)
  To: zsh-workers


Bruce Stephens wrote:

> With zsh-3.1.5-pws-13, zsh -f, files with spaces in don't seem to get
> quoted properly.
> 
> So if I have the file "readme - corrections.txt", and I type:
> 
>         % less read<TAB>
> 
> I get 
> 
>         % less readme - 
> 
> I was expecting the spaces to be quoted with \.
> 
> I'm sure this worked once.  What's happened?

Me -- breaking up things (my favorite pastime).

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Thu Mar 25 15:31:01 1999
+++ Src/Zle/zle_tricky.c	Thu Mar 25 17:26:47 1999
@@ -3644,7 +3646,8 @@
 		    isalt = 1;
 	}
 	if (!(ms = comp_match(fpre, fsuf, s, filecomp, &lc,
-			      (addwhat == CC_FILES || addwhat == -6),
+			      (addwhat == CC_FILES || addwhat == -6 ||
+			       addwhat == -5 || addwhat == -8),
 			      &bpl, &bsl, &isexact)))
 	    return;
 

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Completion of files with spaces in
@ 1999-03-25 16:19 Bruce Stephens
  0 siblings, 0 replies; 8+ messages in thread
From: Bruce Stephens @ 1999-03-25 16:19 UTC (permalink / raw)
  To: zsh-workers

With zsh-3.1.5-pws-13, zsh -f, files with spaces in don't seem to get
quoted properly.

So if I have the file "readme - corrections.txt", and I type:

        % less read<TAB>

I get 

        % less readme - 

I was expecting the spaces to be quoted with \.

I'm sure this worked once.  What's happened?


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1999-03-29  8:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-29  8:39 Completion of files with spaces in Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-03-26 13:37 Sven Wischnowsky
1999-03-26 13:53 ` Bruce Stephens
1999-03-26 12:45 Sven Wischnowsky
1999-03-26 13:32 ` Bruce Stephens
1999-03-25 16:29 Sven Wischnowsky
1999-03-26 11:41 ` Bruce Stephens
1999-03-25 16:19 Bruce Stephens

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).