summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-07-29 13:51:16 +0200
committerTor Andersson <tor.andersson@artifex.com>2015-07-31 15:07:30 +0200
commitefb5a38ca0bac3537ceaf3383681a518df133143 (patch)
tree5de66e15f7569b32789e36a6d0b902692f3e8106 /platform
parentc9f78a28b21da2a321334282fb683cf0a5eb3319 (diff)
downloadmupdf-efb5a38ca0bac3537ceaf3383681a518df133143.tar.xz
win32: Convert argv to utf-8 and use regular getopt.
Easier than duplicating getopt for wchar_t, since we already have windows specific functions to convert wchar_t strings.
Diffstat (limited to 'platform')
-rw-r--r--platform/win32/libmupdf.vcproj4
-rw-r--r--platform/x11/win_main.c38
2 files changed, 25 insertions, 17 deletions
diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj
index b47540ba..a1df42fd 100644
--- a/platform/win32/libmupdf.vcproj
+++ b/platform/win32/libmupdf.vcproj
@@ -870,10 +870,6 @@
>
</File>
<File
- RelativePath="..\..\source\fitz\getoptw.c"
- >
- </File>
- <File
RelativePath="..\..\source\fitz\glyph.c"
>
</File>
diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c
index 538f02f5..0ef15919 100644
--- a/platform/x11/win_main.c
+++ b/platform/x11/win_main.c
@@ -1209,7 +1209,8 @@ int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
int argc;
- LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
+ LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
+ char **argv;
char argv0[256];
MSG msg;
int code;
@@ -1217,8 +1218,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
int bps = 0;
int displayRes = get_system_dpi();
int c;
- wchar_t *password = NULL;
- wchar_t *layout_css = NULL;
+ int i;
+ char *password = NULL;
+ char *layout_css = NULL;
ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT);
if (!ctx)
@@ -1226,27 +1228,33 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
fprintf(stderr, "cannot initialise context\n");
exit(1);
}
+
+ /* Convert wchar_t argv to utf-8 */
+ argv = fz_malloc_array(ctx, argc, sizeof (char*));
+ for (i = 0; i < argc; ++i)
+ argv[i] = fz_utf8_from_wchar(wargv[i]);
+
pdfapp_init(ctx, &gapp);
- while ((c = fz_getoptw(argc, argv, L"p:r:A:C:W:H:S:U:b:")) != -1)
+ while ((c = fz_getopt(argc, argv, L"p:r:A:C:W:H:S:U:b:")) != -1)
{
switch (c)
{
case 'C':
- c = wcstol(fz_optargw, NULL, 16);
+ c = strtol(fz_optarg, NULL, 16);
gapp.tint = 1;
gapp.tint_r = (c >> 16) & 255;
gapp.tint_g = (c >> 8) & 255;
gapp.tint_b = (c) & 255;
break;
- case 'p': password = fz_optargw; break;
- case 'r': displayRes = _wtoi(fz_optargw); break;
- case 'A': fz_set_aa_level(ctx, _wtoi(fz_optargw)); break;
- case 'W': gapp.layout_w = _wtoi(fz_optargw); break;
- case 'H': gapp.layout_h = _wtoi(fz_optargw); break;
- case 'S': gapp.layout_em = _wtoi(fz_optargw); break;
- case 'b': bps = (fz_optargw && *fz_optargw) ? _wtoi(fz_optargw) : 4096; break;
- case 'U': layout_css = fz_optargw; break;
+ case 'p': password = fz_optarg; break;
+ case 'r': displayRes = atoi(fz_optarg); break;
+ case 'A': fz_set_aa_level(ctx, atoi(fz_optarg)); break;
+ case 'W': gapp.layout_w = fz_atof(fz_optarg); break;
+ case 'H': gapp.layout_h = fz_atof(fz_optarg); break;
+ case 'S': gapp.layout_em = fz_atof(fz_optarg); break;
+ case 'b': bps = (fz_optarg && *fz_optarg) ? atoi(fz_optarg) : 4096; break;
+ case 'U': layout_css = fz_optarg; break;
default: usage();
}
}
@@ -1291,6 +1299,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
DispatchMessage(&msg);
}
+ for (i = 0; i < argc; ++i)
+ free(argv[i]);
+ free(argv);
+
do_close(&gapp);
return 0;