From ac2d553aade080b719f7b5b8ad1162dd933e30b5 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 17 Aug 2015 19:45:42 +0100 Subject: Revert "win32: Convert argv to utf-8 and use regular getopt." Neatness doesn't override actually working. This reverts commit efb5a38ca0bac3537ceaf3383681a518df133143. --- source/fitz/getoptw.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 source/fitz/getoptw.c (limited to 'source/fitz') 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 +#include +#include + +#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 -- cgit v1.2.3