78443: Subject: [3/5] cmd: Clarify WCMD_if function

buildbot at kegel.com buildbot at kegel.com
Tue Sep 6 13:46:37 CDT 2011


This is an experimental automated build and test service.
Please feel free to ignore this email while we work the kinks out.

The Buildbot has detected a failed build on builder runtests-heaptest while building Wine.
Full details are available at: http://buildbot.kegel.com/builders/runtests-heaptest/builds/8 (though maybe not for long, as I'm still reinstalling the buildbot periodically while experimenting)
BUILD FAILED: failed shell_3


For more info about this message, see http://wiki.winehq.org/BuildBot


-------------- next part --------------
From: Frédéric Delanoy <frederic.delanoy at gmail.com>
Subject: [1/5] cmd: Fix misleading WCMD_parameter documentation (resend)
Message-Id: <1315329584-2435-1-git-send-email-frederic.delanoy at gmail.com>
Date: Tue,  6 Sep 2011 19:19:40 +0200

---
 programs/cmd/batch.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index f010f28..a978ef1 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -113,12 +113,28 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
 }
 
 /*******************************************************************
- * WCMD_parameter - extract a parameter from a command line.
+ * WCMD_parameter
  *
- *	Returns the 'n'th delimited parameter on the command line (zero-based).
- *	Parameter is in static storage overwritten on the next call.
- *	Parameters in quotes (and brackets) are handled.
- *	Also returns a pointer to the location of the parameter in the command line.
+ * Extracts a delimited parameter from an input string
+ *
+ * PARAMS
+ *  s     [I] input string, non NULL
+ *  n     [I] # of the (possibly double quotes-delimited) parameter to return
+ *            Starts at 0
+ *  where [O] if non NULL, pointer to the start of the nth parameter in s,
+ *            potentially a " character
+ *
+ * RETURNS
+ *  Success: Returns the nth delimited parameter found in s.
+ *           *where points to the start of the param, possibly a starting
+ *           double quotes character
+ *  Failure: Returns an empty string if the param is not found.
+ *           *where is set to NULL
+ *
+ * NOTES
+ *  Return value is stored in static storage, hence is overwritten
+ *  after each call.
+ *  Doesn't include any potentially delimiting double quotes
  */
 
 WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
-- 
1.7.6

From: Frédéric Delanoy <frederic.delanoy at gmail.com>
Subject: [2/5] cmd: Simplify WCMD_parameter function (resend)
Message-Id: <1315329584-2435-2-git-send-email-frederic.delanoy at gmail.com>
Date: Tue,  6 Sep 2011 19:19:41 +0200

---
 programs/cmd/batch.c |   78 ++++++++++++++++++--------------------------------
 1 files changed, 28 insertions(+), 50 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index a978ef1..53330ff 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -138,59 +138,37 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
  */
 
 WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
-
-  int i = 0;
-  static WCHAR param[MAX_PATH];
-  WCHAR *p;
-
-  if (where != NULL) *where = NULL;
-  p = param;
-  while (TRUE) {
-    switch (*s) {
-      case ' ': /* Skip leading spaces */
-      case '\t': /* Treat tabs as spaces */
-	s++;
-	break;
-      case '"':
-        if (where != NULL && i==n) *where = s;
-	s++;
-	while ((*s != '\0') && (*s != '"')) {
-	  *p++ = *s++;
-	}
-        if (i == n) {
-          *p = '\0';
-          return param;
-        }
-	if (*s == '"') s++;
-          param[0] = '\0';
-          i++;
-        p = param;
-	break;
-      /* The code to handle bracketed parms is removed because it should no longer
-         be necessary after the multiline support has been added and the for loop
-         set of data is now parseable individually. */
-      case '\0':
-        return param;
-      default:
-        /* Only return where if it is for the right parameter */
-        if (where != NULL && i==n) *where = s;
-	while ((*s != '\0') && (*s != ' ') && (*s != ',') && (*s != '=') && (*s != '\t')) {
-	  *p++ = *s++;
-	}
-        if (i == n && (p!=param)) {
-          *p = '\0';
-          return param;
-        }
-        /* Skip double delimiters, eg. dir a.a,,,,,b.b */
-        if (p != param) {
-          param[0] = '\0';
-          i++;
+    int curParamNb = 0;
+    static WCHAR param[MAX_PATH];
+    WCHAR *p = s, *q;
+    BOOL quotesDelimited;
+
+    if (where != NULL) *where = NULL;
+    param[0] = '\0';
+    while (TRUE) {
+        while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
+            p++;
+        if (*p == '\0') return param;
+
+        quotesDelimited = (*p == '"');
+        if (where != NULL && curParamNb == n) *where = p;
+
+        if (quotesDelimited) {
+            q = ++p;
+            while (*p && *p != '"') p++;
         } else {
-          s++; /* Skip delimiter */
+            q = p;
+            while (*p && (*p != ' ') && (*p != ',') && (*p != '=') && (*p != '\t'))
+                p++;
         }
-        p = param;
+        if (curParamNb == n) {
+            memcpy(param, q, (p - q) * sizeof(WCHAR));
+            param[p-q] = '\0';
+            return param;
+        }
+        if (quotesDelimited && *p == '"') p++;
+        curParamNb++;
     }
-  }
 }
 
 /****************************************************************************
-- 
1.7.6

From: Frédéric Delanoy <frederic.delanoy at gmail.com>
Subject: [3/5] cmd: Clarify WCMD_if function
Message-Id: <1315329584-2435-3-git-send-email-frederic.delanoy at gmail.com>
Date: Tue,  6 Sep 2011 19:19:42 +0200

---
 programs/cmd/builtins.c |   31 ++++++++++---------------------
 1 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 7063eb7..25503bd 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1480,7 +1480,8 @@ void WCMD_popd (void) {
 
 void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
 
-  int negate = 0, test = 0;
+  int negate; /* Negate condition */
+  int test;   /* Condition evaluation result */
   WCHAR condition[MAX_PATH], *command, *s;
   static const WCHAR notW[]    = {'n','o','t','\0'};
   static const WCHAR errlvlW[] = {'e','r','r','o','r','l','e','v','e','l','\0'};
@@ -1488,40 +1489,28 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
   static const WCHAR defdW[]   = {'d','e','f','i','n','e','d','\0'};
   static const WCHAR eqeqW[]   = {'=','=','\0'};
   static const WCHAR parmI[]   = {'/','I','\0'};
+  int caseInsensitive = (strstrW(quals, parmI) != NULL);
 
-  if (!lstrcmpiW (param1, notW)) {
-    negate = 1;
-    strcpyW (condition, param2);
-  }
-  else {
-    strcpyW (condition, param1);
-  }
+  negate = !lstrcmpiW(param1,notW);
+  strcpyW(condition, (negate ? param2 : param1));
   WINE_TRACE("Condition: %s\n", wine_dbgstr_w(condition));
 
   if (!lstrcmpiW (condition, errlvlW)) {
-    if (errorlevel >= atoiW(WCMD_parameter (p, 1+negate, NULL))) test = 1;
+    test = (errorlevel >= atoiW(WCMD_parameter(p, 1+negate, NULL)));
     WCMD_parameter (p, 2+negate, &command);
   }
   else if (!lstrcmpiW (condition, existW)) {
-    if (GetFileAttributesW(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) {
-        test = 1;
-    }
+    test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES);
     WCMD_parameter (p, 2+negate, &command);
   }
   else if (!lstrcmpiW (condition, defdW)) {
-    if (GetEnvironmentVariableW(WCMD_parameter (p, 1+negate, NULL), NULL, 0) > 0) {
-        test = 1;
-    }
+    test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL), NULL, 0) > 0);
     WCMD_parameter (p, 2+negate, &command);
   }
   else if ((s = strstrW (p, eqeqW))) {
     s += 2;
-    if (strstrW (quals, parmI) == NULL) {
-        if (!lstrcmpW (condition, WCMD_parameter (s, 0, NULL))) test = 1;
-    }
-    else {
-        if (!lstrcmpiW (condition, WCMD_parameter (s, 0, NULL))) test = 1;
-    }
+    test = caseInsensitive ? (!lstrcmpiW(condition, WCMD_parameter(s, 0, NULL)))
+                           : (!lstrcmpW (condition, WCMD_parameter(s, 0, NULL)));
     WCMD_parameter (s, 1, &command);
   }
   else {
-- 
1.7.6



More information about the wine-tests-results mailing list