Jason Edmeades : cmd: Support copy to an 'ascii' destination.

Alexandre Julliard julliard at winehq.org
Mon Oct 15 14:29:06 CDT 2012


Module: wine
Branch: master
Commit: 260210f6e60755e980a73870852bd837821a72d7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=260210f6e60755e980a73870852bd837821a72d7

Author: Jason Edmeades <jason at edmeades.me.uk>
Date:   Fri Oct 12 00:37:24 2012 +0100

cmd: Support copy to an 'ascii' destination.

---

 programs/cmd/builtins.c                  |   49 ++++++++++++++++++++++++++----
 programs/cmd/tests/test_builtins.cmd.exp |   10 +++---
 2 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 9e66cb0..c560602 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -371,6 +371,36 @@ void WCMD_choice (const WCHAR * command) {
 }
 
 /****************************************************************************
+ * WCMD_AppendEOF
+ *
+ * Adds an EOF onto the end of a file
+ * Returns TRUE on success
+ */
+static BOOL WCMD_AppendEOF(WCHAR *filename)
+{
+    HANDLE h;
+
+    char eof = '\x1a';
+
+    WINE_TRACE("Appending EOF to %s\n", wine_dbgstr_w(filename));
+    h = CreateFileW(filename, GENERIC_WRITE, 0, NULL,
+                    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+    if (h == NULL) {
+      WINE_ERR("Failed to open %s (%d)\n", wine_dbgstr_w(filename), GetLastError());
+      return FALSE;
+    } else {
+      SetFilePointer (h, 0, NULL, FILE_END);
+      if (!WriteFile(h, &eof, 1, NULL, NULL)) {
+        WINE_ERR("Failed to append EOF to %s (%d)\n", wine_dbgstr_w(filename), GetLastError());
+        return FALSE;
+      }
+      CloseHandle(h);
+    }
+    return TRUE;
+}
+
+/****************************************************************************
  * WCMD_copy
  *
  * Copy a file or wildcarded set.
@@ -800,10 +830,6 @@ void WCMD_copy(WCHAR * command) {
               WINE_FIXME("Need to ascii copy %s to %s - dropping to binary copy\n",
                          wine_dbgstr_w(srcpath), wine_dbgstr_w(outname));
             }
-            /* Append EOF if ascii destination and we are not going to add more onto the end */
-            if (!destination->binarycopy && !anyconcats) {
-              WINE_FIXME("Need to ascii copy destination (append EOF)\n");
-            }
             status = CopyFileW(srcpath, outname, FALSE);
             if (!status) {
               WCMD_print_error ();
@@ -811,6 +837,14 @@ void WCMD_copy(WCHAR * command) {
             } else {
               WINE_TRACE("Copied successfully\n");
               if (anyconcats) writtenoneconcat = TRUE;
+
+              /* Append EOF if ascii destination and we are not going to add more onto the end */
+              if (!destination->binarycopy && !anyconcats) {
+                if (!WCMD_AppendEOF(outname)) {
+                  WCMD_print_error ();
+                  errorlevel = 1;
+                }
+              }
             }
           }
         }
@@ -829,8 +863,11 @@ void WCMD_copy(WCHAR * command) {
   }
 
   /* Append EOF if ascii destination and we were concatenating */
-  if (!destination->binarycopy && anyconcats && writtenoneconcat) {
-    WINE_FIXME("Need to ascii copy destination (append EOF) to concatenated file\n");
+  if (!errorlevel && !destination->binarycopy && anyconcats && writtenoneconcat) {
+    if (!WCMD_AppendEOF(destination->name)) {
+      WCMD_print_error ();
+      errorlevel = 1;
+    }
   }
 
   /* Exit out of the routine, freeing any remaing allocated memory */
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 9eebcdf..620e44b 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -879,14 +879,14 @@ Passed: file size check on file2 [8]@or_broken at Skipping file size check on NT4
 Passed: file size check on file3 [11]@or_broken at Skipping file size check on NT4
 Passed: file size check on file1_default [5]@or_broken at Skipping file size check on NT4
 Passed: file size check on file1_default2 [5]@or_broken at Skipping file size check on NT4
- at todo_wine@Passed: file size check on file1_plus_eof [6]@or_broken at Skipping file size check on NT4
- at todo_wine@Passed: file size check on file2_plus_eof [9]@or_broken at Skipping file size check on NT4
- at todo_wine@Passed: file size check on file3_plus_eof [12]@or_broken at Skipping file size check on NT4
+Passed: file size check on file1_plus_eof [6]@or_broken at Skipping file size check on NT4
+Passed: file size check on file2_plus_eof [9]@or_broken at Skipping file size check on NT4
+Passed: file size check on file3_plus_eof [12]@or_broken at Skipping file size check on NT4
 @todo_wine at Passed: file size check on file12_plus_eof [14]@or_broken at Skipping file size check on NT4
 @todo_wine at Passed: file size check on file12_no_eof [13]@or_broken at Skipping file size check on NT4
 @todo_wine at Passed: file size check on file12_eof2 [14]@or_broken at Skipping file size check on NT4
- at todo_wine@Passed: file size check on file1_binary_srccopy [6]@or_broken at Skipping file size check on NT4
-Passed: file size check on file1_ascii_srccopy [5]@or_broken at Skipping file size check on NT4
+Passed: file size check on file1_binary_srccopy [6]@or_broken at Skipping file size check on NT4
+ at todo_wine@Passed: file size check on file1_ascii_srccopy [5]@or_broken at Skipping file size check on NT4
 @todo_wine at Passed: file size check on file123_default_copy [25]@or_broken at Skipping file size check on NT4
 @todo_wine at Passed: file size check on file123_ascii_copy [25]@or_broken at Skipping file size check on NT4
 @todo_wine at Passed: file size check on file123_binary_copy [27]@or_broken at Skipping file size check on NT4




More information about the wine-cvs mailing list