1
mirror of https://github.com/mpv-player/mpv synced 2025-01-24 19:37:30 +01:00

options: change --no-config option, make it apply to input.conf as well

Simplify --no-config and make it a normal flag option, and doesn't take
an argument anymore. You can get the same behavior by using --no-config
and then --include to explicitly load a certain config file.

Make --no-config work for input.conf as well. Make it so that
--input:conf=file still works in this case. As a  technically unrelated
change, the file argument now works as one would expect, instead of
making it relatively to "~/.mpv/". This makes for simpler code and
easier to understand option semantics. We can also print better error
messages.
This commit is contained in:
wm4 2013-02-08 23:52:06 +01:00
parent c1ddfb5907
commit a1be0e1aec
8 changed files with 38 additions and 46 deletions

View File

@ -886,8 +886,7 @@
conf=<filename> conf=<filename>
Specify input configuration file other than the default Specify input configuration file other than the default
``~/.mpv/input.conf``. ``~/.mpv/<filename>`` is assumed if no ``~/.mpv/input.conf``.
full path is given.
ar-dev=<device> ar-dev=<device>
Device to be used for Apple IR Remote (default is autodetected, Linux Device to be used for Apple IR Remote (default is autodetected, Linux
@ -1251,17 +1250,16 @@
Disables colorkeying. Only supported by the xv (see ``--vo=xv:ck``) video Disables colorkeying. Only supported by the xv (see ``--vo=xv:ck``) video
output driver. output driver.
--no-config=<options> --no-config
Do not parse selected configuration files. Do not load default configuration files. This prevents loading of
``~/.mpv/config`` and ``~/.mpv/input.conf``, as well as loading the
same files from system wide configuration directories.
*NOTE*: If ``--include`` or ``--use-filedir-conf`` options are specified Loading of some configuration files is not affected by this option, such
at the command line, they will be honoured. as configuration files for cddb, DVB code and fontconfig.
Available options are: *NOTE*: Files explicitly requested by command line options, like
``--include`` or ``--use-filedir-conf``, will still be loaded.
:all: all configuration files
:system: system configuration file
:user: user configuration file
--no-idx --no-idx
Do not use index present in the file even if one is present. Do not use index present in the file even if one is present.

View File

@ -297,8 +297,7 @@ const m_option_t common_opts[] = {
#ifdef CONFIG_PRIORITY #ifdef CONFIG_PRIORITY
{"priority", &proc_priority, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"priority", &proc_priority, CONF_TYPE_STRING, 0, 0, 0, NULL},
#endif #endif
OPT_CHOICE("no-config", noconfig, CONF_GLOBAL | CONF_NOCFG | CONF_PRE_PARSE, OPT_FLAG("config", load_config, CONF_GLOBAL | CONF_NOCFG | CONF_PRE_PARSE),
({"no", 0}, {"user", 1}, {"system", 2}, {"all", 3})),
// ------------------------- stream options -------------------- // ------------------------- stream options --------------------

View File

@ -31,6 +31,7 @@ void set_default_mplayer_options(struct MPOpts *opts)
.loop_times = -1, .loop_times = -1,
.ordered_chapters = 1, .ordered_chapters = 1,
.chapter_merge_threshold = 100, .chapter_merge_threshold = 100,
.load_config = 1,
.stream_cache_min_percent = 20.0, .stream_cache_min_percent = 20.0,
.stream_cache_seek_min_percent = 50.0, .stream_cache_seek_min_percent = 50.0,
.stream_cache_pause = 10.0, .stream_cache_pause = 10.0,

View File

@ -520,7 +520,7 @@ static int print_cmd_list(m_option_t *cfg, char *optname, char *optparam);
// Our command line options // Our command line options
static const m_option_t input_conf[] = { static const m_option_t input_conf[] = {
OPT_STRING("conf", input.config_file, CONF_GLOBAL, OPTDEF_STR("input.conf")), OPT_STRING("conf", input.config_file, CONF_GLOBAL),
OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL), OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL),
OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL), OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL),
{ "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, { "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG },
@ -1721,15 +1721,16 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
return n_binds; return n_binds;
} }
static int parse_config_file(struct input_ctx *ictx, char *file) static int parse_config_file(struct input_ctx *ictx, char *file, bool warn)
{ {
if (!mp_path_exists(file)) { if (!mp_path_exists(file)) {
mp_msg(MSGT_INPUT, MSGL_V, "Input config file %s missing.\n", file); mp_msg(MSGT_INPUT, warn ? MSGL_ERR : MSGL_V,
"Input config file %s not found.\n", file);
return 0; return 0;
} }
stream_t *s = open_stream(file, NULL, NULL); stream_t *s = open_stream(file, NULL, NULL);
if (!s) { if (!s) {
mp_msg(MSGT_INPUT, MSGL_V, "Can't open input config file %s.\n", file); mp_msg(MSGT_INPUT, MSGL_ERR, "Can't open input config file %s.\n", file);
return 0; return 0;
} }
bstr res = stream_read_complete(s, NULL, 1000000, 0); bstr res = stream_read_complete(s, NULL, 1000000, 0);
@ -1754,7 +1755,8 @@ char *mp_input_get_section(struct input_ctx *ictx)
return ictx->section; return ictx->section;
} }
struct input_ctx *mp_input_init(struct input_conf *input_conf) struct input_ctx *mp_input_init(struct input_conf *input_conf,
bool load_default_conf)
{ {
struct input_ctx *ictx = talloc_ptrtype(NULL, ictx); struct input_ctx *ictx = talloc_ptrtype(NULL, ictx);
*ictx = (struct input_ctx){ *ictx = (struct input_ctx){
@ -1786,27 +1788,18 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf)
NULL, NULL); NULL, NULL);
#endif #endif
char *file; bool config_ok = false;
char *config_file = input_conf->config_file; if (input_conf->config_file)
file = config_file[0] != '/' ? config_ok = parse_config_file(ictx, input_conf->config_file, true);
mp_find_user_config_file(config_file) : config_file; if (!config_ok && load_default_conf) {
if (!file)
return ictx;
if (!parse_config_file(ictx, file)) {
// free file if it was allocated by get_path(),
// before it gets overwritten
if (file != config_file)
talloc_free(file);
// Try global conf dir // Try global conf dir
file = MPLAYER_CONFDIR "/input.conf"; char *file = mp_find_config_file("input.conf");
if (!parse_config_file(ictx, file)) config_ok = file && parse_config_file(ictx, file, false);
mp_msg(MSGT_INPUT, MSGL_V, "Falling back on default (hardcoded) " talloc_free(file);
"input config\n"); }
} else { if (!config_ok) {
// free file if it was allocated by get_path() mp_msg(MSGT_INPUT, MSGL_V, "Falling back on default (hardcoded) "
if (file != config_file) "input config\n");
talloc_free(file);
} }
#ifdef CONFIG_JOYSTICK #ifdef CONFIG_JOYSTICK

View File

@ -203,7 +203,8 @@ char *mp_input_get_section(struct input_ctx *ictx);
// Initialize the input system // Initialize the input system
struct input_conf; struct input_conf;
struct input_ctx *mp_input_init(struct input_conf *input_conf); struct input_ctx *mp_input_init(struct input_conf *input_conf,
bool load_default_conf);
void mp_input_uninit(struct input_ctx *ictx); void mp_input_uninit(struct input_ctx *ictx);

View File

@ -689,8 +689,9 @@ static bool parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf)
struct MPOpts *opts = &mpctx->opts; struct MPOpts *opts = &mpctx->opts;
char *conffile; char *conffile;
int conffile_fd; int conffile_fd;
if (!(opts->noconfig & 2) && if (!opts->load_config)
m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mpv.conf") < 0) return true;
if (!m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mpv.conf") < 0)
return false; return false;
if ((conffile = mp_find_user_config_file("")) == NULL) if ((conffile = mp_find_user_config_file("")) == NULL)
mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n"); mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n");
@ -708,8 +709,7 @@ static bool parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf)
write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1); write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1);
close(conffile_fd); close(conffile_fd);
} }
if (!(opts->noconfig & 1) && if (m_config_parse_config_file(conf, conffile) < 0)
m_config_parse_config_file(conf, conffile) < 0)
return false; return false;
talloc_free(conffile); talloc_free(conffile);
} }
@ -3657,7 +3657,7 @@ static void check_previous_track_selection(struct MPContext *mpctx)
static void init_input(struct MPContext *mpctx) static void init_input(struct MPContext *mpctx)
{ {
mpctx->input = mp_input_init(&mpctx->opts.input); mpctx->input = mp_input_init(&mpctx->opts.input, mpctx->opts.load_config);
mpctx->key_fifo = mp_fifo_create(mpctx->input, &mpctx->opts); mpctx->key_fifo = mp_fifo_create(mpctx->input, &mpctx->opts);
if (slave_mode) if (slave_mode)
mp_input_add_cmd_fd(mpctx->input, 0, USE_FD0_CMD_SELECT, MP_INPUT_SLAVE_CMD_FUNC, NULL); mp_input_add_cmd_fd(mpctx->input, 0, USE_FD0_CMD_SELECT, MP_INPUT_SLAVE_CMD_FUNC, NULL);

View File

@ -54,7 +54,7 @@ typedef struct MPOpts {
int ordered_chapters; int ordered_chapters;
int chapter_merge_threshold; int chapter_merge_threshold;
int quiet; int quiet;
int noconfig; int load_config;
char *codecs_file; char *codecs_file;
int stream_cache_size; int stream_cache_size;
float stream_cache_min_percent; float stream_cache_min_percent;

View File

@ -289,7 +289,7 @@ err_out:
extern int mp_msg_levels[]; extern int mp_msg_levels[];
/* Parse some command line options early before main parsing. /* Parse some command line options early before main parsing.
* --noconfig prevents reading configuration files (otherwise done before * --no-config prevents reading configuration files (otherwise done before
* command line parsing), and --really-quiet suppresses messages printed * command line parsing), and --really-quiet suppresses messages printed
* during normal options parsing. * during normal options parsing.
*/ */