mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add support for escaping spaces and tabs in shell.
This commit is contained in:
parent
5209258de0
commit
ab1901976c
1 changed files with 17 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue