diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2013-06-17 14:31:22 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2013-06-17 14:31:22 +0200 |
commit | e860f7240878c22d90b086827e58e1e8e055bbf8 (patch) | |
tree | 744f3594c58f4abc246da1a130715e9266998608 /apps | |
parent | bd2eb44aa27ee92564325e61b5fae81322b9e7ce (diff) | |
download | mupdf-e860f7240878c22d90b086827e58e1e8e055bbf8.tar.xz |
Make common wchar_t / utf-8 conversion functions for MSVC tools.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/mudraw.c | 61 | ||||
-rw-r--r-- | apps/mutool.c | 64 |
2 files changed, 11 insertions, 114 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index 8e550c84..f2fa53a7 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -7,6 +7,7 @@ #ifdef _MSC_VER #include <winsock2.h> +#define main main_utf8 #else #include <sys/time.h> #endif @@ -812,11 +813,7 @@ parse_colorspace(const char *name) return -1; } -#ifdef _MSC_VER -static int main_utf8(int argc, char **argv) -#else int main(int argc, char **argv) -#endif { char *password = ""; fz_document *doc = NULL; @@ -1083,61 +1080,11 @@ int main(int argc, char **argv) } #ifdef _MSC_VER -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); - + char **argv = fz_argv_from_wargv(argc, wargv); + int ret = main(argc, argv); + fz_free_argv(argc, argv); return ret; } #endif diff --git a/apps/mutool.c b/apps/mutool.c index 17c98424..1d7fb9dd 100644 --- a/apps/mutool.c +++ b/apps/mutool.c @@ -4,6 +4,10 @@ #include <fitz.h> +#ifdef _MSC_VER +#define main main_utf8 +#endif + int pdfclean_main(int argc, char *argv[]); int pdfextract_main(int argc, char *argv[]); int pdfinfo_main(int argc, char *argv[]); @@ -29,11 +33,7 @@ namematch(const char *end, const char *start, const char *match) return ((end-len >= start) && (strncmp(end-len, match, len) == 0)); } -#ifdef _MSC_VER -static int main_utf8(int argc, char **argv) -#else int main(int argc, char **argv) -#endif { char *start, *end; char buf[32]; @@ -83,61 +83,11 @@ int main(int argc, char **argv) } #ifdef _MSC_VER -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); - + char **argv = fz_argv_from_wargv(argc, wargv); + int ret = main(argc, argv); + fz_free_argv(argc, argv); return ret; } #endif |