summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-09-17 18:23:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-09-17 18:23:49 +0000
commitdc060607e9d9de14f6be02a27a4b54a2643d03a8 (patch)
treee86259f349e445697c23b956d1d432707b774656
parentba9bad6c0eedf9602da805ffcc48b3fecc30f176 (diff)
downloadzsh-dc060607e9d9de14f6be02a27a4b54a2643d03a8.tar.gz
zsh-dc060607e9d9de14f6be02a27a4b54a2643d03a8.tar.xz
zsh-dc060607e9d9de14f6be02a27a4b54a2643d03a8.zip
21730: fix metafication of nicechar and pwd
-rw-r--r--ChangeLog7
-rw-r--r--Src/builtin.c2
-rw-r--r--Src/utils.c48
3 files changed, 41 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index be9f79ec0..455f84b52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-09-17  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
+
+	* 21730: Src/builtin.c, Src/utils.c: nicechar(), used in
+	prompts and other forms of formatted output, didn't return
+	a metafied string with confusing results.  Also outputting
+	pwd didn't unmetafy it in one place.
+
 2005-09-14  Doug Kearns  <djkea2@gus.gscit.monash.edu.au>
 
 	* unposted: Completion/Unix/Command/_rake: update for version 0.6.0
diff --git a/Src/builtin.c b/Src/builtin.c
index 4bb62aa9c..cd1358614 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -699,7 +699,7 @@ bin_dirs(UNUSED(char *name), char **argv, Options ops, UNUSED(int func))
 	else
 	    fmt = " ";
 	if (OPT_ISSET(ops,'l'))
-	    fputs(pwd, stdout);
+	    zputs(pwd, stdout);
 	else
 	    fprintdir(pwd, stdout);
 	for (node = firstnode(dirstack); node; incnode(node)) {
diff --git a/Src/utils.c b/Src/utils.c
index 8b1326444..71af531c3 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -146,7 +146,7 @@ zerrmsg(const char *fmt, const char *str, int num)
 		putc('%', stderr);
 		break;
 	    case 'c':
-		fputs(nicechar(num), stderr);
+		zputs(nicechar(num), stderr);
 		break;
 	    case 'e':
 		/* print the corresponding message for this errno */
@@ -195,15 +195,21 @@ putshout(int c)
     return 0;
 }
 
-/* Turn a character into a visible representation thereof.  The visible *
- * string is put together in a static buffer, and this function returns *
- * a pointer to it.  Printable characters stand for themselves, DEL is  *
- * represented as "^?", newline and tab are represented as "\n" and     *
- * "\t", and normal control characters are represented in "^C" form.    *
- * Characters with bit 7 set, if unprintable, are represented as "\M-"  *
- * followed by the visible representation of the character with bit 7   *
- * stripped off.  Tokens are interpreted, rather than being treated as  *
- * literal characters.                                                  */
+/*
+ * Turn a character into a visible representation thereof.  The visible
+ * string is put together in a static buffer, and this function returns
+ * a pointer to it.  Printable characters stand for themselves, DEL is
+ * represented as "^?", newline and tab are represented as "\n" and
+ * "\t", and normal control characters are represented in "^C" form.
+ * Characters with bit 7 set, if unprintable, are represented as "\M-"
+ * followed by the visible representation of the character with bit 7
+ * stripped off.  Tokens are interpreted, rather than being treated as
+ * literal characters.
+ *
+ * Note that the returned string is metafied, so that it must be
+ * treated like any other zsh internal string (and not, for example,
+ * output directly).
+ */
 
 /**/
 mod_export char *
@@ -238,7 +244,17 @@ nicechar(int c)
 	c += 0x40;
     }
     done:
-    *s++ = c;
+    /*
+     * The resulting string is still metafied, so check if
+     * we are returning a character in the range that needs metafication.
+     * This can't happen if the character is printed "nicely", so
+     * this results in a maximum of two bytes total (plus the null).
+     */
+    if (itok(c)) {
+	*s++ = Meta;
+	*s++ = c ^ 32;
+    } else
+	*s++ = c;
     *s = 0;
     return buf;
 }
@@ -292,7 +308,7 @@ void
 nicefputs(char *s, FILE *f)
 {
     for (; *s; s++)
-	fputs(nicechar(STOUC(*s)), f);
+	zputs(nicechar(STOUC(*s)), f);
 }
 #endif
 
@@ -3177,7 +3193,7 @@ wcs_zputs(wchar_t const *s, FILE *stream)
 static char *
 nicedup(char const *s, int heap)
 {
-    int c, len = strlen(s) * 5;
+    int c, len = strlen(s) * 5 + 1;
     VARARR(char, buf, len);
     char *p = buf, *n;
 
@@ -3190,11 +3206,13 @@ nicedup(char const *s, int heap)
 	}
 	if (c == Meta)
 	    c = *s++ ^ 32;
+	/* The result here is metafied */
 	n = nicechar(c);
 	while(*n)
 	    *p++ = *n++;
     }
-    return metafy(buf, p - buf, (heap ? META_HEAPDUP : META_DUP));
+    *p = '\0';
+    return heap ? dupstring(buf) : ztrdup(buf);
 }
 
 /**/
@@ -3228,7 +3246,7 @@ nicezputs(char const *s, FILE *stream)
 	}
 	if (c == Meta)
 	    c = *s++ ^ 32;
-	if(fputs(nicechar(c), stream) < 0)
+	if(zputs(nicechar(c), stream) < 0)
 	    return EOF;
     }
     return 0;