From ad2199128da4a689be374e92aab57ac2c9fa76b9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 20:45:19 +0100 Subject: path lookup functions: mp_msg conversions There's a single mp_msg() in path.c, but all path lookup functions seem to depend on it, so we get a rat-tail of stuff we have to change. This is probably a good thing though, because we can have the path lookup functions also access options, so we could allow overriding the default config path, or ignore the MPV_HOME environment variable, and such things. Also take the chance to consistently add talloc_ctx parameters to the path lookup functions. Also, this change causes a big mess on configfiles.c. It's the same issue: everything suddenly needs a (different) context argument. Make it less wild by providing a mp_load_auto_profiles() function, which isolates most of it to configfiles.c. --- options/path.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'options/path.c') diff --git a/options/path.c b/options/path.c index 43c2c0fb80..17d6245582 100644 --- a/options/path.c +++ b/options/path.c @@ -33,13 +33,14 @@ #include #include #include "config.h" +#include "common/global.h" #include "common/msg.h" #include "options/path.h" #include "talloc.h" #include "osdep/io.h" #include "osdep/path.h" -typedef char *(*lookup_fun)(const char *); +typedef char *(*lookup_fun)(void *tctx, struct mpv_global *global, const char *); static const lookup_fun config_lookup_functions[] = { mp_find_user_config_file, #if HAVE_COCOA @@ -49,10 +50,11 @@ static const lookup_fun config_lookup_functions[] = { NULL }; -char *mp_find_config_file(const char *filename) +char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, + const char *filename) { for (int i = 0; config_lookup_functions[i] != NULL; i++) { - char *path = config_lookup_functions[i](filename); + char *path = config_lookup_functions[i](talloc_ctx, global, filename); if (!path) continue; if (mp_path_exists(path)) @@ -63,7 +65,8 @@ char *mp_find_config_file(const char *filename) return NULL; } -char *mp_find_user_config_file(const char *filename) +char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global, + const char *filename) { char *homedir = getenv("MPV_HOME"); char *configdir = NULL; @@ -71,7 +74,7 @@ char *mp_find_user_config_file(const char *filename) if (!homedir) { #ifdef _WIN32 - result = mp_get_win_config_path(filename); + result = talloc_steal(talloc_ctx, mp_get_win_config_path(filename)); #endif homedir = getenv("HOME"); configdir = ".mpv"; @@ -79,25 +82,27 @@ char *mp_find_user_config_file(const char *filename) if (!result && homedir) { char *temp = mp_path_join(NULL, bstr0(homedir), bstr0(configdir)); - result = mp_path_join(NULL, bstr0(temp), bstr0(filename)); + result = mp_path_join(talloc_ctx, bstr0(temp), bstr0(filename)); talloc_free(temp); } - mp_msg(MSGT_GLOBAL, MSGL_V, "mp_find_user_config_file('%s') -> '%s'\n", - filename ? filename : "(NULL)", result ? result : "(NULL)"); + MP_VERBOSE(global, "mp_find_user_config_file('%s') -> '%s'\n", + filename ? filename : "(NULL)", result ? result : "(NULL)"); return result; } -char *mp_find_global_config_file(const char *filename) +char *mp_find_global_config_file(void *talloc_ctx, struct mpv_global *global, + const char *filename) { if (filename) { - return mp_path_join(NULL, bstr0(MPLAYER_CONFDIR), bstr0(filename)); + return mp_path_join(talloc_ctx, bstr0(MPLAYER_CONFDIR), bstr0(filename)); } else { - return talloc_strdup(NULL, MPLAYER_CONFDIR); + return talloc_strdup(talloc_ctx, MPLAYER_CONFDIR); } } -char *mp_get_user_path(void *talloc_ctx, const char *path) +char *mp_get_user_path(void *talloc_ctx, struct mpv_global *global, + const char *path) { if (!path) return NULL; @@ -108,10 +113,11 @@ char *mp_get_user_path(void *talloc_ctx, const char *path) 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, "")) + if (bstr_equals0(prefix, "~")) { + res = mp_find_user_config_file(talloc_ctx, global, rest0); + } else if (bstr_equals0(prefix, "")) { res = mp_path_join(talloc_ctx, bstr0(getenv("HOME")), rest); + } if (res) return res; } @@ -225,10 +231,10 @@ bool mp_is_url(bstr path) return true; } -void mp_mk_config_dir(char *subdir) +void mp_mk_config_dir(struct mpv_global *global, char *subdir) { void *tmp = talloc_new(NULL); - char *confdir = talloc_steal(tmp, mp_find_user_config_file("")); + char *confdir = mp_find_user_config_file(tmp, global, ""); if (confdir) { if (subdir) confdir = mp_path_join(tmp, bstr0(confdir), bstr0(subdir)); -- cgit v1.2.3