diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-08-19 12:14:52 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-08-24 10:32:50 +0100 |
commit | db3f7ffe32808fde89ce7696066c0b1276756703 (patch) | |
tree | 4945d22f62bcd475cf54605b7ad6515e6ae5f50e | |
parent | 697f6a7cc3eb4230fcf0825b23125c54cbbe412b (diff) | |
download | mupdf-db3f7ffe32808fde89ce7696066c0b1276756703.tar.xz |
Revert revert of WinMain utf-8 handling and fix the bugs.
Also fix a few ifdefs in time.c so that it builds on MinGW.
-rw-r--r-- | platform/win32/libmupdf.vcproj | 6 | ||||
-rw-r--r-- | platform/x11/win_main.c | 51 | ||||
-rw-r--r-- | source/fitz/getoptw.c | 72 | ||||
-rw-r--r-- | source/fitz/time.c | 6 |
4 files changed, 29 insertions, 106 deletions
diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj index b47540ba..b12c624f 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> @@ -908,7 +904,7 @@ <File RelativePath="..\..\source\fitz\load-gif.c" > - </File> + </File> <File RelativePath="..\..\source\fitz\load-jpeg.c" > diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c index 538f02f5..c249b135 100644 --- a/platform/x11/win_main.c +++ b/platform/x11/win_main.c @@ -35,11 +35,12 @@ static int justcopied = 0; static pdfapp_t gapp; +#ifndef PATH_MAX #define PATH_MAX (1024) +#endif static wchar_t wbuf[PATH_MAX]; static char filename[PATH_MAX]; -static char layout_css_buf[PATH_MAX]; /* * Create registry keys to associate MuPDF with PDF and XPS files. @@ -1209,7 +1210,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 +1219,8 @@ 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; + char *password = NULL; + char *layout_css = NULL; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) @@ -1228,25 +1230,27 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow } pdfapp_init(ctx, &gapp); - while ((c = fz_getoptw(argc, argv, L"p:r:A:C:W:H:S:U:b:")) != -1) + argv = fz_argv_from_wargv(argc, wargv); + + while ((c = fz_getopt(argc, argv, "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 = fz_atoi(fz_optarg); break; + case 'A': fz_set_aa_level(ctx, fz_atoi(fz_optarg)); break; + case 'W': gapp.layout_w = fz_atoi(fz_optarg); break; + case 'H': gapp.layout_h = fz_atoi(fz_optarg); break; + case 'S': gapp.layout_em = fz_atoi(fz_optarg); break; + case 'b': bps = (fz_optarg && *fz_optarg) ? fz_atoi(fz_optarg) : 4096; break; + case 'U': layout_css = fz_optarg; break; default: usage(); } } @@ -1258,26 +1262,17 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow winopen(); - if (fz_optindw < argc) + if (fz_optind < argc) { - wcscpy(wbuf, argv[fz_optindw]); + strcpy(filename, argv[fz_optind]); } else { if (!winfilename(wbuf, nelem(wbuf))) exit(0); - } - - code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); - if (code == 0) - winerror(&gapp, "cannot convert filename to utf-8"); - - if (layout_css) - { - code = WideCharToMultiByte(CP_UTF8, 0, layout_css, -1, layout_css_buf, sizeof layout_css_buf, NULL, NULL); + code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) - winerror(&gapp, "cannot convert layout_css filename to utf-8"); - gapp.layout_css = layout_css_buf; + winerror(&gapp, "cannot convert filename to utf-8"); } if (bps) @@ -1291,6 +1286,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow DispatchMessage(&msg); } + fz_free_argv(argc, argv); + do_close(&gapp); return 0; diff --git a/source/fitz/getoptw.c b/source/fitz/getoptw.c deleted file mode 100644 index 55b8d015..00000000 --- a/source/fitz/getoptw.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This is a version of the public domain getopt implementation by - * Henry Spencer originally posted to net.sources. Adapted to - * windows wchar's. - * - * This file is in the public domain. - */ - -#if defined(_WIN64) || defined(_WIN32) - -#include <stdio.h> -#include <string.h> -#include <windows.h> - -#define getoptw fz_getoptw -#define optargw fz_optargw -#define optindw fz_optindw - -wchar_t *optargw; /* Global argument pointer. */ -int optindw = 0; /* Global argv index. */ - -static wchar_t *scan = NULL; /* Private scan pointer. */ - -int -getoptw(wchar_t argc, wchar_t *argv[], wchar_t *optstring) -{ - wchar_t c; - wchar_t *place; - - optargw = NULL; - - if (!scan || *scan == '\0') { - if (optindw == 0) - optindw++; - - if (optindw >= argc || argv[optindw][0] != '-' || argv[optindw][1] == '\0') - return EOF; - if (argv[optindw][1] == '-' && argv[optindw][2] == '\0') { - optindw++; - return EOF; - } - - scan = argv[optindw]+1; - optindw++; - } - - c = *scan++; - place = wcschr(optstring, c); - - if (!place || c == ':') { - fprintf(stderr, "%s: unknown option -%C\n", argv[0], c); - return '?'; - } - - place++; - if (*place == ':') { - if (*scan != '\0') { - optargw = scan; - scan = NULL; - } else if( optindw < argc ) { - optargw = argv[optindw]; - optindw++; - } else { - fprintf(stderr, "%s: option requires argument -%C\n", argv[0], c); - return ':'; - } - } - - return c; -} - -#endif diff --git a/source/fitz/time.c b/source/fitz/time.c index 6b1d6255..1f45e665 100644 --- a/source/fitz/time.c +++ b/source/fitz/time.c @@ -1,10 +1,11 @@ -#ifdef _MSC_VER +#ifdef _WIN32 #include "mupdf/fitz.h" #include <time.h> #include <windows.h> +#ifdef _MSC_VER #ifndef _WINRT #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 @@ -33,6 +34,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) } #endif /* !_WINRT */ +#endif /* _MSC_VER */ char * fz_utf8_from_wchar(const wchar_t *s) @@ -138,4 +140,4 @@ fz_free_argv(int argc, char **argv) free(argv); } -#endif /* _MSC_VER */ +#endif /* _WIN32 */ |