summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-02-27 17:43:55 +0000
committerRobin Watts <robin.watts@artifex.com>2013-02-27 17:43:55 +0000
commita00b3069c1409a3d24bd3c8998693ac8052d78ef (patch)
treeaa2fda3a9a7db26907c9faee6a697d81faef20dc
parent4d7c32754abb96b5cbbea6cd98d5ca386ad2a81e (diff)
downloadmupdf-a00b3069c1409a3d24bd3c8998693ac8052d78ef.tar.xz
Bug 693624: Update mudraw and mutool to use Unicode entry points on windows
Convert the unicode argv to utf8, and pass in to our existing main function.
-rw-r--r--apps/mudraw.c64
-rw-r--r--apps/mutool.c64
2 files changed, 128 insertions, 0 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c
index a1cc4eaf..98380409 100644
--- a/apps/mudraw.c
+++ b/apps/mudraw.c
@@ -648,8 +648,12 @@ static void drawoutline(fz_context *ctx, fz_document *doc)
#ifdef MUPDF_COMBINED_EXE
int draw_main(int argc, char **argv)
#else
+#ifdef _WIN32
+static int main_utf8(int argc, char **argv)
+#else
int main(int argc, char **argv)
#endif
+#endif
{
char *password = "";
int grayscale = 0;
@@ -862,3 +866,63 @@ int main(int argc, char **argv)
fz_free_context(ctx);
return (errored != 0);
}
+
+#ifdef _WIN32
+static char *
+wchar_to_utf8(wchar_t *s)
+{
+ wchar_t *src = s;
+ char *d;
+ char *dst;
+ int len = 1;
+
+ while (*src)
+ {
+ len += fz_runelen(*src++);
+ }
+
+ d = malloc(len);
+ if (d != NULL)
+ {
+ dst = d;
+ src = s;
+ while (*src)
+ {
+ dst += fz_runetochar(dst, *src++);
+ }
+ *dst = 0;
+ }
+ return d;
+}
+
+int wmain(int argc, wchar_t *wargv[])
+{
+ int i, ret;
+ char **argv = calloc(argc, sizeof(char *));
+ if (argv == NULL)
+ goto oom;
+
+ for (i = 0; i < argc; i++)
+ {
+ argv[i] = wchar_to_utf8(wargv[i]);
+ if (argv[i] == NULL)
+ goto oom;
+ }
+
+ ret = main_utf8(argc, argv);
+
+ if (0)
+ {
+oom:
+ ret = 1;
+ fprintf(stderr, "Out of memory while processing command line args\n");
+ }
+ for (i = 0; i < argc; i++)
+ {
+ free(argv[i]);
+ }
+ free(argv);
+
+ return ret;
+}
+#endif
diff --git a/apps/mutool.c b/apps/mutool.c
index 0b66e067..5215b78d 100644
--- a/apps/mutool.c
+++ b/apps/mutool.c
@@ -29,7 +29,11 @@ namematch(const char *end, const char *start, const char *match)
return ((end-len >= start) && (strncmp(end-len, match, len) == 0));
}
+#ifdef _WIN32
+static int main_utf8(int argc, char **argv)
+#else
int main(int argc, char **argv)
+#endif
{
char *start, *end;
char buf[32];
@@ -77,3 +81,63 @@ int main(int argc, char **argv)
return 1;
}
+
+#ifdef _WIN32
+static char *
+wchar_to_utf8(wchar_t *s)
+{
+ wchar_t *src = s;
+ char *d;
+ char *dst;
+ int len = 1;
+
+ while (*src)
+ {
+ len += fz_runelen(*src++);
+ }
+
+ d = malloc(len);
+ if (d != NULL)
+ {
+ dst = d;
+ src = s;
+ while (*src)
+ {
+ dst += fz_runetochar(dst, *src++);
+ }
+ *dst = 0;
+ }
+ return d;
+}
+
+int wmain(int argc, wchar_t *wargv[])
+{
+ int i, ret;
+ char **argv = calloc(argc, sizeof(char *));
+ if (argv == NULL)
+ goto oom;
+
+ for (i = 0; i < argc; i++)
+ {
+ argv[i] = wchar_to_utf8(wargv[i]);
+ if (argv[i] == NULL)
+ goto oom;
+ }
+
+ ret = main_utf8(argc, argv);
+
+ if (0)
+ {
+oom:
+ ret = 1;
+ fprintf(stderr, "Out of memory while processing command line args\n");
+ }
+ for (i = 0; i < argc; i++)
+ {
+ free(argv[i]);
+ }
+ free(argv);
+
+ return ret;
+}
+#endif