cmd/tests: Convert line endings to DOS style at runtime before running batch test file (try 2)

Frédéric Delanoy frederic.delanoy at gmail.com
Fri Jul 15 04:26:25 CDT 2011


This is needed to avoid a windows cmd bug/feature where using UNIX line endings may cause some subroutine/goto labels not to be found in certain cases
---
 programs/cmd/tests/batch.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/programs/cmd/tests/batch.c b/programs/cmd/tests/batch.c
index 03c2b56..b4625a7 100644
--- a/programs/cmd/tests/batch.c
+++ b/programs/cmd/tests/batch.c
@@ -25,16 +25,34 @@
 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)
+/* Convert to DOS line endings, and substitute escaped spaces with real ones */
+static const char* convert_input_data(const char *data, DWORD size, DWORD *new_size)
 {
     static const char escaped_space[] = {'@','s','p','a','c','e','@','\0'};
+    DWORD i, eol_count = 0;
+    const char *p = data;
     char *ptr, *new_data;
 
-    new_data = ptr = HeapAlloc(GetProcessHeap(), 0, size + 1);
-    memcpy( new_data, data, size );
-    new_data[size] = 0;
+    for (i = 0; i < size; i++)
+        if (data[i] == '\n') eol_count++;
 
+    ptr = new_data = HeapAlloc(GetProcessHeap(), 0, size + eol_count + 1);
+    if (new_data == NULL) return NULL;
+
+    for (i = 0; i < eol_count; i++)
+    {
+        const char *end = strchr(p, '\n');
+        memcpy(ptr, p, end - p);
+        ptr +=  end - p;
+        *ptr++ = '\r';
+        *ptr++ = '\n';
+        p = end + 1;
+    }
+
+    memcpy(ptr, p, data + size - p);
+    new_data[size + eol_count] = '\0';
+
+    ptr = new_data;
     while ((ptr = strstr(ptr, escaped_space)))
     {
         char *end = ptr + sizeof(escaped_space) - 1;
@@ -233,7 +251,7 @@ static void run_test(const char *cmd_data, DWORD cmd_size, const char *exp_data,
     const char *out_data, *actual_cmd_data;
     DWORD out_size, actual_cmd_size;
 
-    actual_cmd_data = replace_escaped_spaces(cmd_data, cmd_size, &actual_cmd_size);
+    actual_cmd_data = convert_input_data(cmd_data, cmd_size, &actual_cmd_size);
     if(!actual_cmd_size || !actual_cmd_data)
         goto cleanup;
 
-- 
1.7.6




More information about the wine-patches mailing list