From fab9febdc3a863c157a56cc4de2418cbb9665844 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 9 Dec 2012 15:05:21 +0100 Subject: path: add mp_find_config_file and reorganize some of the code Add `mp_find_config_file` to search different known paths and use that in ass_mp to look for the fontconfig configuration file. Some incidental changes spawned by this feature where: * Buffer allocation for the strings containing the paths is now performed with talloc. All of the allocations are done on a NULL context, but it still improves readability of the code. * Move the OSX function for lookup inside of a bundle: this code path was currently not used by the bundle generated with `make osxbundle`. The plan is to use it again in a future commit to get a fontconfig config file. --- sub/ass_mp.c | 19 +++++++------------ sub/find_subfiles.c | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) (limited to 'sub') diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 36e03fb2d6..c992f017f7 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -255,23 +255,18 @@ void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, void mp_ass_configure_fonts(ASS_Renderer *priv, struct osd_style_opts *opts) { - char *default_font = get_path("subfont.ttf"); - char *config = get_path("fonts.conf"); + char *default_font = mp_find_user_config_file("subfont.ttf"); + char *config = mp_find_config_file("fonts.conf"); if (!mp_path_exists(default_font)) { - free(default_font); + talloc_free(default_font); default_font = NULL; } - if (!mp_path_exists(config)) { - free(config); - config = NULL; - } - ass_set_fonts(priv, default_font, opts->font, 1, config, 1); - free(default_font); - free(config); + talloc_free(default_font); + talloc_free(config); } void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time, @@ -332,11 +327,11 @@ static void message_callback(int level, const char *format, va_list va, void *ct ASS_Library *mp_ass_init(struct MPOpts *opts) { ASS_Library *priv; - char *path = get_path("fonts"); + char *path = mp_find_user_config_file("fonts"); priv = ass_library_init(); ass_set_message_cb(priv, message_callback, NULL); ass_set_fonts_dir(priv, path); ass_set_extract_fonts(priv, opts->use_embedded_fonts); - free(path); + talloc_free(path); return priv; } diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index 95004b564f..aa8df2ea49 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -212,10 +212,10 @@ char **find_text_subtitles(struct MPOpts *opts, const char *fname) } // Load subtitles in ~/.mplayer/sub limiting sub fuzziness - char *mp_subdir = get_path("sub/"); + char *mp_subdir = mp_find_user_config_file("sub/"); if (mp_subdir) append_dir_subtitles(opts, &slist, &n, bstr0(mp_subdir), fname, 1); - free(mp_subdir); + talloc_free(mp_subdir); // Sort subs by priority and append them qsort(slist, n, sizeof(*slist), compare_sub_priority); -- cgit v1.2.3