From 6a29bc80d032ec7224240789deb622e07478028c Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Thu, 19 May 2011 16:16:28 +0000 Subject: 29261: Add g:: flag. --- Src/subst.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'Src/subst.c') diff --git a/Src/subst.c b/Src/subst.c index 244c066d4..822b24a40 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1606,6 +1606,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) * The (%) flag, c.f. mods again. */ 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 @@ -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; @@ -3082,6 +3116,28 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) val = casemodify(val, casmod); } } + /* + * 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. */ -- cgit 1.4.1