cmd: Add a space at the end of the first echo'ed batch line.
This commit is contained in:
parent
1579ab0e01
commit
4cd2a0e542
|
@ -25,6 +25,36 @@
|
|||
static char workdir[MAX_PATH];
|
||||
static DWORD workdir_len;
|
||||
|
||||
/* Substitute escaped spaces with real ones */
|
||||
static const char* replace_escaped_spaces(const char *data, DWORD size, DWORD *new_size)
|
||||
{
|
||||
static const char escaped_space[] = {'@','s','p','a','c','e','@','\0'};
|
||||
const char *a, *b;
|
||||
char *new_data;
|
||||
DWORD len_space = sizeof(escaped_space) -1;
|
||||
|
||||
a = b = data;
|
||||
*new_size = 0;
|
||||
|
||||
new_data = HeapAlloc(GetProcessHeap(), 0, size*sizeof(char));
|
||||
ok(new_data != NULL, "HeapAlloc failed\n");
|
||||
if(!new_data)
|
||||
return NULL;
|
||||
|
||||
while( (b = strstr(a, escaped_space)) )
|
||||
{
|
||||
strncpy(new_data + *new_size, a, b-a + 1);
|
||||
*new_size += b-a + 1;
|
||||
new_data[*new_size - 1] = ' ';
|
||||
a = b + len_space;
|
||||
}
|
||||
|
||||
strncpy(new_data + *new_size, a, strlen(a) + 1);
|
||||
*new_size += strlen(a);
|
||||
|
||||
return new_data;
|
||||
}
|
||||
|
||||
static BOOL run_cmd(const char *cmd_data, DWORD cmd_size)
|
||||
{
|
||||
SECURITY_ATTRIBUTES sa = {sizeof(sa), 0, TRUE};
|
||||
|
@ -113,6 +143,7 @@ static const char *compare_line(const char *out_line, const char *out_end, const
|
|||
|
||||
static const char pwd_cmd[] = {'@','p','w','d','@'};
|
||||
static const char todo_space_cmd[] = {'@','t','o','d','o','_','s','p','a','c','e','@'};
|
||||
static const char space_cmd[] = {'@','s','p','a','c','e','@'};
|
||||
static const char or_broken_cmd[] = {'@','o','r','_','b','r','o','k','e','n','@'};
|
||||
|
||||
while(exp_ptr < exp_end) {
|
||||
|
@ -135,6 +166,13 @@ static const char *compare_line(const char *out_line, const char *out_end, const
|
|||
if(out_ptr < out_end && *out_ptr == ' ')
|
||||
out_ptr++;
|
||||
continue;
|
||||
}else if(exp_ptr+sizeof(space_cmd) <= exp_end
|
||||
&& !memcmp(exp_ptr, space_cmd, sizeof(space_cmd))) {
|
||||
exp_ptr += sizeof(space_cmd);
|
||||
ok(*out_ptr == ' ', "expected space\n");
|
||||
if(out_ptr < out_end && *out_ptr == ' ')
|
||||
out_ptr++;
|
||||
continue;
|
||||
}else if(exp_ptr+sizeof(or_broken_cmd) <= exp_end
|
||||
&& !memcmp(exp_ptr, or_broken_cmd, sizeof(or_broken_cmd))) {
|
||||
exp_ptr = exp_end;
|
||||
|
@ -199,11 +237,15 @@ static void test_output(const char *out_data, DWORD out_size, const char *exp_da
|
|||
|
||||
static void run_test(const char *cmd_data, DWORD cmd_size, const char *exp_data, DWORD exp_size)
|
||||
{
|
||||
const char *out_data;
|
||||
DWORD out_size;
|
||||
const char *out_data, *actual_cmd_data;
|
||||
DWORD out_size, actual_cmd_size;
|
||||
|
||||
if(!run_cmd(cmd_data, cmd_size))
|
||||
return;
|
||||
actual_cmd_data = replace_escaped_spaces(cmd_data, cmd_size, &actual_cmd_size);
|
||||
if(!actual_cmd_size || !actual_cmd_data)
|
||||
goto cleanup;
|
||||
|
||||
if(!run_cmd(actual_cmd_data, actual_cmd_size))
|
||||
goto cleanup;
|
||||
|
||||
out_size = map_file("test.out", &out_data);
|
||||
if(out_size) {
|
||||
|
@ -212,6 +254,9 @@ static void run_test(const char *cmd_data, DWORD cmd_size, const char *exp_data,
|
|||
}
|
||||
DeleteFileA("test.out");
|
||||
DeleteFileA("test.err");
|
||||
|
||||
cleanup:
|
||||
HeapFree(GetProcessHeap(), 0, (LPVOID)actual_cmd_data);
|
||||
}
|
||||
|
||||
static void run_from_file(char *file_name)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
echo Tests for cmd's builtin commands
|
||||
@echo off
|
||||
|
||||
echo ------------ Testing 'echo' --------------
|
||||
@echo on
|
||||
echo ------------ Testing 'echo' [ON] --------------
|
||||
echo word
|
||||
echo 'singlequotedword'
|
||||
echo "doublequotedword"
|
||||
|
@ -11,6 +11,22 @@ echo.
|
|||
echo .
|
||||
echo.word
|
||||
echo .word
|
||||
echo word@space@
|
||||
echo word@space@@space@
|
||||
|
||||
@echo off
|
||||
echo ------------ Testing 'echo' [OFF] --------------
|
||||
echo word
|
||||
echo 'singlequotedword'
|
||||
echo "doublequotedword"
|
||||
@echo at-echoed-word
|
||||
echo "/?"
|
||||
echo.
|
||||
echo .
|
||||
echo.word
|
||||
echo .word
|
||||
echo word@space@
|
||||
echo word@space@@space@
|
||||
|
||||
echo ------------ Testing 'set' --------------
|
||||
echo set "FOO=bar" should not include the quotes in the variable value
|
||||
|
|
|
@ -1,7 +1,41 @@
|
|||
|
||||
@pwd@>echo Tests for cmd's builtin commands@todo_space@
|
||||
@pwd@>echo Tests for cmd's builtin commands@space@
|
||||
Tests for cmd's builtin commands
|
||||
------------ Testing 'echo' --------------
|
||||
|
||||
@pwd@>echo ------------ Testing 'echo' [ON] --------------@space@
|
||||
------------ Testing 'echo' [ON] --------------
|
||||
|
||||
@pwd@>echo word@space@
|
||||
word
|
||||
|
||||
@pwd@>echo 'singlequotedword'@space@
|
||||
'singlequotedword'
|
||||
|
||||
@pwd@>echo "doublequotedword"@space@
|
||||
"doublequotedword"
|
||||
at-echoed-word
|
||||
|
||||
@pwd@>echo "/?"@space@
|
||||
"/?"
|
||||
|
||||
@pwd@>echo.
|
||||
|
||||
|
||||
@pwd@>echo .@space@
|
||||
.
|
||||
|
||||
@pwd@>echo.word
|
||||
word
|
||||
|
||||
@pwd@>echo .word@space@
|
||||
.word
|
||||
|
||||
@pwd@>echo word@space@@space@
|
||||
word@space@
|
||||
|
||||
@pwd@>echo word@space@@space@@space@
|
||||
word@space@@space@
|
||||
------------ Testing 'echo' [OFF] --------------
|
||||
word
|
||||
'singlequotedword'
|
||||
"doublequotedword"
|
||||
|
@ -11,6 +45,8 @@ at-echoed-word
|
|||
.
|
||||
word
|
||||
.word
|
||||
word@space@
|
||||
word@space@@space@
|
||||
------------ Testing 'set' --------------
|
||||
set "FOO=bar" should not include the quotes in the variable value
|
||||
bar
|
||||
|
|
|
@ -1779,8 +1779,11 @@ WCHAR *WCMD_ReadAndParseLine(WCHAR *optionalcmd, CMD_LIST **output, HANDLE readF
|
|||
if (context) handleExpansion(extraSpace, FALSE, NULL, NULL);
|
||||
/* Show prompt before batch line IF echo is on and in batch program */
|
||||
if (context && echo_mode && extraSpace[0] && (extraSpace[0] != '@')) {
|
||||
const WCHAR spc[]={' ','\0'};
|
||||
WCMD_show_prompt();
|
||||
WCMD_output_asis(extraSpace);
|
||||
/* I don't know why Windows puts a space here but it does */
|
||||
WCMD_output_asis(spc);
|
||||
WCMD_output_asis(newline);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue