currentry, cmdutils convert all command lines to UTF-8 on windows.
In almost all cases, it works as expected, but this is harmful when
inputting avisynth script.

From: Oka Motofumi <[email protected]>
Date: Wed, 30 May 2012 22:46:33 +0900
Subject: [PATCH] cmdutils.c: avoid converting filepath to UTF-8 for avisynth

avisynth is a non-unicode application.
if UTF-8 is used for input filepath, avisynth may not operate normally.
---
 cmdutils.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index bd07d2a..0b3606b 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -175,7 +175,7 @@ static int win32_argc = 0;
 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
 {
     char *argstr_flat;
-    wchar_t **argv_w;
+    wchar_t **argv_w, *avs_ext = NULL;
     int i, buffsize = 0, offset = 0;

     if (win32_argv_utf8) {
@@ -191,8 +191,15 @@ static void prepare_app_arguments(int *argc_ptr, char
***argv_ptr)

     /* determine the UTF-8 buffer size (including NULL-termination
symbols) */
     for (i = 0; i < win32_argc; i++)
-        buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
-                                        NULL, 0, NULL, NULL);
+        /* Avisynth is a non-unicode application.
+           If input filepath which includes multibyte-characters is
converted
+           to UTF-8, avisynth will miss the valid filepath. */
+        if ((avs_ext = wcsrchr(argv_w[i], L'.')) && wcscmp(avs_ext,
L".avs") == 0)
+            buffsize += WideCharToMultiByte(CP_THREAD_ACP, 0, argv_w[i],
-1,
+                                            NULL, 0, NULL, NULL);
+        else
+            buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+                                            NULL, 0, NULL, NULL);

     win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) +
buffsize);
     argstr_flat     = (char *)win32_argv_utf8 + sizeof(char *) *
(win32_argc + 1);
@@ -203,9 +210,14 @@ static void prepare_app_arguments(int *argc_ptr, char
***argv_ptr)

     for (i = 0; i < win32_argc; i++) {
         win32_argv_utf8[i] = &argstr_flat[offset];
-        offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
-                                      &argstr_flat[offset],
-                                      buffsize - offset, NULL, NULL);
+        if ((avs_ext = wcsrchr(argv_w[i], L'.')) && wcscmp(avs_ext,
L".avs") == 0)
+            offset += WideCharToMultiByte(CP_THREAD_ACP, 0, argv_w[i], -1,
+                                          &argstr_flat[offset],
+                                          buffsize - offset, NULL, NULL);
+        else
+            offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+                                          &argstr_flat[offset],
+                                          buffsize - offset, NULL, NULL);
     }
     win32_argv_utf8[i] = NULL;
     LocalFree(argv_w);
-- 
1.7.9
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to