diff options
author | wm4 <wm4@nowhere> | 2013-12-14 19:50:00 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-14 19:54:49 +0100 |
commit | 683d7e88e46463497033eb4759ced45ee8b8cc49 (patch) | |
tree | aa99cebe436f180c2d3c2e070ec4d3896386153a /mpvcore/input | |
parent | dcf9f77c58691bde3e4e0ac60e5a5d7e1fc95b42 (diff) | |
download | mpv-683d7e88e46463497033eb4759ced45ee8b8cc49.tar.bz2 mpv-683d7e88e46463497033eb4759ced45ee8b8cc49.tar.xz |
Allow some options taking filenames to refer to mpv config dir
Add the mp_get_user_path() function, and make it expand special path
prefixes. Use it for some things in mpv which take filenames
(--input-config, --screenshot-template, opengl icc-profile suboption).
This allows accessing files in the mpv config dir without hardcoding the
config path by prefixing the path with ~~/. Details see manpage
additions.
Diffstat (limited to 'mpvcore/input')
-rw-r--r-- | mpvcore/input/input.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c index f6553e7ba4..f9c7e0c173 100644 --- a/mpvcore/input/input.c +++ b/mpvcore/input/input.c @@ -2156,23 +2156,31 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data, static int parse_config_file(struct input_ctx *ictx, char *file, bool warn) { + int r = 0; + void *tmp = talloc_new(NULL); + stream_t *s = NULL; + + file = mp_get_user_path(tmp, file); if (!mp_path_exists(file)) { MP_MSG(ictx, warn ? MSGL_ERR : MSGL_V, "Input config file %s not found.\n", file); - return 0; + goto done; } - stream_t *s = stream_open(file, NULL); + s = stream_open(file, NULL); if (!s) { MP_ERR(ictx, "Can't open input config file %s.\n", file); - return 0; + goto done; } - bstr res = stream_read_complete(s, NULL, 1000000); - free_stream(s); + bstr data = stream_read_complete(s, tmp, 1000000); MP_VERBOSE(ictx, "Parsing input config file %s\n", file); - int n_binds = parse_config(ictx, false, res, file, NULL); - talloc_free(res.start); + int n_binds = parse_config(ictx, false, data, file, NULL); MP_VERBOSE(ictx, "Input config file %s parsed: %d binds\n", file, n_binds); - return 1; + r = 1; + +done: + free_stream(s); + talloc_free(tmp); + return r; } // If name is NULL, return "default". |