summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2011-05-19 16:16:28 +0000
committerMikael Magnusson <mikachu@gmail.com>2011-05-19 16:16:28 +0000
commit6a29bc80d032ec7224240789deb622e07478028c (patch)
treeb925cd3e877f8ed8c43a8db49666d8a74e030036 /Src
parent72cb7cfc6fff21d3fb9b3f1aa384ce4b17a4e8c0 (diff)
downloadzsh-6a29bc80d032ec7224240789deb622e07478028c.tar.gz
zsh-6a29bc80d032ec7224240789deb622e07478028c.tar.xz
zsh-6a29bc80d032ec7224240789deb622e07478028c.zip
29261: Add g:: flag.
Diffstat (limited to 'Src')
-rw-r--r--Src/subst.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/Src/subst.c b/Src/subst.c
index 244c066d4..822b24a40 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1607,6 +1607,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
      */	
     int presc = 0;
     /*
+     * The (g) flag.  Process escape sequences with various GETKEY_ flags.
+     */
+    int getkeys = -1;
+    /*
      * The (@) flag; interacts obscurely with qt and isarr.
      * This is one of the things that decides whether multsub
      * will produce an array, but in an extremely indirect fashion.
@@ -1932,6 +1936,36 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 		    presc++;
 		    break;
 
+		case 'g':
+		    t = get_strarg(++s, &arglen);
+		    if (getkeys < 0)
+			getkeys = 0;
+		    if (*t) {
+			sav = *t;
+			*t = 0;
+			while (*++s) {
+			    switch (*s) {
+			    case 'e':
+				getkeys |= GETKEY_EMACS;
+				break;
+			    case 'o':
+				getkeys |= GETKEY_OCTAL_ESC;
+				break;
+			    case 'c':
+				getkeys |= GETKEY_CTRL;
+				break;
+
+			    default:
+				*t = sav;
+				goto flagerr;
+			    }
+			}
+			*t = sav;
+			s = t + arglen - 1;
+		    } else
+			goto flagerr;
+		    break;
+
 		case 'z':
 		    shsplit = LEXFLAGS_ACTIVE;
 		    break;
@@ -3083,6 +3117,28 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 	}
     }
     /*
+     * Process echo- and print-style escape sequences.
+     */
+    if (getkeys >= 0) {
+	int len;
+
+	copied = 1;		/* string is always copied */
+	if (isarr) {
+	    char **ap, **ap2;
+
+	    ap = aval;
+	    aval = (char **) zhalloc(sizeof(char *) * (arrlen(aval)+1));
+	    for (ap2 = aval; *ap; ap++, ap2++) {
+		*ap2 = getkeystring(*ap, &len, getkeys, NULL);
+		*ap2 = metafy(*ap2, len, META_USEHEAP);
+	    }
+	    *ap2++ = NULL;
+	} else {
+	    val = getkeystring(val, &len, getkeys, NULL);
+	    val = metafy(val, len, META_USEHEAP);
+	}
+    }
+    /*
      * Perform prompt-style modifications.
      */
     if (presc) {