summaryrefslogtreecommitdiffstats
path: root/test/test.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2013-09-22 17:19:38 +0000
committerjstebbins <[email protected]>2013-09-22 17:19:38 +0000
commit5e712218d8eb3f71a06356ed6f952b86ca947fca (patch)
treecd20ec0c7f22a94c11594deb195c7ec939dee4d1 /test/test.c
parent10fda25f44d362349694a42127e8ba4974a4a6ad (diff)
libhb: make libhb internal character code utf8
This makes libhb expect all strings passed to it to be in utf8 format. The cli converts the converts from the current code page to utf8. libhb converts back to the current code page when necessary for libraries that expect it. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5798 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'test/test.c')
-rw-r--r--test/test.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test.c b/test/test.c
index 6047796f9..7de2561f3 100644
--- a/test/test.c
+++ b/test/test.c
@@ -15,6 +15,7 @@
#include <inttypes.h>
#if defined( __MINGW32__ )
+#include <windows.h>
#include <conio.h>
#endif
@@ -189,6 +190,48 @@ static void hb_cli_error_handler ( const char *errmsg )
fprintf( stderr, "ERROR: %s\n", errmsg );
}
+static int get_argv_utf8(int *argc_ptr, char ***argv_ptr)
+{
+#if defined( __MINGW32__ )
+ int ret = 0;
+ int argc;
+ char **argv;
+
+ wchar_t **argv_utf16 = CommandLineToArgvW(GetCommandLineW(), &argc);
+ if (argv_utf16)
+ {
+ int i;
+ int offset = (argc+1) * sizeof(char*);
+ int size = offset;
+
+ for(i = 0; i < argc; i++)
+ size += WideCharToMultiByte(CP_UTF8, 0, argv_utf16[i], -1, NULL, 0, NULL, NULL );
+
+ argv = malloc(size);
+ if (argv)
+ {
+ for (i = 0; i < argc; i++)
+ {
+ argv[i] = (char*)argv + offset;
+ offset += WideCharToMultiByte(CP_UTF8, 0, argv_utf16[i], -1, argv[i], size-offset, NULL, NULL);
+ }
+ argv[argc] = NULL;
+ ret = 1;
+ }
+ LocalFree(argv_utf16);
+ }
+ if (ret)
+ {
+ *argc_ptr = argc;
+ *argv_ptr = argv;
+ }
+ return ret;
+#else
+ // On other systems, assume command line is already utf8
+ return 1;
+#endif
+}
+
int main( int argc, char ** argv )
{
hb_handle_t * h;
@@ -199,6 +242,9 @@ int main( int argc, char ** argv )
audios = hb_list_init();
+ // Get utf8 command line if windows
+ get_argv_utf8(&argc, &argv);
+
/* Parse command line */
if( ParseOptions( argc, argv ) ||
CheckOptions( argc, argv ) )