[PATCH 6/8] [cmd] Correct for /f string and command set handling

Ann and Jason Edmeades jason at edmeades.me.uk
Tue Oct 23 16:33:10 CDT 2012


When the parameter to for /f is a string or a command, then do not
attempt to walk the set parameter by parameter. If it is a list of
files, then each needs processing.

(No tests, other bugs prevent them working - see next few patches)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121023/da28a780/attachment.html>
-------------- next part --------------
From bce4ac77c9a6a44c75d08011b0b1ca31a60e9dfe Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Tue, 23 Oct 2012 00:28:18 +0100
Subject: [PATCH 6/8] [cmd] Correct for /f string and command set handling

When the parameter to for /f is a string or a command, then do not
attempt to walk the set parameter by parameter. If it is a list of
files, then each needs processing.

(No tests, other bugs prevent them working - see next few patches)
---
 programs/cmd/builtins.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 6e252fe..721a1b7 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -2039,6 +2039,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
                                  (forf_usebackq && *itemStart != '\''))) {
 
             HANDLE input;
+            WCHAR *itemparm;
 
             WINE_TRACE("Processing for filespec from item %d '%s'\n", itemNum,
                        wine_dbgstr_w(item));
@@ -2049,12 +2050,13 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
                 (!forf_usebackq && *itemStart == '\'')) {
 
               /* Use itemstart because the command is the whole set, not just the first token */
-              input = WCMD_forf_getinputhandle(forf_usebackq, itemStart, TRUE);
+              itemparm = itemStart;
             } else {
 
               /* Use item because the file to process is just the first item in the set */
-              input = WCMD_forf_getinputhandle(forf_usebackq, item, FALSE);
+              itemparm = item;
             }
+            input = WCMD_forf_getinputhandle(forf_usebackq, itemparm, (itemparm==itemStart));
 
             /* Process the input file */
             if (input == INVALID_HANDLE_VALUE) {
@@ -2074,6 +2076,12 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
               CloseHandle (input);
             }
 
+            /* When we have processed the item as a whole command, abort future set processing */
+            if (itemparm==itemStart) {
+              thisSet = NULL;
+              break;
+            }
+
         /* Filesets - A string literal */
         } else if (doFileset && ((!forf_usebackq && *itemStart == '"') ||
                                  (forf_usebackq && *itemStart == '\''))) {
@@ -2082,6 +2090,10 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
           strcpyW(buffer, item);
           WCMD_parse_line(cmdStart, firstCmd, &cmdEnd, variable, buffer, &doExecuted,
                             &forf_skip, forf_eol);
+
+          /* Only one string can be supplied in the whole set, abort future set processing */
+          thisSet = NULL;
+          break;
         }
 
         WINE_TRACE("Post-command, cmdEnd = %p\n", cmdEnd);
@@ -2089,7 +2101,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
       }
 
       /* Move onto the next set line */
-      thisSet = thisSet->nextcommand;
+      if (thisSet) thisSet = thisSet->nextcommand;
     }
 
     /* If /L is provided, now run the for loop */
-- 
1.7.9.5


More information about the wine-patches mailing list