78442: Subject: [4/5] cmd: Add an output parameter to WCMD_parameter to point to the end of the extracted param; if requested

buildbot at kegel.com buildbot at kegel.com
Tue Sep 6 13:42:44 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-default while building Wine.
Full details are available at: http://buildbot.kegel.com/builders/runtests-default/builds/9 (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

From: Frédéric Delanoy <frederic.delanoy at gmail.com>
Subject: [4/5] cmd: Add an output parameter to WCMD_parameter to point to the end of the extracted param, if requested
Message-Id: <1315329584-2435-4-git-send-email-frederic.delanoy at gmail.com>
Date: Tue,  6 Sep 2011 19:19:43 +0200

Necessary mainly for double quoted string parameters, as they are stripped in
the return value.
Such params need to be preserved for certain commands, notably when comparing
strings with IF '==' operator.
---
 programs/cmd/batch.c     |   18 ++++++++++++------
 programs/cmd/builtins.c  |   34 +++++++++++++++++-----------------
 programs/cmd/directory.c |    2 +-
 programs/cmd/wcmd.h      |    2 +-
 programs/cmd/wcmdmain.c  |   10 +++++-----
 5 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 53330ff..9b29bb3 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -123,6 +123,8 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
  *            Starts at 0
  *  where [O] if non NULL, pointer to the start of the nth parameter in s,
  *            potentially a " character
+ *  end   [O] if non NULL, and 'where' non NULL, pointer to the last char of
+ *            the nth parameter in s, potentially a " character
  *
  * RETURNS
  *  Success: Returns the nth delimited parameter found in s.
@@ -136,14 +138,16 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
  *  after each call.
  *  Doesn't include any potentially delimiting double quotes
  */
-
-WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
+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;
+    BOOL setWhere = (where != NULL);
+    BOOL setEnd   = setWhere && (end != NULL);
 
-    if (where != NULL) *where = NULL;
+    if (setWhere) *where = NULL;
+    if (setEnd)   *end   = NULL;
     param[0] = '\0';
     while (TRUE) {
         while (*p && ((*p == ' ') || (*p == ',') || (*p == '=') || (*p == '\t')))
@@ -151,7 +155,7 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
         if (*p == '\0') return param;
 
         quotesDelimited = (*p == '"');
-        if (where != NULL && curParamNb == n) *where = p;
+        if (setWhere && curParamNb == n) *where = p;
 
         if (quotesDelimited) {
             q = ++p;
@@ -164,6 +168,7 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) {
         if (curParamNb == n) {
             memcpy(param, q, (p - q) * sizeof(WCHAR));
             param[p-q] = '\0';
+            if (setEnd) *end = p - 1 + quotesDelimited;
             return param;
         }
         if (quotesDelimited && *p == '"') p++;
@@ -360,8 +365,9 @@ void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
   if (*lastModifier == '0') {
     strcpyW(outputparam, context->batchfileW);
   } else if ((*lastModifier >= '1' && *lastModifier <= '9')) {
-    strcpyW(outputparam, WCMD_parameter (context -> command,
-                 *lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL));
+    strcpyW(outputparam,
+            WCMD_parameter (context -> command, *lastModifier-'0' + context -> shift_count[*lastModifier-'0'],
+                            NULL, NULL));
   } else {
     strcpyW(outputparam, forValue);
   }
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 25503bd..c7814f9 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -526,7 +526,7 @@ void WCMD_create_dir (WCHAR *command) {
     }
     /* Loop through all args */
     while (TRUE) {
-        WCHAR *thisArg = WCMD_parameter(command, argno++, &argN);
+        WCHAR *thisArg = WCMD_parameter(command, argno++, &argN, NULL);
         if (!argN) break;
         if (!create_full_path(thisArg)) {
             WCMD_print_error ();
@@ -830,7 +830,7 @@ BOOL WCMD_delete (WCHAR *command) {
         WCHAR *thisArg;
 
         argN = NULL;
-        thisArg = WCMD_parameter (command, argno, &argN);
+        thisArg = WCMD_parameter (command, argno, &argN, NULL);
         if (!argN)
             break;       /* no more parameters */
         if (argN[0] == '/')
@@ -1037,7 +1037,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
 
     WINE_TRACE("Processing for set %p\n", thisSet);
     i = 0;
-    while (*(item = WCMD_parameter (thisSet->command, i, &itemStart))) {
+    while (*(item = WCMD_parameter (thisSet->command, i, &itemStart, NULL))) {
 
       /*
        * If the parameter within the set has a wildcard then search for matching files
@@ -1134,7 +1134,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
             while (WCMD_fgets (buffer, sizeof(buffer)/sizeof(WCHAR), input)) {
 
               /* Skip blank lines*/
-              parm = WCMD_parameter (buffer, 0, &where);
+              parm = WCMD_parameter (buffer, 0, &where, NULL);
               WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
                          wine_dbgstr_w(buffer));
 
@@ -1164,7 +1164,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
 
           /* Skip blank lines, and re-extract parameter now string has quotes removed */
           strcpyW(buffer, item);
-          parm = WCMD_parameter (buffer, 0, &where);
+          parm = WCMD_parameter (buffer, 0, &where, NULL);
           WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm),
                        wine_dbgstr_w(buffer));
 
@@ -1496,22 +1496,22 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
   WINE_TRACE("Condition: %s\n", wine_dbgstr_w(condition));
 
   if (!lstrcmpiW (condition, errlvlW)) {
-    test = (errorlevel >= atoiW(WCMD_parameter(p, 1+negate, NULL)));
-    WCMD_parameter (p, 2+negate, &command);
+    test = (errorlevel >= atoiW(WCMD_parameter(p, 1+negate, NULL, NULL)));
+    WCMD_parameter(p, 2+negate, &command, NULL);
   }
   else if (!lstrcmpiW (condition, existW)) {
-    test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES);
-    WCMD_parameter (p, 2+negate, &command);
+    test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL, NULL)) != INVALID_FILE_ATTRIBUTES);
+    WCMD_parameter(p, 2+negate, &command, NULL);
   }
   else if (!lstrcmpiW (condition, defdW)) {
-    test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL), NULL, 0) > 0);
-    WCMD_parameter (p, 2+negate, &command);
+    test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+negate, NULL, NULL), NULL, 0) > 0);
+    WCMD_parameter(p, 2+negate, &command, NULL);
   }
   else if ((s = strstrW (p, eqeqW))) {
     s += 2;
-    test = caseInsensitive ? (!lstrcmpiW(condition, WCMD_parameter(s, 0, NULL)))
-                           : (!lstrcmpW (condition, WCMD_parameter(s, 0, NULL)));
-    WCMD_parameter (s, 1, &command);
+    test = caseInsensitive ? (!lstrcmpiW(condition, WCMD_parameter(s, 0, NULL, NULL)))
+                           : (!lstrcmpW (condition, WCMD_parameter(s, 0, NULL, NULL)));
+    WCMD_parameter(s, 1, &command, NULL);
   }
   else {
     WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR));
@@ -1691,7 +1691,7 @@ void WCMD_remove_dir (WCHAR *command) {
 
   /* Loop through all args */
   while (argN) {
-    WCHAR *thisArg = WCMD_parameter (command, argno++, &argN);
+    WCHAR *thisArg = WCMD_parameter (command, argno++, &argN, NULL);
     if (argN && argN[0] != '/') {
       WINE_TRACE("rd: Processing arg %s (quals:%s)\n", wine_dbgstr_w(thisArg),
                  wine_dbgstr_w(quals));
@@ -2428,7 +2428,7 @@ void WCMD_type (WCHAR *command) {
   /* Loop through all args */
   errorlevel = 0;
   while (argN) {
-    WCHAR *thisArg = WCMD_parameter (command, argno++, &argN);
+    WCHAR *thisArg = WCMD_parameter (command, argno++, &argN, NULL);
 
     HANDLE h;
     WCHAR buffer[512];
@@ -2522,7 +2522,7 @@ void WCMD_more (WCHAR *command) {
     WCMD_enter_paged_mode(moreStrPage);
 
     while (argN) {
-      WCHAR *thisArg = WCMD_parameter (command, argno++, &argN);
+      WCHAR *thisArg = WCMD_parameter (command, argno++, &argN, NULL);
       HANDLE h;
 
       if (!argN) break;
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index 217f31c..1863690 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -839,7 +839,7 @@ void WCMD_directory (WCHAR *cmd) {
   prevEntry = NULL;
   while (argN) {
     WCHAR fullname[MAXSTRING];
-    WCHAR *thisArg = WCMD_parameter (cmd, argno++, &argN);
+    WCHAR *thisArg = WCMD_parameter(cmd, argno++, &argN, NULL);
     if (argN && argN[0] != '/') {
 
       WINE_TRACE("Found parm '%s'\n", wine_dbgstr_w(thisArg));
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index c4ece13..4b48420 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -97,7 +97,7 @@ void WCMD_version (void);
 int  WCMD_volume (int mode, const WCHAR *command);
 
 WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream);
-WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where);
+WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end);
 WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
 BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
 void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 4f1a2f3..4fbbbf6 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -833,13 +833,13 @@ static void handleExpansion(WCHAR *cmd, BOOL justFors,
 
     /* Replace use of %0...%9 if in batch program*/
     } else if (!justFors && context && (i >= 0) && (i <= 9)) {
-      t = WCMD_parameter (context -> command, i + context -> shift_count[i], NULL);
+      t = WCMD_parameter(context -> command, i + context -> shift_count[i], NULL, NULL);
       WCMD_strsubstW(p, p+2, t, -1);
 
     /* Replace use of %* if in batch program*/
     } else if (!justFors && context && *(p+1)=='*') {
       WCHAR *startOfParms = NULL;
-      t = WCMD_parameter (context -> command, 1, &startOfParms);
+      t = WCMD_parameter(context -> command, 1, &startOfParms, NULL);
       if (startOfParms != NULL)
         WCMD_strsubstW(p, p+2, startOfParms, -1);
       else
@@ -1357,8 +1357,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
 
     /* Otherwise STDIN could come from a '<' redirect */
     } else if ((p = strchrW(new_redir,'<')) != NULL) {
-      h = CreateFileW(WCMD_parameter (++p, 0, NULL), GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
-		FILE_ATTRIBUTE_NORMAL, NULL);
+      h = CreateFileW(WCMD_parameter(++p, 0, NULL, NULL), GENERIC_READ, FILE_SHARE_READ,
+                      &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
       if (h == INVALID_HANDLE_VALUE) {
 	WCMD_print_error ();
         HeapFree( GetProcessHeap(), 0, cmd );
@@ -1402,7 +1402,7 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
         WINE_TRACE("Redirect %d (%p) to %d (%p)\n", handle, GetStdHandle(idx_stdhandles[idx]), idx, h);
 
       } else {
-        WCHAR *param = WCMD_parameter (p, 0, NULL);
+        WCHAR *param = WCMD_parameter(p, 0, NULL, NULL);
         h = CreateFileW(param, GENERIC_WRITE, 0, &sa, creationDisposition,
                         FILE_ATTRIBUTE_NORMAL, NULL);
         if (h == INVALID_HANDLE_VALUE) {
-- 
1.7.6



More information about the wine-tests-results mailing list