Hi everyone,
I'm trying to fix the wine cmd behavior but as this 5th try differs
greatly with the previous one, I'd like to have some feedback before
submitting it.
If you have any question, just let me know.
Thanks is advance.
diff --git a/programs/cmd/tests/batch.c b/programs/cmd/tests/batch.c
index cc8c020..7d598fd 100644
--- a/programs/cmd/tests/batch.c
+++ b/programs/cmd/tests/batch.c
@@ -25,6 +25,36 @@
static char workdir[MAX_PATH];
static DWORD workdir_len;
+/* Substitute escaped spaces with real ones */
+static char* replace_escaped_spaces(const char *data, DWORD size, DWORD *new_size)
+{
+ static const char escaped_space[] = "@space@";
+ char *a, *b, *new_data;
+ DWORD len_space = strlen(escaped_space);
+
+ a = b = (char*)data;
+ *new_size=0;
+
+ new_data = (char*)malloc(size*sizeof(char));
+ ok(new_data != NULL, "malloc failed\n");
+ if(!new_data)
+ return NULL;
+
+ while( (b = strstr(a, escaped_space)) )
+ {
+ new_size += b-a +1;
+ strncpy(new_data, a, b-a+1);
+ new_data[b-a] = ' ';
+ new_data += b-a+1;
+ a = b += len_space;
+ }
+
+ *new_size += strlen(a);
+ strncpy(new_data, a, strlen(a)+1);
+
+ return new_data-*new_size+strlen(a);
+}
+
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;
@@ -200,9 +238,14 @@ 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;
+ char *actual_cmd_data;
+ DWORD out_size, actual_cmd_size;
- if(!run_cmd(cmd_data, cmd_size))
+ 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))
return;
out_size = map_file("test.out", &out_data);
@@ -212,6 +255,10 @@ static void run_test(const char *cmd_data, DWORD cmd_size, const char *exp_data,
}
DeleteFileA("test.out");
DeleteFileA("test.err");
+
+cleanup:
+ if(actual_cmd_data)
+ free(actual_cmd_data);
}
static void run_from_file(char *file_name)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index d9f5cf7..375b7a1 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1,7 +1,21 @@
echo Tests for cmd's builtin commands
-...@echo off
-echo ------------ Testing 'echo' --------------
+...@echo on
+echo ------------ Testing 'echo' [ON] --------------
+echo word
+echo 'singlequotedword'
+echo "doublequotedword"
+...@echo at-echoed-word
+echo "/?"
+echo.
+echo .
+echo.word
+echo .word
+echo w...@space@
+echo w...@space@@space@
+
+...@echo off
+echo ------------ Testing 'echo' [OFF] --------------
echo word
echo 'singlequotedword'
echo "doublequotedword"
@@ -11,6 +25,8 @@ echo.
echo .
echo.word
echo .word
+echo w...@space@
+echo w...@space@@space@
echo ------------ Testing 'set' --------------
echo set "FOO=bar" should not include the quotes in the variable value
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 8942cb3..dee2c5b 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -1,7 +1,41 @@
-...@pwd@>echo Tests for cmd's builtin comma...@todo_space@
+...@pwd@>echo Tests for cmd's builtin comma...@space@
Tests for cmd's builtin commands
------------- Testing 'echo' --------------
+
+...@pwd@>echo ------------ Testing 'echo' [ON] -----------...@space@
+------------ Testing 'echo' [ON] --------------
+
+...@pwd@>echo w...@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 .w...@space@
+.word
+
+...@pwd@>echo w...@space@@space@
+w...@space@
+
+...@pwd@>echo w...@space@@space@@space@
+w...@space@@space@
+------------ Testing 'echo' [OFF] --------------
word
'singlequotedword'
"doublequotedword"
@@ -11,6 +45,8 @@ at-echoed-word
.
word
.word
+w...@space@
+w...@space@@space@
------------ Testing 'set' --------------
set "FOO=bar" should not include the quotes in the variable value
bar
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index b50512e..85f78b8 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -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);
}