zsh-workers
 help / color / mirror / code / Atom feed
* Re: Chatty little precompiler for _arguments
@ 1999-09-20  8:43 Sven Wischnowsky
  1999-09-20 12:15 ` PATCH: was: " Sven Wischnowsky
  1999-09-23  1:39 ` Tanaka Akira
  0 siblings, 2 replies; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-20  8:43 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> though it would be really useful if $param:q could emit quoting instead of
> backslashes.

I would be against this because its much less useful in cases where
you stuff together string from multiple parameters. However, in its
first life `:q' did that and we could use the doubled-flag convention
so that `${(qq)foo}' would emit stuff in single quotes. (Tripled for
double quotes?)

Bye
 Sven


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


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

* PATCH: was: Re: Chatty little precompiler for _arguments
@ 1999-09-20 12:15 ` Sven Wischnowsky
  1999-09-20 16:36   ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-20 12:15 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> Bart Schaefer wrote:
> 
> > though it would be really useful if $param:q could emit quoting instead of
> > backslashes.
> 
> I would be against this because its much less useful in cases where
> you stuff together string from multiple parameters. However, in its
> first life `:q' did that and we could use the doubled-flag convention
> so that `${(qq)foo}' would emit stuff in single quotes. (Tripled for
> double quotes?)

This does that. `${(qqq)foo}' looks a bit silly doesn't it?

Bye
 Sven

--- os/subst.c	Mon Sep 20 13:53:20 1999
+++ Src/subst.c	Mon Sep 20 14:05:41 1999
@@ -721,7 +721,7 @@
     int flnum = 0;
     int sortit = 0, casind = 0;
     int casmod = 0;
-    int quotemod = 0, quoteerr = 0;
+    int quotemod = 0, quotetype = 0, quoteerr = 0;
     char *sep = NULL, *spsep = NULL;
     char *premul = NULL, *postmul = NULL, *preone = NULL, *postone = NULL;
     char *replstr = NULL;	/* replacement string for /orig/repl */
@@ -826,7 +826,7 @@
 		    break;
 
 		case 'q':
-		    quotemod++;
+		    quotemod++, quotetype++;
 		    break;
 		case 'Q':
 		    quotemod--;
@@ -1617,6 +1617,8 @@
 	opts[PROMPTPERCENT] = opp;
     }
     if (quotemod) {
+	if (--quotetype > 2)
+	    quotetype = 2;
 	if (isarr) {
 	    char **ap;
 
@@ -1624,10 +1626,23 @@
 		aval = arrdup(aval), copied = 1;
 	    ap = aval;
 
-	    if (quotemod > 0)
-		for (; *ap; ap++)
-		    *ap = bslashquote(*ap, NULL, 0);
-	    else {
+	    if (quotemod > 0) {
+		if (quotetype) {
+		    int sl;
+		    char *tmp;
+
+		    for (; *ap; ap++) {
+			tmp = bslashquote(*ap, NULL, quotetype);
+			sl = strlen(tmp);
+			*ap = (char *) zhalloc(sl + 3);
+			strcpy((*ap) + 1, tmp);
+			ap[0][0] = ap[0][sl + 1] = (quotetype == 1 ? '\'' : '"');
+			ap[0][sl + 2] = '\0';
+		    }
+		} else
+		    for (; *ap; ap++)
+			*ap = bslashquote(*ap, NULL, 0);
+	    } else {
 		int one = noerrs, oef = errflag, haserr = 0;
 
 		if (!quoteerr)
@@ -1648,9 +1663,20 @@
 	} else {
 	    if (!copied)
 		val = dupstring(val), copied = 1;
-	    if (quotemod > 0)
-		val = bslashquote(val, NULL, 0);
-	    else {
+	    if (quotemod > 0) {
+		if (quotetype) {
+		    int sl;
+		    char *tmp;
+
+		    tmp = bslashquote(val, NULL, quotetype);
+		    sl = strlen(tmp);
+		    val = (char *) zhalloc(sl + 3);
+		    strcpy(val + 1, tmp);
+		    val[0] = val[sl + 1] = (quotetype == 1 ? '\'' : '"');
+		    val[sl + 2] = '\0';
+		} else
+		    val = bslashquote(val, NULL, 0);
+	    } else {
 		int one = noerrs, oef = errflag, haserr;
 
 		if (!quoteerr)
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo	Mon Sep 20 13:06:32 1999
+++ Doc/Zsh/expn.yo	Mon Sep 20 14:14:20 1999
@@ -582,7 +582,9 @@
 that result from field splitting.
 )
 item(tt(q))(
-Quote the resulting words with backslashes.
+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.
 )
 item(tt(Q))(
 Remove one level of quotes from the resulting words.

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


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

* Re: Chatty little precompiler for _arguments
  1999-09-20 12:15 ` PATCH: was: " Sven Wischnowsky
@ 1999-09-20 16:36   ` Bart Schaefer
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 1999-09-20 16:36 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Sep 20, 10:43am, Sven Wischnowsky wrote:
} Subject: Re: Chatty little precompiler for _arguments
}
} Bart Schaefer wrote:
} 
} > though it would be really useful if $param:q could emit quoting instead of
} > backslashes.
} 
} I would be against this because its much less useful in cases where
} you stuff together string from multiple parameters.

I'm not sure what you're getting at, there.

With 7951 applied, compare:

    print -R ${(q):-"$histchars $WORDCHARS $SPROMPT $TIMEFMT"}
    print -R ${(qq):-"$histchars $WORDCHARS $SPROMPT $TIMEFMT"}
    print -R ${(qqq):-"$histchars $WORDCHARS $SPROMPT $TIMEFMT"}

On Sep 20,  2:15pm, Sven Wischnowsky wrote:
} Subject: PATCH: was: Re: Chatty little precompiler for _arguments
}
} This does that. `${(qqq)foo}' looks a bit silly doesn't it?

The man who wrote

${(@)^${(@)${(@)${(@M)${(@ps:\n:j:\n:)${(@)${(@M)${(@f)$(${~words[1]} --help 2>&1)//\[--/
--}:#[ 	]#-*}//,/
}}:#[ 	]#--*}#*--}%%[, ]*}:#}

wants to talk about "looks a bit silly"?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Chatty little precompiler for _arguments
  1999-09-20  8:43 Chatty little precompiler for _arguments Sven Wischnowsky
  1999-09-20 12:15 ` PATCH: was: " Sven Wischnowsky
@ 1999-09-23  1:39 ` Tanaka Akira
  1 sibling, 0 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-23  1:39 UTC (permalink / raw)
  To: zsh-workers

In article <199909200843.KAA06289@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> I would be against this because its much less useful in cases where
> you stuff together string from multiple parameters. However, in its
> first life `:q' did that and we could use the doubled-flag convention
> so that `${(qq)foo}' would emit stuff in single quotes. (Tripled for
> double quotes?)

I found a problem about quoting.

Z(2):akr@is27e1u11% Src/zsh -f
is27e1u11% a=$'\n\n\n\n\n\n'
is27e1u11% print -lr - ${(q)a}
zsh: segmentation fault (core dumped)  Src/zsh -f

Also I suppose that `${(qqqq)foo}' should quote foo in $'...' style.
# I really want this because I frequently use dangeraous characters
# such as NUL.
-- 
Tanaka Akira


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

* Re: Chatty little precompiler for _arguments
  1999-09-23 15:12   ` Bart Schaefer
@ 1999-09-25  2:53     ` Tanaka Akira
  0 siblings, 0 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-25  2:53 UTC (permalink / raw)
  To: zsh-workers

In article <990923151211.ZM26950@candle.brasslantern.com>,
  "Bart Schaefer" <schaefer@candle.brasslantern.com> writes:

> Further, with extendedglob, the output of ${(qqqq)...} can't be "eval"d
> without quoting it yet again, because ^ is a metacharacter.  So maybe
> we should use a different letter -- perhaps ${(v)...} like cat? -- for
> Sven's (qqqq).

The patch follows implement (qqqq) intended by me.  Sven's (qqqq) is
changed to (V) because (v) is already used for associative array
values.

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /projects/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.1.1.37
diff -u -F^( -r1.1.1.37 expn.yo
--- Doc/Zsh/expn.yo	1999/09/23 13:21:09	1.1.1.37
+++ Doc/Zsh/expn.yo	1999/09/25 02:44:35
@@ -581,12 +581,14 @@ (see below) is applied using the rules f
 of alphanumeric characters separated by non-alphanumerics, em(not) to words
 that result from field splitting.
 )
+item(tt(V))(
+Make any special characters in the resulting words visible.
+)
 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. 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.
+given four times, the words are quoted in single quotes preceded a tt($).
 )
 item(tt(Q))(
 Remove one level of quotes from the resulting words.
Index: Src/subst.c
===================================================================
RCS file: /projects/zsh/zsh/Src/subst.c,v
retrieving revision 1.1.1.42
diff -u -F^( -r1.1.1.42 subst.c
--- Src/subst.c	1999/09/23 13:21:36	1.1.1.42
+++ Src/subst.c	1999/09/25 02:44:36
@@ -723,6 +723,7 @@
     int sortit = 0, casind = 0;
     int casmod = 0;
     int quotemod = 0, quotetype = 0, quoteerr = 0;
+    int visiblemod = 0;
     char *sep = NULL, *spsep = NULL;
     char *premul = NULL, *postmul = NULL, *preone = NULL, *postone = NULL;
     char *replstr = NULL;	/* replacement string for /orig/repl */
@@ -826,6 +827,10 @@
 		    casind = 1;
 		    break;
 
+		case 'V':
+		    visiblemod++;
+		    break;
+
 		case 'q':
 		    quotemod++, quotetype++;
 		    break;
@@ -1628,20 +1633,20 @@
 	    ap = aval;
 
 	    if (quotemod > 0) {
-		if (quotetype == 3)
-		    for (; *ap; ap++)
-			*ap = nicedupstring(*ap);
-		else if (quotetype) {
+		if (quotetype) {
 		    int sl;
 		    char *tmp;
 
 		    for (; *ap; ap++) {
+			int pre = quotetype != 3 ? 1 : 2;
 			tmp = bslashquote(*ap, NULL, quotetype);
 			sl = strlen(tmp);
-			*ap = (char *) zhalloc(sl + 3);
-			strcpy((*ap) + 1, tmp);
-			ap[0][0] = ap[0][sl + 1] = (quotetype == 1 ? '\'' : '"');
-			ap[0][sl + 2] = '\0';
+			*ap = (char *) zhalloc(pre + sl + 2);
+			strcpy((*ap) + pre, tmp);
+			ap[0][pre - 1] = ap[0][pre + sl] = (quotetype != 2 ? '\'' : '"');
+			ap[0][pre + sl + 1] = '\0';
+			if (quotetype == 3)
+			  ap[0][0] = '$';
 		    }
 		} else
 		    for (; *ap; ap++)
@@ -1668,18 +1673,19 @@
 	    if (!copied)
 		val = dupstring(val), copied = 1;
 	    if (quotemod > 0) {
-		if (quotetype == 3)
-		    val = nicedupstring(val);
-		else if (quotetype) {
+		if (quotetype) {
+		    int pre = quotetype != 3 ? 1 : 2;
 		    int sl;
 		    char *tmp;
 
 		    tmp = bslashquote(val, NULL, quotetype);
 		    sl = strlen(tmp);
-		    val = (char *) zhalloc(sl + 3);
-		    strcpy(val + 1, tmp);
-		    val[0] = val[sl + 1] = (quotetype == 1 ? '\'' : '"');
-		    val[sl + 2] = '\0';
+		    val = (char *) zhalloc(pre + sl + 2);
+		    strcpy(val + pre, tmp);
+		    val[pre - 1] = val[pre + sl] = (quotetype != 2 ? '\'' : '"');
+		    val[pre + sl + 1] = '\0';
+		    if (quotetype == 3)
+		      val[0] = '$';
 		} else
 		    val = bslashquote(val, NULL, 0);
 	    } else {
@@ -1698,6 +1704,19 @@
 		remnulargs(val);
 		untokenize(val);
 	    }
+	}
+    }
+    if (visiblemod) {
+	if (isarr) {
+	    char **ap;
+	    if (!copied)
+		aval = arrdup(aval), copied = 1;
+	    for (ap = aval; *ap; ap++)
+		*ap = nicedupstring(*ap);
+	} else {
+	    if (!copied)
+		val = dupstring(val), copied = 1;
+	    val = nicedupstring(val);
 	}
     }
     if (isarr) {
Index: Src/utils.c
===================================================================
RCS file: /projects/zsh/zsh/Src/utils.c,v
retrieving revision 1.1.1.32
diff -u -F^( -r1.1.1.32 utils.c
--- Src/utils.c	1999/09/24 12:54:44	1.1.1.32
+++ Src/utils.c	1999/09/25 02:44:36
@@ -2984,7 +2984,64 @@
     for (; *u; u++) {
 	if (e && *e == u)
 	    *e = v, sf = 1;
-	if (ispecial(*u) &&
+	if (instring == 3) {
+	  int c = *u;
+	  if (c == Meta) {
+	    c = *++u ^ 32;
+	  }
+	  c &= 0xff;
+	  if(isprint(c)) {
+	    switch (c) {
+	    case '\\':
+	    case '\'':
+	      *v++ = '\\';
+	      *v++ = c;
+	      break;
+
+	    default:
+	      if(imeta(c)) {
+		*v++ = Meta;
+		*v++ = c ^ 32;
+	      }
+	      else {
+		if (isset(BANGHIST) && c == bangchar) {
+		  *v++ = '\\';
+		}
+		*v++ = c;
+	      }
+	      break;
+	    }
+	  }
+	  else {
+	    switch (c) {
+	    case '\0':
+	      *v++ = '\\';
+	      *v++ = '0';
+	      if ('0' <= u[1] && u[1] <= '7') {
+		*v++ = '0';
+		*v++ = '0';
+	      }
+	      break;
+
+	    case '\007': *v++ = '\\'; *v++ = 'a'; break;
+	    case '\b': *v++ = '\\'; *v++ = 'b'; break;
+	    case '\f': *v++ = '\\'; *v++ = 'f'; break;
+	    case '\n': *v++ = '\\'; *v++ = 'n'; break;
+	    case '\r': *v++ = '\\'; *v++ = 'r'; break;
+	    case '\t': *v++ = '\\'; *v++ = 't'; break;
+	    case '\v': *v++ = '\\'; *v++ = 'v'; break;
+
+	    default:
+	      *v++ = '\\';
+	      *v++ = '0' + ((c >> 6) & 7);
+	      *v++ = '0' + ((c >> 3) & 7);
+	      *v++ = '0' + (c & 7);
+	      break;
+	    }
+	  }
+	  continue;
+	}
+	else if (ispecial(*u) &&
 	    (!instring ||
 	     (isset(BANGHIST) && *u == (char)bangchar) ||
 	     (instring == 2 &&
-- 
Tanaka Akira


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

* Re: Chatty little precompiler for _arguments
  1999-09-23 14:12 ` Tanaka Akira
@ 1999-09-23 15:12   ` Bart Schaefer
  1999-09-25  2:53     ` Tanaka Akira
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 1999-09-23 15:12 UTC (permalink / raw)
  To: Tanaka Akira, zsh-workers

On Sep 23, 11:12pm, Tanaka Akira wrote:
} Subject: Re: Chatty little precompiler for _arguments
}
} In article <199909231028.MAA24049@beta.informatik.hu-berlin.de>,
}   Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
} 
} > 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?
} 
} No. I want the form which result of expansion is original string.

Well, somebody offline just asked me about implementing "cat -v" entirely
within zsh, so I'm actually pretty happy with what Sven did.  Although I
begin to think that five q might be going a little overboard to add what
Tanaka wants as well.

Further, with extendedglob, the output of ${(qqqq)...} can't be "eval"d
without quoting it yet again, because ^ is a metacharacter.  So maybe
we should use a different letter -- perhaps ${(v)...} like cat? -- for
Sven's (qqqq).

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Chatty little precompiler for _arguments
  1999-09-23 10:28 Sven Wischnowsky
@ 1999-09-23 14:12 ` Tanaka Akira
  1999-09-23 15:12   ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Tanaka Akira @ 1999-09-23 14:12 UTC (permalink / raw)
  To: zsh-workers

In article <199909231028.MAA24049@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> 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?

No. I want the form which result of expansion is original string.

is27e1u11% print -lr - ${(qqqq):-$'\0'}
^@
is27e1u11% 

should be

is27e1u11% print -lr - ${(qqqq):-$'\0'}
$'\0'
is27e1u11% 

My expected use is in _regex_arguments. It generate cache file
containing zsh function and it validates itself by comparing the
arguments between compile time and load time when it is sourced. So
the cache file contains NULs because arguments contain NULs. I want to
avoid NULs from cache files because it makes viewing (and editing) the
file bit hard.
-- 
Tanaka Akira


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

* Re: Chatty little precompiler for _arguments
@ 1999-09-23 14:07 Sven Wischnowsky
  0 siblings, 0 replies; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-23 14:07 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> In article <199909230913.LAA23608@beta.informatik.hu-berlin.de>,
>   Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> 
> > The longest string a character can be quoted to is three characters...
> 
> It's not longest, in current implementation at least.
> 
> Z:akr@is27e1u11% Src/zsh -f
> is27e1u11% a="'''''''''''"
> is27e1u11% print -lr - ${(qq)a}
> zsh: segmentation fault (core dumped)  Src/zsh -f
> Z:akr@is27e1u11% 

Ouch.

Bye
 Sven

--- os/utils.c	Thu Sep 23 12:30:20 1999
+++ Src/utils.c	Thu Sep 23 16:05:22 1999
@@ -2976,7 +2976,7 @@
 {
     const char *u, *tt;
     char *v;
-    char *buf = ncalloc(3 * strlen(s) + 1);
+    char *buf = ncalloc(4 * strlen(s) + 1);
     int sf = 0;
 
     tt = v = buf;

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


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

* Re: Chatty little precompiler for _arguments
  1999-09-23  9:13 Sven Wischnowsky
@ 1999-09-23 13:57 ` Tanaka Akira
  0 siblings, 0 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-23 13:57 UTC (permalink / raw)
  To: zsh-workers

In article <199909230913.LAA23608@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> The longest string a character can be quoted to is three characters...

It's not longest, in current implementation at least.

Z:akr@is27e1u11% Src/zsh -f
is27e1u11% a="'''''''''''"
is27e1u11% print -lr - ${(qq)a}
zsh: segmentation fault (core dumped)  Src/zsh -f
Z:akr@is27e1u11% 
-- 
Tanaka Akira


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

* Re: Chatty little precompiler for _arguments
@ 1999-09-23 10:28 Sven Wischnowsky
  1999-09-23 14:12 ` Tanaka Akira
  0 siblings, 1 reply; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-23 10:28 UTC (permalink / raw)
  To: zsh-workers


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@informatik.hu-berlin.de


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

* Re: Chatty little precompiler for _arguments
@ 1999-09-23  9:13 Sven Wischnowsky
  1999-09-23 13:57 ` Tanaka Akira
  0 siblings, 1 reply; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-23  9:13 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> In article <199909200843.KAA06289@beta.informatik.hu-berlin.de>,
>   Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> 
> > I would be against this because its much less useful in cases where
> > you stuff together string from multiple parameters. However, in its
> > first life `:q' did that and we could use the doubled-flag convention
> > so that `${(qq)foo}' would emit stuff in single quotes. (Tripled for
> > double quotes?)
> 
> I found a problem about quoting.
> 
> Z(2):akr@is27e1u11% Src/zsh -f
> is27e1u11% a=$'\n\n\n\n\n\n'
> is27e1u11% print -lr - ${(q)a}
> zsh: segmentation fault (core dumped)  Src/zsh -f
> 
> Also I suppose that `${(qqqq)foo}' should quote foo in $'...' style.
> # I really want this because I frequently use dangeraous characters
> # such as NUL.

The longest string a character can be quoted to is three characters...

Bye
 Sven

--- os/utils.c	Thu Sep 23 10:18:58 1999
+++ Src/utils.c	Thu Sep 23 11:04:51 1999
@@ -2964,7 +2964,7 @@
 {
     const char *u, *tt;
     char *v;
-    char *buf = ncalloc(2 * strlen(s) + 1);
+    char *buf = ncalloc(3 * strlen(s) + 1);
     int sf = 0;
 
     tt = v = buf;

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


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

* Re: Chatty little precompiler for _arguments
@ 1999-09-21  7:15 Sven Wischnowsky
  0 siblings, 0 replies; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-21  7:15 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Sep 20, 10:43am, Sven Wischnowsky wrote:
> } Subject: Re: Chatty little precompiler for _arguments
> }
> } Bart Schaefer wrote:
> } 
> } > though it would be really useful if $param:q could emit quoting instead of
> } > backslashes.
> } 
> } I would be against this because its much less useful in cases where
> } you stuff together string from multiple parameters.
> 
> I'm not sure what you're getting at, there.

I was thinking about uses as in `_path_files' where we have
`$linepath${testpath:q}' (yes, this could be changed to `(q)' some
time). The only thing I wanted to point out that having *only* the
put-in-quotes style would be ugly in such cases (and I knew about the
`${:-...}' trick, of course, but in contexts like `_pth_files' I would 
like to avoid the quotes altogether).

And I didn't want to say that I would be against changing the
behaviour of `:q' as long as we still have the possibility to get
backslashes with the `(q)' flag.

> On Sep 20,  2:15pm, Sven Wischnowsky wrote:
> } Subject: PATCH: was: Re: Chatty little precompiler for _arguments
> }
> } This does that. `${(qqq)foo}' looks a bit silly doesn't it?
> 
> The man who wrote
> 
> ${(@)^${(@)${(@)${(@M)${(@ps:\n:j:\n:)${(@)${(@M)${(@f)$(${~words[1]} --help 2>&1)//\[--/
> --}:#[ 	]#-*}//,/
> }}:#[ 	]#--*}#*--}%%[, ]*}:#}
> 
> wants to talk about "looks a bit silly"?

;-)


Bye
 Sven


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


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

* Re: Chatty little precompiler for _arguments
@ 1999-09-20 12:57 Sven Wischnowsky
  0 siblings, 0 replies; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-20 12:57 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> For your consideration ... if _arguments gets converted into C code, I'd like
> to see an interface something like this available for it (in addtion to the
> more compact/cryptic one).  Before that happens, it's probably not efficient
> to use this kind of thing for anything but testing.

Btw, after having a look at `_arguments' when this first came up: if I
ever come to this, I wouldn't turn the whole of `_arguments' into C,
but instead add only support for the argument- and command-line-parsing.
Probably made a bit more generic so that we could use this is other
places, too.

Has anyone had ideas for other things we might want to add support in
C for?

Bye
 Sven


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


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

* Chatty little precompiler for _arguments
@ 1999-09-19 22:57 Bart Schaefer
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 1999-09-19 22:57 UTC (permalink / raw)
  To: zsh-workers

For your consideration ... if _arguments gets converted into C code, I'd like
to see an interface something like this available for it (in addtion to the
more compact/cryptic one).  Before that happens, it's probably not efficient
to use this kind of thing for anything but testing.

An extremely useful dual of this would be an _arg_explain that takes exactly
the same arguments as _arguments, but outputs this little language; so one
could check that what one wrote is really what one meant.  I'm probably not
going to get around to writing that anytime soon, but maybe someone else ...
though it would be really useful if $param:q could emit quoting instead of
backslashes.

If anyone feels inspired to tackle the TODOs, go ahead.

Also below is a fix for a rather amusing typo in a comment in _describe.

Index: Completion/Base/_arg_compile
===================================================================
@@ -0,0 +1,199 @@
+#autoload
+
+# A simple compiler for _arguments descriptions.  The first argument of
+# _arg_compile is the name of an array parameter in which the parse is
+# returned.  The remaining arguments form a series of `phrases'.  Each
+# `phrase' begins with one of the keywords "argument", "option", or "help"
+# and consists of a series of keywords and/or values.  The syntax is as
+# free-form as possible, but "argument" phrases generally must appear in
+# the same relative position as the corresponding argument on the command
+# line to be completed, and there are some restrictions on ordering of
+# keywords and values within each phrase.
+#
+# Anything appearing before the first phrase or after the last is passed
+# through verbatim.  (See TODO.)  If more detailed mixing of compiled and
+# uncompiled fragments is necessary, use two or more calls, either with
+# different array names or by passing the output of each previous call
+# through the next.
+#
+# In the documentation below, brackets [ ] indicate optional elements and
+# braces { } indicate elements that may be repeated zero or more times.
+# Except as noted, bracketed or braced elements may appear in any order
+# relative to each other, but tokens within each element are ordered.
+#
+#   argument [POS] [means MSG] [action ACT]
+#
+#     POS may be an integer N for the Nth argument or "*" for all, and
+#      must appear first if it appears at all.
+#     MSG is a string to be displayed above the matches in a listing.
+#     ACT is (currently) as described in the compsys manual.
+#
+#   option OPT [follow HOW] [explain STR] {unless XOR} \
+#    {[means MSG] [action ACT]} [through PAT [means MSG] [action ACT]]
+#
+#     OPT is the option, prefixed with "*" if it may appear more than once.
+#     HOW refers to a following argument, and may be one of:
+#       "close"   must appear in the same word (synonyms "join" or "-")
+#       "next"    the argument must appear in the next word (aka "split")
+#       "loose"   the argument may appear in the same or the next word ("+")
+#       "assign"  as loose, but must follow an "=" in the same word ("=")
+#     HOW should be suffixed with a colon if the following argument is
+#      _not_ required to appear.
+#     STR is to be displayed based on compconfig[describe_options].
+#     XOR is another option in combination with which OPT may not appear.
+#      It may be ":" to disable non-option completions when OPT is present.
+#     MSG is a string to be displayed above the matches in a listing.
+#     ACT is (currently) as described in the compsys manual.
+#     PAT is either "*" for "all remaining words on the line" or a pattern
+#      that, if matched, marks the end of the arguments of this option.
+#      The "through PAT ..." description must be the last.
+#     PAT may be suffixed with one colon to narrow the $words array to
+#      the remainder of the command line, or with two colons to narrow
+#      to the words before (not including) the next that matches PAT.
+#
+#   help PAT [means MSG] action ACT
+#
+#     ACT is applied to any option output by --help that matches PAT.
+#      Do not use "help" with commands that do not support --help.
+#     PAT may be suffixed with a colon if the following argument is
+#      _not_ required to appear (this is usually inferred from --help).
+#     MSG is a string to be displayed above the matches in a listing.
+
+# EXAMPLE:
+# This is from _gprof in the standard distribution.  Note that because of
+# the brace expansion trick used in the "function name" case, no attempt
+# is made to use `phrase' form; that part gets passed through unchanged.
+# It could simply be moved to the _arguments call ahead of "$args[@]".
+#
+# _arg_compile args -s -{a,b,c,D,h,i,l,L,s,T,v,w,x,y,z} \
+#              -{A,C,e,E,f,F,J,n,N,O,p,P,q,Q,Z}:'function name:->funcs' \
+#              option -I means directory action _dir_list \
+#              option -d follow close means "debug level" \
+#              option -k means "function names" action '->pair' \
+#              option -m means "minimum execution count" \
+#              argument means executable action '_files -g \*\(\*\)' \
+#              argument means "profile file" action '_files -g gmon.\*' \
+#              help '*=name*' means "function name" action '->funcs' \
+#              help '*=dirs*' means "directory" action _dir_list
+# _arguments "$args[@]"
+
+# TODO:
+# Verbose forms of various actions, e.g. (but not exactly)
+#   "state foo"                  becomes "->foo"
+#   "completion X explain Y ..." becomes "((X\:Y ...))"
+#   etc.
+# Represent leading "*" in OPT some other way.
+# Represent trailing colons in HOW and PAT some other way.
+# Stricter syntax checking on HOW, sanity checks on XOR.
+# Something less obscure than "unless :" would be nice.
+# Warning or other syntax check for stuff after the last phrase.
+
+emulate -L zsh
+local -h argspec dspec helpspec prelude xor
+local -h -A amap dmap safe
+
+[[ -n "$1" ]] || return 1
+[[ ${(tP)${1}} = *-local ]] && { print -R NAME CONFLICT: $1 1>&2; return 1 }
+safe[reply]="$1"; shift
+
+# First consume and save anything before the argument phrases
+
+helpspec=()
+prelude=()
+
+while (($#))
+do
+  case $1 in
+  (argument|help|option) break;;
+  (*) prelude=("$prelude[@]" "$1"); shift;;
+  esac
+done
+
+# Consume all the argument phrases and build the argspec array
+
+while (($#))
+do
+  amap=()
+  dspec=()
+  case $1 in
+
+  # argument [POS] [means MSG] [action ACT]
+  (argument)
+    shift
+    while (($#))
+    do
+      case $1 in
+      (<1->|\*) amap[position]="$1"; shift;;
+      (means|action) amap[$1]="$2"; shift 2;;
+      (argument|option|help) break;;
+      (*) print -R SYNTAX ERROR at "$@" 1>&2; return 1;;
+      esac
+    done
+    if (( $#amap ))
+    then
+      argspec=("$argspec[@]" "${amap[position]}:${amap[means]}:${amap[action]}")
+    fi;;
+
+  # option OPT [follow HOW] [explain STR] {unless XOR} \
+  #  {[through PAT] [means MSG] [action ACT]}
+  (option)
+    amap[option]="$2"; shift 2
+    dmap=()
+    xor=()
+    while (( $# ))
+    do
+      (( ${+amap[$1]} || ${+dmap[through]} )) && break;
+      case $1 in
+      (follow)
+	amap[follow]="${2:s/join/-/:s/close/-/:s/next//:s/split//:s/loose/+/:s/assign/=/:s/none//}"
+	shift 2;;
+      (explain) amap[explain]="[$2]" ; shift 2;;
+      (unless) xor=("$xor[@]" "${(@)=2}"); shift 2;;
+      (through|means|action)
+	while (( $# ))
+	do
+	  (( ${+dmap[$1]} )) && break 2
+	  case $1 in
+	  (through|means|action) dmap[$1]=":${2}"; shift 2;;
+	  (argument|option|help|follow|explain|unless) break;;
+	  (*) print -R SYNTAX ERROR at "$@" 1>&2; return 1;;
+	  esac
+	done;;
+      (argument|option|help) break;;
+      (*) print -R SYNTAX ERROR at "$@" 1>&2; return 1;;
+      esac
+      if (( $#dmap ))
+      then
+	dspec=("$dspec[@]" "${dmap[through]}${dmap[means]:-:}${dmap[action]:-:}")
+      fi
+    done
+    if (( $#amap ))
+    then
+      argspec=("$argspec[@]" "${xor:+($xor)}${amap[option]}${amap[follow]}${amap[explain]}${dspec}")
+    fi;;
+
+  # help PAT [means MSG] action ACT
+  (help)
+    amap[pattern]="$2"; shift 2
+    while (($#))
+    do
+      (( ${+amap[$1]} )) && break;
+      case $1 in
+      (means|action) amap[$1]="$2"; shift 2;;
+      (argument|option|help) break;;
+      (*) print -R SYNTAX ERROR at "$@" 1>&2; return 1;;
+      esac
+    done
+    if (( $#amap ))
+    then
+      helpspec=("$helpspec[@]" "${amap[pattern]}:${amap[means]}:${amap[action]}")
+    fi;;
+  (*) break;;
+  esac
+done
+
+eval $safe[reply]'=( "${prelude[@]}" "${argspec[@]}" ${helpspec:+"-- ${helpspec[@]}"} "$@" )'
+
+# print -R _arguments "${prelude[@]:q}" "${argspec[@]:q}" ${helpspec:+"-- ${helpspec[@]:q}"} "$@:q"
+
+return 0
Index: Completion/Base/_describe
===================================================================
@@ -24,7 +24,7 @@
 
 if [[ -n "$isopt" ]]; then
 
-  # We take the value to test the number of patches from a non-local
+  # We take the value to test the number of matches from a non-local
   # parameter `nm' if that exists and contains only digits. It's a hack.
 
   if [[ "$nm" = [0-9]## ]]; then

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

end of thread, other threads:[~1999-09-25  2:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-20  8:43 Chatty little precompiler for _arguments Sven Wischnowsky
1999-09-20 12:15 ` PATCH: was: " Sven Wischnowsky
1999-09-20 16:36   ` Bart Schaefer
1999-09-23  1:39 ` Tanaka Akira
  -- strict thread matches above, loose matches on Subject: below --
1999-09-23 14:07 Sven Wischnowsky
1999-09-23 10:28 Sven Wischnowsky
1999-09-23 14:12 ` Tanaka Akira
1999-09-23 15:12   ` Bart Schaefer
1999-09-25  2:53     ` Tanaka Akira
1999-09-23  9:13 Sven Wischnowsky
1999-09-23 13:57 ` Tanaka Akira
1999-09-21  7:15 Sven Wischnowsky
1999-09-20 12:57 Sven Wischnowsky
1999-09-19 22:57 Bart Schaefer

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).