[PATCH 4/5] [cmd] Echo back command with whitespace removed first

Ann and Jason Edmeades jason at edmeades.me.uk
Tue Sep 25 18:07:46 CDT 2012


This patch fixes two problems, one was some trivial todos in the
testsuite, but it highlighted more importantly that we only supported
the '@' (dont echo) prefix character if at the beginning of a line,
ie not preceeded by whitespace. Tests added for this as well

[No bug#]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20120926/ea7a7ab6/attachment.html>
-------------- next part --------------
From 8048a90ae7fd3c2e696d910419b37123b82fe98c Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Tue, 25 Sep 2012 22:05:03 +0100
Subject: [PATCH 4/5] [cmd] Echo back command with whitespace removed first

This patch fixes two problems, one was some trivial todos in the
testsuite, but it highlighted more importantly that we only supported
the '@' (dont echo) prefix character if at the beginning of a line,
ie not preceeded by whitespace. Tests added for this as well

[No bug#]
---
 programs/cmd/tests/test_builtins.cmd     |    5 +++++
 programs/cmd/tests/test_builtins.cmd.exp |    9 +++++++--
 programs/cmd/wcmdmain.c                  |   17 ++++++++++++-----
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 27a8672..d8c0fcb 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -30,6 +30,9 @@ echo @tab@ on @space@
 
 @echo off
 echo off at tab@@space@
+ at echo noecho1
+ @echo noecho2
+@@@@@echo echo3
 echo ------------ Testing 'echo' [OFF] ------------
 echo word
 echo 'singlequotedword'
@@ -324,6 +327,8 @@ set VAR=
 echo ------------ Testing variable substitution ------------
 echo --- in FOR variables
 for %%i in ("A B" C) do echo %%i
+rem check works when prefix with @
+ at for %%i in ("A B" C) do echo %%i
 rem quotes removal
 for %%i in ("A B" C) do echo '%%~i'
 rem fully qualified path
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 2888ffc..d2938ce 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -51,7 +51,7 @@ word at space@
 @pwd@>echo word at space@@space@@space@
 word at space@@space@
 
- at todo_wine@@pwd@>echo word at space@
+ at pwd@>echo word at space@
 word
 
 @pwd@>echo at tab@word at space@
@@ -63,7 +63,7 @@ word at space@@tab@
 @pwd@>echo at tab@word at tab@@space@@space@
 word at tab@@space@
 
- at todo_wine@@pwd@>echo word at space@
+ at pwd@>echo word at space@
 word
 
 @pwd@>echo at space@@tab at word@space@
@@ -76,6 +76,9 @@ word
 @tab at word
 
 @pwd@>echo @tab@ on @space@@space@
+noecho1
+noecho2
+echo3
 ------------ Testing 'echo' [OFF] ------------
 word
 'singlequotedword'
@@ -282,6 +285,8 @@ r at or_broken@qwerty
 --- in FOR variables
 "A B"
 C
+"A B"
+C
 'A B'@or_broken@''
 'C'@or_broken@''
 @pwd@\C D at or_broken@%~ff
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index b095deb..c0d4925 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1819,27 +1819,34 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
 
     /* Replace env vars if in a batch context */
     if (context) handleExpansion(extraSpace, FALSE, NULL, NULL);
+
+    /* Skip preceeding whitespace */
+    while (*curPos == ' ' || *curPos == '\t') curPos++;
+
     /* Show prompt before batch line IF echo is on and in batch program */
-    if (context && echo_mode && extraSpace[0] && (extraSpace[0] != '@')) {
+    if (context && echo_mode && *curPos && (*curPos != '@')) {
       static const WCHAR echoDot[] = {'e','c','h','o','.'};
       static const WCHAR echoCol[] = {'e','c','h','o',':'};
       const DWORD len = sizeof(echoDot)/sizeof(echoDot[0]);
-      DWORD curr_size = strlenW(extraSpace);
+      DWORD curr_size = strlenW(curPos);
       DWORD min_len = (curr_size < len ? curr_size : len);
       WCMD_show_prompt();
-      WCMD_output_asis(extraSpace);
+      WCMD_output_asis(curPos);
       /* I don't know why Windows puts a space here but it does */
       /* Except for lines starting with 'echo.' or 'echo:'. Ask MS why */
       if (CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
-                         extraSpace, min_len, echoDot, len) != CSTR_EQUAL
+                         curPos, min_len, echoDot, len) != CSTR_EQUAL
           && CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
-                         extraSpace, min_len, echoCol, len) != CSTR_EQUAL)
+                         curPos, min_len, echoCol, len) != CSTR_EQUAL)
       {
           WCMD_output_asis(spaceW);
       }
       WCMD_output_asis(newlineW);
     }
 
+    /* Skip repeated 'no echo' characters */
+    while (*curPos == '@') curPos++;
+
     /* Start with an empty string, copying to the command string */
     curStringLen = 0;
     curRedirsLen = 0;
-- 
1.7.9.5


More information about the wine-patches mailing list