zsh-workers
 help / color / mirror / code / Atom feed
From: Tanaka Akira <akr@jaist.ac.jp>
To: zsh-workers@sunsite.auc.dk
Subject: Re: Chatty little precompiler for _arguments
Date: 25 Sep 1999 11:53:33 +0900	[thread overview]
Message-ID: <rsqvh8z7lci.fsf@crane.jaist.ac.jp> (raw)
In-Reply-To: "Bart Schaefer"'s message of "Thu, 23 Sep 1999 15:12:11 +0000"

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


  reply	other threads:[~1999-09-25  2:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-09-23 14:07 Sven Wischnowsky
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-20  8:43 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
1999-09-19 22:57 Bart Schaefer

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=rsqvh8z7lci.fsf@crane.jaist.ac.jp \
    --to=akr@jaist.ac.jp \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).