CVS: libraries/commandline commandline.c,1.1,1.2

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/libraries/commandline
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4799/libraries/commandline

Modified Files:
	commandline.c 
Log Message:
support quoted arguments

Index: commandline.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/commandline.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- commandline.c	22 Aug 2005 11:25:26 -0000	1.1
+++ commandline.c	13 Sep 2005 12:25:15 -0000	1.2
@@ -8,6 +8,7 @@
     int argc = 0;
     char *argv[MAXARGS];
     char *ptr;
+    int in_string = 0;
 
     // Split string into separate arguments
     ptr = commandline;
@@ -21,8 +22,14 @@
     }
     argv[argc++] = ptr;
     while (*ptr) { // Search to the end of the string
+        if (in_string) {
+            if (*ptr == '"') {          // String finished
+                in_string = 0;
+                *ptr = '\0';
+            }
+        } else {
         if (*ptr == ' ') { // Space is the delimiter
-            *ptr = 0;
+                *ptr = '\0';
             if (argc >= MAXARGS) {
                 //addidional args will get lost...
                 break;
@@ -37,6 +44,11 @@
                 break;
             }
         }
+            if (*ptr == '"') {   // String begin
+                in_string = 1;
+                argv[argc-1] = ptr+1;
+            }
+        }
         ptr++;
     }
     //search table for command



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.