summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-06-26 15:59:17 +0100
committerRobin Watts <robin.watts@artifex.com>2015-06-26 19:06:22 +0100
commit2b08c7f7ed2d4bc3874e5d2734c7d4a0ca3ad966 (patch)
tree09f71d07e0c16cd4a64048387ae9c718d57bebd3 /source
parent7b5720137cef833476d4015cce6402e3c272ccad (diff)
downloadmupdf-2b08c7f7ed2d4bc3874e5d2734c7d4a0ca3ad966.tar.xz
Bug 696053: Update windows mupdf to respect command line flags.
Previously, only the unix executable had been updated to take command line flags; update the windows one in line with it. We have to cope with the argv being in Unicode; add a windows specific version of getoptw for this. Also note that that fprintf's in the windows mupdf exe won't work as GUI apps don't have a console window, and can't write to the parent one. Fixing that is a larger project than I have time for right now.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/getoptw.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/source/fitz/getoptw.c b/source/fitz/getoptw.c
new file mode 100644
index 00000000..55b8d015
--- /dev/null
+++ b/source/fitz/getoptw.c
@@ -0,0 +1,72 @@
+/*
+ * 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