From ab1901976ca9329437535c14bbd0cb1575d348da Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 9 Sep 2012 21:03:02 +0200 Subject: [PATCH] Add support for escaping spaces and tabs in shell. --- utils/mxsh.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/utils/mxsh.cpp b/utils/mxsh.cpp index 0be0d9f6..f7da7341 100644 --- a/utils/mxsh.cpp +++ b/utils/mxsh.cpp @@ -314,18 +314,32 @@ void get_and_run_command() argv[0] = NULL; bool lastwasspace = true; + bool escaped = false; for ( size_t i = 0; i <= commandused; i++ ) { switch ( command[i] ) { + case '\\': + if ( !escaped ) + { + memmove(command + i, command + i + 1, commandused+1 - (i-1)); + i--; + commandused--; + escaped = true; + break; + } case '\0': case ' ': case '\t': case '\n': - command[i] = 0; - lastwasspace = true; - break; + if ( !command[i] || !escaped ) + { + command[i] = 0; + lastwasspace = true; + break; + } default: + escaped = false; if ( lastwasspace ) { argv[argc++] = command + i; } lastwasspace = false; }