1
0
Fork 0
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:
Jonas 'Sortie' Termansen 2012-09-09 21:03:02 +02:00
parent 5209258de0
commit ab1901976c

View file

@ -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;
}