[PATCH 8/9] cmd: fix parameter parsing of quotes and special chars

Martin Wilck mwilck at arcor.de
Mon Sep 19 18:51:18 CDT 2011


This patch applies the same logic of changes to WCMD_parameter()
that the previous two patches made to WCMD_parse().
---
 programs/cmd/batch.c |   44 ++++++++++++++++++++++++++++++--------------
 1 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index f988d95..6672d15 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -137,39 +137,55 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
  *  after each call.
  *  Doesn't include any potentially delimiting double quotes
  */
+static BOOL is_param_delimiter(WCHAR c, int n)
+{
+    return ((c == ' ') || (c == ',') || (c == '=') || (c == '\t') 
+	    || (c == ';') || (c == '(' && n == 0));
+}
+
 WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end) {
     int curParamNb = 0;
     static WCHAR param[MAX_PATH];
-    WCHAR *p = s, *q;
-    BOOL quotesDelimited;
+    WCHAR *p = s, *poff = param, *q, *pend;
 
     if (where != NULL) *where = NULL;
     if (end != NULL) *end = NULL;
     param[0] = '\0';
     while (TRUE) {
-        while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
+        while (is_param_delimiter(*p, curParamNb))
             p++;
         if (*p == '\0') return param;
 
-        quotesDelimited = (*p == '"');
         if (where != NULL && curParamNb == n) *where = p;
-
-        if (quotesDelimited) {
-            q = ++p;
+      inWord:
+        if (*p == '"') {
+            q = p++;
+	    if (curParamNb == 0) q++;
             while (*p && *p != '"') p++;
+	    pend = p;
+	    if (*p == '"') {
+		p++;
+		if (curParamNb != 0) pend++;
+	    }
         } else {
             q = p;
-            while (*p && (*p != ' ') && (*p != ',') && (*p != '=') && (*p != '\t'))
+            while (*p && !is_param_delimiter(*p, curParamNb) && (*p != '"'))
                 p++;
+	    pend = p;
         }
         if (curParamNb == n) {
-            memcpy(param, q, (p - q) * sizeof(WCHAR));
-            param[p-q] = '\0';
-            if (end) *end = p - 1 + quotesDelimited;
-            return param;
+            memcpy(poff, q, (pend - q) * sizeof(WCHAR));
+	    poff += pend - q;
         }
-        if (quotesDelimited && *p == '"') p++;
-        curParamNb++;
+	if (*p == '\0' || is_param_delimiter(*p, curParamNb)) {
+	    if (curParamNb == n) {
+	        *poff = '\0';
+	        if (end) *end = p - 1;
+		return param;
+	    } else	
+		curParamNb++;
+	} else
+	    goto inWord;
     }
 }
 
-- 
1.7.3.4



More information about the wine-patches mailing list