summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell_makeargs.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libmisc/shell/shell_makeargs.c')
-rw-r--r--cpukit/libmisc/shell/shell_makeargs.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/cpukit/libmisc/shell/shell_makeargs.c b/cpukit/libmisc/shell/shell_makeargs.c
new file mode 100644
index 0000000000..727ea829c9
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_makeargs.c
@@ -0,0 +1,68 @@
+/*
+ * Split string into argc/argv style argument list
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <ctype.h>
+
+int rtems_shell_make_args(
+ char *commandLine,
+ int *argc_p,
+ char **argv_p,
+ int max_args
+)
+{
+ int argc;
+ char *ch;
+ int status = 0;
+
+ argc = 0;
+ ch = commandLine;
+
+ while ( *ch ) {
+
+ while ( isspace((unsigned char)*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((unsigned char)*ch) ) ) ch++;
+ }
+
+ argc++;
+
+ if ( *ch == '\0' )
+ break;
+
+ *ch++ = '\0';
+
+ if ( argc == (max_args-1) ) {
+ status = -1;
+ break;
+ }
+
+
+ }
+ argv_p[ argc ] = NULL;
+ *argc_p = argc;
+ return status;
+}
+