summaryrefslogtreecommitdiffstats
path: root/mpvcore/path.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-14 19:50:00 +0100
committerwm4 <wm4@nowhere>2013-12-14 19:54:49 +0100
commit683d7e88e46463497033eb4759ced45ee8b8cc49 (patch)
treeaa99cebe436f180c2d3c2e070ec4d3896386153a /mpvcore/path.c
parentdcf9f77c58691bde3e4e0ac60e5a5d7e1fc95b42 (diff)
downloadmpv-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/path.c')
-rw-r--r--mpvcore/path.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/mpvcore/path.c b/mpvcore/path.c
index df138489d6..9de11b24d1 100644
--- a/mpvcore/path.c
+++ b/mpvcore/path.c
@@ -97,6 +97,28 @@ char *mp_find_global_config_file(const char *filename)
}
}
+char *mp_get_user_path(void *talloc_ctx, const char *path)
+{
+ if (!path)
+ return NULL;
+ bstr bpath = bstr0(path);
+ if (bstr_eatstart0(&bpath, "~")) {
+ // parse to "~" <prefix> "/" <rest>
+ bstr prefix, rest;
+ if (bstr_split_tok(bpath, "/", &prefix, &rest)) {
+ const char *rest0 = rest.start; // ok in this case
+ char *res = NULL;
+ if (bstr_equals0(prefix, "~"))
+ res = talloc_steal(talloc_ctx, mp_find_user_config_file(rest0));
+ if (bstr_equals0(prefix, ""))
+ res = mp_path_join(talloc_ctx, bstr0(getenv("HOME")), rest);
+ if (res)
+ return res;
+ }
+ }
+ return talloc_strdup(talloc_ctx, path);
+}
+
char *mp_basename(const char *path)
{
char *s;