cmd: Echo back command with whitespace removed first.

This commit is contained in:
Jason Edmeades 2012-09-25 22:05:03 +01:00 committed by Alexandre Julliard
parent 2ff533c1f2
commit a810e41e47
3 changed files with 24 additions and 7 deletions

View File

@ -30,6 +30,9 @@ echo @tab@ on @space@
@echo off @echo off
echo off@tab@@space@ echo off@tab@@space@
@echo noecho1
@echo noecho2
@@@@@echo echo3
echo ------------ Testing 'echo' [OFF] ------------ echo ------------ Testing 'echo' [OFF] ------------
echo word echo word
echo 'singlequotedword' echo 'singlequotedword'
@ -324,6 +327,8 @@ set VAR=
echo ------------ Testing variable substitution ------------ echo ------------ Testing variable substitution ------------
echo --- in FOR variables echo --- in FOR variables
for %%i in ("A B" C) do echo %%i for %%i in ("A B" C) do echo %%i
rem check works when prefix with @
@for %%i in ("A B" C) do echo %%i
rem quotes removal rem quotes removal
for %%i in ("A B" C) do echo '%%~i' for %%i in ("A B" C) do echo '%%~i'
rem fully qualified path rem fully qualified path

View File

@ -51,7 +51,7 @@ word@space@
@pwd@>echo word@space@@space@@space@ @pwd@>echo word@space@@space@@space@
word@space@@space@ word@space@@space@
@todo_wine@@pwd@>echo word@space@ @pwd@>echo word@space@
word word
@pwd@>echo@tab@word@space@ @pwd@>echo@tab@word@space@
@ -63,7 +63,7 @@ word@space@@tab@
@pwd@>echo@tab@word@tab@@space@@space@ @pwd@>echo@tab@word@tab@@space@@space@
word@tab@@space@ word@tab@@space@
@todo_wine@@pwd@>echo word@space@ @pwd@>echo word@space@
word word
@pwd@>echo@space@@tab@word@space@ @pwd@>echo@space@@tab@word@space@
@ -76,6 +76,9 @@ word
@tab@word @tab@word
@pwd@>echo @tab@ on @space@@space@ @pwd@>echo @tab@ on @space@@space@
noecho1
noecho2
echo3
------------ Testing 'echo' [OFF] ------------ ------------ Testing 'echo' [OFF] ------------
word word
'singlequotedword' 'singlequotedword'
@ -282,6 +285,8 @@ r@or_broken@qwerty
--- in FOR variables --- in FOR variables
"A B" "A B"
C C
"A B"
C
'A B'@or_broken@'' 'A B'@or_broken@''
'C'@or_broken@'' 'C'@or_broken@''
@pwd@\C D@or_broken@%~ff @pwd@\C D@or_broken@%~ff

View File

@ -1819,27 +1819,34 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
/* Replace env vars if in a batch context */ /* Replace env vars if in a batch context */
if (context) handleExpansion(extraSpace, FALSE, NULL, NULL); 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 */ /* 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 echoDot[] = {'e','c','h','o','.'};
static const WCHAR echoCol[] = {'e','c','h','o',':'}; static const WCHAR echoCol[] = {'e','c','h','o',':'};
const DWORD len = sizeof(echoDot)/sizeof(echoDot[0]); 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); DWORD min_len = (curr_size < len ? curr_size : len);
WCMD_show_prompt(); WCMD_show_prompt();
WCMD_output_asis(extraSpace); WCMD_output_asis(curPos);
/* I don't know why Windows puts a space here but it does */ /* I don't know why Windows puts a space here but it does */
/* Except for lines starting with 'echo.' or 'echo:'. Ask MS why */ /* Except for lines starting with 'echo.' or 'echo:'. Ask MS why */
if (CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, 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, && 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(spaceW);
} }
WCMD_output_asis(newlineW); WCMD_output_asis(newlineW);
} }
/* Skip repeated 'no echo' characters */
while (*curPos == '@') curPos++;
/* Start with an empty string, copying to the command string */ /* Start with an empty string, copying to the command string */
curStringLen = 0; curStringLen = 0;
curRedirsLen = 0; curRedirsLen = 0;