From 1fe7324a08ece271886a1aabcfef9c963004b132 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 11 Mar 2010 15:35:24 +0000 Subject: [PATCH] 2010-03-11 Andrei Mozzhuhin PR 1496/shell * libmisc/shell/shell_makeargs.c: Add support for quoted arguments. --- cpukit/ChangeLog | 5 ++++ cpukit/libmisc/shell/shell_makeargs.c | 38 +++++++++++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index ed134541f4..0cabb535c7 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,8 @@ +2010-03-11 Andrei Mozzhuhin + + PR 1496/shell + * libmisc/shell/shell_makeargs.c: Add support for quoted arguments. + 2010-03-10 Joel Sherrill * score/include/rtems/score/interr.h, diff --git a/cpukit/libmisc/shell/shell_makeargs.c b/cpukit/libmisc/shell/shell_makeargs.c index 77d937e101..4901b54bd7 100644 --- a/cpukit/libmisc/shell/shell_makeargs.c +++ b/cpukit/libmisc/shell/shell_makeargs.c @@ -25,22 +25,38 @@ int rtems_shell_make_args( ) { int argc; - char *command; + char *ch; int status = 0; - + argc = 0; - command = commandLine; + ch = commandLine; - while ( 1 ) { - command = strtok( command, " \t\r\n" ); - if ( command == NULL ) - break; - argv_p[ argc++ ] = command; - command = '\0'; - if ( argc == (max_args-1) ) { - status = -1; + while ( *ch ) { + + while ( isspace(*ch) ) ch++; + + if ( *ch == '\0' ) break; + + if ( *ch == '"' ) { + argv_p[ argc++ ] = ++ch; + while ( ( *ch == '\0' ) && ( *ch != '"' ) ) ch++; + } else { + argv_p[ argc++ ] = ch; + while ( ( *ch == '\0' ) && ( !isspace(*ch) ) ) ch++; } + + if ( *ch == '\0' ) + break; + + *ch++ = '\0'; + + if ( argc == (max_args-1) ) { + status = -1; + break; + } + + } argv_p[ argc ] = NULL; *argc_p = argc;