Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completion of mixed-style paths still doesn't work under Cygwin with 4.3.10-dev-1



On Wed, 13 Jan 2010 10:25:54 +0000
Peter Stephenson <pws@xxxxxxx> wrote:
> On Tue, 12 Jan 2010 21:52:10 +0100
> Vadim Zeitlin <vz-zsh@xxxxxxxxxxxx> wrote:
>> [completing after c:/ doesn't work sometimes]
>
>> I built zsh using "--enable-pcre --enable-multibyte" under Cygwin 1.7.1.
>> Should I have used different configure options? Or maybe it's 1.7-specific?

It does appear to be a new feature which is easy enough to work around.
It looks like "c:" is no longer regarded as a directory while "c:/"
still is (try it with [[ -d c: ]] if you want to play along at home).
This may be part of the attempt to make Windows special characters less
special.

I've now escaped back to Linux: here's a patch that seemed to work,
except I've only just realised that I'd better limit the slash-appending
to single-letter drives---someone may know better---so that isn't
tested.  We stick the "/" back for the purpose of testing the directory,
but only for that purpose (the completion system will get a bit confused
if we append directories willy nilly).

I presume this still works in earlier versions of Cygwin.

Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.117
diff -u -r1.117 computil.c
--- Src/Zle/computil.c	21 Nov 2009 06:51:14 -0000	1.117
+++ Src/Zle/computil.c	22 Jan 2010 20:32:48 -0000
@@ -4050,19 +4050,44 @@
     for (node = firstnode(names); node; incnode(node)) {
 	l = strlen(p = (char *) getdata(node));
 	if (l + sl < PATH_MAX2) {
+#ifdef __CYGWIN__
+	    char *testbuf;
+#define TESTBUF testbuf
+#else
+#define TESTBUF buf
+#endif
 	    strcpy(buf, p);
 	    strcpy(buf + l, suf);
 #ifdef __CYGWIN__
-	    /*
-	     * If accept-exact is not set, accept this only if
-	     * it looks like a special file such as a drive.
-	     * We still test if it exists.
-	     */
-	    if (accept_off &&
-		(strchr(buf, '/') || buf[strlen(buf)-1] != ':'))
-		continue;
+	    if (accept_off) {
+		int sl = strlen(buf);
+		/*
+		 * If accept-exact is not set, accept this only if
+		 * it looks like a special file such as a drive.
+		 * We still test if it exists.
+		 */
+		if (!sl || strchr(buf, '/') || buf[sl-1] != ':')
+		    continue;
+		if (sl == 2) {
+		    /*
+		     * Recent versions of Cygwin only recognise "c:/",
+		     * but not "c:", as special directories.  So
+		     * we have to append the slash for the purpose of
+		     * the test.
+		     */
+		    testbuf = zhalloc(sl + 2);
+		    strcpy(testbuf, buf);
+		    testbuf[sl] = '/';
+		    testbuf[sl+1] = '\0';
+		} else {
+		    /* Don't do this with stuff like PRN: */
+		    testbuf = buf;
+		}
+	    } else {
+		testbuf = buf;
+	    }
 #endif
-	    if (!ztat(buf, &st, 0)) {
+	    if (!ztat(TESTBUF, &st, 0)) {
 		/*
 		 * File exists; if accept-exact contained non-boolean
 		 * values it must match those, too.



-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author