From 2a6c084e4c57f28b422a5c83e44e7297473fbb90 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Thu, 13 Feb 2014 18:50:56 +1100 Subject: parse_commandline: glob filenames on Windows The Windows port uses CommandLineToArgvW, which doesn't expand wildcards in command line arguments. Use glob to expand them instead, but only for non-option arguments. --- options/parse_commandline.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'options') diff --git a/options/parse_commandline.c b/options/parse_commandline.c index ed567d6171..d86dde68fc 100644 --- a/options/parse_commandline.c +++ b/options/parse_commandline.c @@ -25,6 +25,7 @@ #include #include +#include "osdep/io.h" #include "common/global.h" #include "common/msg.h" #include "common/msg_control.h" @@ -111,6 +112,28 @@ static bool split_opt(struct parse_state *p) return false; } +#ifdef __MINGW32__ +static void process_non_option(struct playlist *files, const char *arg) +{ + glob_t gg; + + // Glob filenames on Windows (cmd.exe doesn't do this automatically) + if (glob(arg, 0, NULL, &gg)) { + playlist_add_file(files, arg); + } else { + for (int i = 0; i < gg.gl_pathc; i++) + playlist_add_file(files, gg.gl_pathv[i]); + + globfree(&gg); + } +} +#else +static void process_non_option(struct playlist *files, const char *arg) +{ + playlist_add_file(files, arg); +} +#endif + // returns M_OPT_... error code int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, struct mpv_global *global, @@ -234,8 +257,9 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, } else // dvd:// or dvd://x entry playlist_add_file(files, file0); - } else - playlist_add_file(files, file0); + } else { + process_non_option(files, file0); + } talloc_free(tmp); // Lock stdin if it will be used as input -- cgit v1.2.3