Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Chatty little precompiler for _arguments
- X-seq: zsh-workers 8023
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: Chatty little precompiler for _arguments
- Date: Thu, 23 Sep 1999 12:28:16 +0200 (MET DST)
- In-reply-to: Tanaka Akira's message of 23 Sep 1999 10:39:25 +0900
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Tanaka Akira wrote:
> Also I suppose that `${(qqqq)foo}' should quote foo in $'...' style.
> # I really want this because I frequently use dangeraous characters
> # such as NUL.
This is the easiest solution, just using existing functions (well, not
really existing: I have added nicedupstring() which is like the
existing niceztrdup() but uses heap memory).
The result is maybe not want one wants exactly, e.g. a NUL is printed
as `^@' (its the format used by `bindkey'). Is that ok?
Bye
Sven
diff -u os/subst.c Src/subst.c
--- os/subst.c Thu Sep 23 10:18:57 1999
+++ Src/subst.c Thu Sep 23 11:55:06 1999
@@ -1618,8 +1618,8 @@
opts[PROMPTPERCENT] = opp;
}
if (quotemod) {
- if (--quotetype > 2)
- quotetype = 2;
+ if (--quotetype > 3)
+ quotetype = 3;
if (isarr) {
char **ap;
@@ -1628,7 +1628,10 @@
ap = aval;
if (quotemod > 0) {
- if (quotetype) {
+ if (quotetype == 3)
+ for (; *ap; ap++)
+ *ap = nicedupstring(*ap);
+ else if (quotetype) {
int sl;
char *tmp;
@@ -1665,7 +1668,9 @@
if (!copied)
val = dupstring(val), copied = 1;
if (quotemod > 0) {
- if (quotetype) {
+ if (quotetype == 3)
+ val = nicedupstring(val);
+ else if (quotetype) {
int sl;
char *tmp;
diff -u os/utils.c Src/utils.c
--- os/utils.c Thu Sep 23 11:13:42 1999
+++ Src/utils.c Thu Sep 23 11:57:13 1999
@@ -2867,12 +2867,12 @@
/* Create a visibly-represented duplicate of a string. */
/**/
-char *
-niceztrdup(char const *s)
+static char *
+nicedup(char const *s, int heap)
{
int c, len = strlen(s) * 5;
- char *buf = zalloc(len);
- char *p = buf, *n, *ret;
+ VARARR(char, buf, len);
+ char *p = buf, *n;
while ((c = *s++)) {
if (itok(c)) {
@@ -2887,9 +2887,21 @@
while(*n)
*p++ = *n++;
}
- ret = metafy(buf, p - buf, META_DUP);
- zfree(buf, len);
- return ret;
+ return metafy(buf, p - buf, (heap ? META_HEAPDUP : META_DUP));
+}
+
+/**/
+char *
+niceztrdup(char const *s)
+{
+ return nicedup(s, 0);
+}
+
+/**/
+char *
+nicedupstring(char const *s)
+{
+ return nicedup(s, 1);
}
/* Unmetafy and output a string, displaying special characters readably. */
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo Wed Sep 22 17:12:32 1999
+++ Doc/Zsh/expn.yo Thu Sep 23 12:01:59 1999
@@ -584,7 +584,9 @@
item(tt(q))(
Quote the resulting words with backslashes. If this flag is given
twice, the resulting words are quoted in single quotes and if it is
-given three times, the words are quoted in double quotes.
+given three times, the words are quoted in double quotes. If it is
+given four times, no real quoting is done, but any special characters
+in the resulting words will be in a human-readable form.
)
item(tt(Q))(
Remove one level of quotes from the resulting words.
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author