Skip to content
Myr

Allow globbing on Windows

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The mingw-w64 runtime expands wildcards, which causes a discrepancy between `main`'s `argv` (multiple file names) and Windows' `wargv` (a single wildcard). Use `wmain` to retrieve the wide character args.

authored by Jason Hood · committed by Nico Williams · parent 80b064f · Browse files · 2 files+23 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+23 added−11 removed

  • other:+23 added−11 removed

2 files+23 added−11 removed

modified:src/main.c+19 added-11 removed
245 unmodified lines
246 jv_dumpf(JV_ARRAY(jv_string("DEBUG:"), input), stderr, dumpopts & ~(JV_PRINT_PRETTY));247 fprintf(stderr, "\n");248}249250#ifdef WIN32251int umain(int argc, char* argv[]);252253int wmain(int argc, wchar_t* wargv[]) {254 size_t arg_sz;255 char **argv = alloca(argc * sizeof(wchar_t*));256 for (int i = 0; i < argc; i++) {257 argv[i] = alloca((arg_sz = WideCharToMultiByte(CP_UTF8,258 0,259 wargv[i],260 -1, 0, 0, 0, 0)));261 WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], arg_sz, 0, 0);262 }263 return umain(argc, argv);264}265266int umain(int argc, char* argv[]) {267#else /*}*/268int main(int argc, char* argv[]) {269#endif270 jq_state *jq = NULL;271 int ret = JQ_OK_NO_OUTPUT;272 int compiled = 0;273 int parser_flags = 0;
7 unmodified lines
281 fflush(stdout);282 fflush(stderr);283 _setmode(fileno(stdout), _O_TEXT | _O_U8TEXT);284 _setmode(fileno(stderr), _O_TEXT | _O_U8TEXT);266 int wargc;267 wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);268 assert(wargc == argc);269 size_t arg_sz;270 for (int i = 0; i < argc; i++) {271 argv[i] = alloca((arg_sz = WideCharToMultiByte(CP_UTF8,272 0,273 wargv[i],274 -1, 0, 0, 0, 0)));275 WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], arg_sz, 0, 0);276 }285#endif286287 if (argc) progname = argv[0];288
418 unmodified lines
modified:Makefile.am+4 added
16 unmodified lines
1718AM_CFLAGS = -Wextra -Wall -Wno-missing-field-initializers \19 -Wno-unused-parameter -Wno-unused-function2021if WIN3222AM_CFLAGS += -municode23endif2425ACLOCAL_AMFLAGS = -I config/m42627### Generating the lexer and parser28
194 unmodified lines