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 ++++++++++++++++++-- src/spawn.cpp | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') 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); diff --git a/src/spawn.cpp b/src/spawn.cpp index 9ea3919..0722180 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -209,6 +209,11 @@ parse_shell_command_line(const gchar *cmdline, GError **error) * \(lq0,128ED\(rq, and is recommended when writing cross-platform * macros using the EC command. * + * When using an UNIX-compatible shell or the UNIX98 shell emulation, + * you might want to use the \fB^E@\fP string-building character + * to pass Q-Register contents reliably as single arguments to + * the spawned process. + * * The spawned process inherits both \*(ST's current working * directory and its environment variables. * More precisely, \*(ST uses its environment registers -- cgit v1.2.3