From 16e9b0dc459f3ac198495127498b2255eb94c1ce Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 4 Jun 2016 21:01:53 +0200 Subject: added ^E@ string building character * allows expansion of Q-Register contents with UNIX shell quoting * This especially improves the usefulness of the EC/EG commands as we can reliably determine that a TECO string (ie. Q-Register) will end up as a single argument to the spawned process. A previous workaround was to enclose ^EQ in quotes, but it does not work e.g. if the register contains the wrong kind of quotes or other magic shell characters. * NOTE: In order to be absolutely sure about the runtime behaviour of EC plus ^E@, you will have to enable UNIX98 shell emulation in portable macros. --- src/parser.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index f05f167..941db49 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -388,6 +388,7 @@ bool StringBuildingMachine::input(gchar chr, gchar *&result) { QRegister *reg; + gchar *str; switch (mode) { case MODE_UPPER: @@ -450,13 +451,17 @@ StateCtlE: undo.push_obj(qregspec_machine) = new QRegSpecMachine; set(&&StateCtlENum); break; + case 'U': + undo.push_obj(qregspec_machine) = new QRegSpecMachine; + set(&&StateCtlEU); + break; case 'Q': undo.push_obj(qregspec_machine) = new QRegSpecMachine; set(&&StateCtlEQ); break; - case 'U': + case '@': undo.push_obj(qregspec_machine) = new QRegSpecMachine; - set(&&StateCtlEU); + set(&&StateCtlEQuote); break; default: result = (gchar *)g_malloc(3); @@ -497,6 +502,17 @@ StateCtlEQ: result = reg->get_string(); return true; +StateCtlEQuote: + if (!qregspec_machine->input(chr, reg)) + return false; + + undo.push_obj(qregspec_machine) = NULL; + set(StateStart); + str = reg->get_string(); + result = g_shell_quote(str); + g_free(str); + return true; + StateEscaped: set(StateStart); result = String::chrdup(chr); -- cgit v1.2.3