From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: print -D and ${(D)} quoting
Date: Tue, 12 Oct 2010 21:53:39 +0100 [thread overview]
Message-ID: <20101012215339.26037042@pws-pc> (raw)
In-Reply-To: <4637.1286902367@csr.com>
Here, I think, is the uncontroversial part, that changes the (D)
substitution flag.
I spent some time wondering whether finddir() took an unmetafied or a
metafied path, and eventually decided it was metafied. This resulted in
one fix and various notes elsewhere; it means the current "print -D" code
is actually broken in this respect.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.119
diff -p -u -r1.119 expn.yo
--- Doc/Zsh/expn.yo 2 Sep 2010 08:46:27 -0000 1.119
+++ Doc/Zsh/expn.yo 12 Oct 2010 20:48:01 -0000
@@ -774,8 +774,10 @@ that result from field splitting.
)
item(tt(D))(
Assume the string or array elements contain directories and attempt
-to substitute the leading part of these by names. This is the reverse
-of `tt(~)' substitution: see
+to substitute the leading part of these by names. The remainder of
+the path (the whole of it if the leading part was not subsituted)
+is then quoted so that the whole string can be used as a shell
+argument. This is the reverse of `tt(~)' substitution: see
ifnzman(noderef(Filename Expansion))\
ifzman(the section FILENAME EXPANSION below).
)
Index: Functions/Chpwd/cdr
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Chpwd/cdr,v
retrieving revision 1.1
diff -p -u -r1.1 cdr
--- Functions/Chpwd/cdr 9 Jul 2010 14:47:48 -0000 1.1
+++ Functions/Chpwd/cdr 12 Oct 2010 20:48:01 -0000
@@ -291,7 +291,7 @@ if (( list )); then
dirs=($reply)
for (( i = 1; i <= ${#dirs}; i++ )); do
print -n ${(r.5.)i}
- print -D ${dirs[i]}
+ print -r ${(D)dirs[i]}
done
return
fi
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.244
diff -p -u -r1.244 builtin.c
--- Src/builtin.c 19 Sep 2010 19:20:33 -0000 1.244
+++ Src/builtin.c 12 Oct 2010 20:48:02 -0000
@@ -3704,6 +3704,7 @@ bin_print(char *name, char **args, Optio
Nameddir d;
queue_signals();
+ /* TODO: finddir takes a metafied file */
d = finddir(args[n]);
if(d) {
int dirlen = strlen(d->dir);
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.245
diff -p -u -r1.245 utils.c
--- Src/utils.c 15 Jul 2010 18:44:13 -0000 1.245
+++ Src/utils.c 12 Oct 2010 20:48:03 -0000
@@ -807,6 +807,8 @@ fprintdir(char *s, FILE *f)
/*
* Substitute a directory using a name.
* If there is none, return the original argument.
+ *
+ * At this level all strings involved are metafied.
*/
/**/
@@ -816,8 +818,9 @@ substnamedir(char *s)
Nameddir d = finddir(s);
if (!d)
- return s;
- return zhtricat("~", d->node.nam, s + strlen(d->dir));
+ return quotestring(s, NULL, QT_BACKSLASH);
+ return zhtricat("~", d->node.nam, quotestring(s + strlen(d->dir),
+ NULL, QT_BACKSLASH));
}
@@ -874,9 +877,13 @@ finddir_scan(HashNode hn, UNUSED(int fla
}
}
-/* See if a path has a named directory as its prefix. *
- * If passed a NULL argument, it will invalidate any *
- * cached information. */
+/*
+ * See if a path has a named directory as its prefix.
+ * If passed a NULL argument, it will invalidate any
+ * cached information.
+ *
+ * s here is metafied.
+ */
/**/
Nameddir
@@ -915,9 +922,7 @@ finddir(char *s)
scanhashtable(nameddirtab, 0, 0, 0, finddir_scan, 0);
if (func) {
- char *dir_meta = metafy(finddir_full, strlen(finddir_full),
- META_ALLOC);
- char **ares = subst_string_by_func(func, "d", dir_meta);
+ char **ares = subst_string_by_func(func, "d", finddir_full);
int len;
if (ares && arrlen(ares) >= 2 &&
(len = (int)zstrtol(ares[1], NULL, 10)) > finddir_best) {
@@ -928,8 +933,6 @@ finddir(char *s)
finddir_last->diff = len - strlen(finddir_last->node.nam);
finddir_best = len;
}
- if (dir_meta != finddir_full)
- zsfree(dir_meta);
}
return finddir_last;
@@ -1039,6 +1042,10 @@ getnameddir(char *name)
return NULL;
}
+/*
+ * Compare directories. Both are metafied.
+ */
+
/**/
static int
dircmp(char *s, char *t)
@@ -4607,7 +4614,7 @@ addunprintable(char *v, const char *u, c
}
/*
- * Quote the string s and return the result.
+ * Quote the string s and return the result as a string from the heap.
*
* If e is non-zero, the
* pointer it points to may point to a position in s and in e the position
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
next prev parent reply other threads:[~2010-10-12 21:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-12 16:52 Peter Stephenson
2010-10-12 20:53 ` Peter Stephenson [this message]
2010-10-13 1:56 ` Bart Schaefer
2010-10-13 9:04 ` Peter Stephenson
2010-10-13 16:14 ` Bart Schaefer
2010-10-13 16:45 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101012215339.26037042@pws-pc \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).