From ffe894ec0a73ab6a16ce1ca62800bf1612542107 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 6 Feb 2015 16:48:52 +0100 Subject: options: change --msg-level option Make it accept "," as separator, instead of only ":". Do this by using the key-value-list parser. Before this, the option was stored as a string, with the option parser verifying that the option value as correct. Now it's stored pre-parsed, although the log levels still require separate verification and parsing-on-use to some degree (which is why the msg-level option type doesn't go away). Because the internal type changes, the client API "native" type also changes. This could be prevented with some more effort, but I don't think it's worth it - if MPV_FORMAT_STRING is used, it still works the same, just with a different separator on read accesses. --- common/msg.c | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'common/msg.c') diff --git a/common/msg.c b/common/msg.c index 33c8d419df..3092845a02 100644 --- a/common/msg.c +++ b/common/msg.c @@ -48,7 +48,7 @@ struct mp_log_root { struct mpv_global *global; // --- protected by mp_msg_lock - char *msglevels; + char **msg_levels; bool use_terminal; // make accesses to stderr/stdout bool module; bool show_time; @@ -96,28 +96,26 @@ static pthread_mutex_t mp_msg_lock = PTHREAD_MUTEX_INITIALIZER; static const struct mp_log null_log = {0}; struct mp_log *const mp_null_log = (struct mp_log *)&null_log; -static bool match_mod(const char *name, bstr mod) +static bool match_mod(const char *name, const char *mod) { - if (bstr_equals0(mod, "all")) + if (!strcmp(mod, "all")) return true; // Path prefix matches bstr b = bstr0(name); - return bstr_eatstart(&b, mod) && (bstr_eatstart0(&b, "/") || !b.len); + return bstr_eatstart0(&b, mod) && (bstr_eatstart0(&b, "/") || !b.len); } static void update_loglevel(struct mp_log *log) { + struct mp_log_root *root = log->root; pthread_mutex_lock(&mp_msg_lock); log->level = -1; log->terminal_level = -1; if (log->root->use_terminal) { log->level = MSGL_STATUS + log->root->verbose; // default log level - bstr s = bstr0(log->root->msglevels); - bstr mod; - int level; - while (mp_msg_split_msglevel(&s, &mod, &level) > 0) { - if (match_mod(log->verbose_prefix, mod)) - log->level = level; + for (int n = 0; root->msg_levels && root->msg_levels[n * 2 + 0]; n++) { + if (match_mod(log->verbose_prefix, root->msg_levels[n * 2 + 0])) + log->level = mp_msg_find_level(root->msg_levels[n * 2 + 1]); } log->terminal_level = log->root->use_terminal ? log->level : -1; } @@ -475,8 +473,9 @@ void mp_msg_update_msglevels(struct mpv_global *global) root->termosd = isatty(STDERR_FILENO); } - talloc_free(root->msglevels); - root->msglevels = talloc_strdup(root, global->opts->msglevels); + m_option_type_msglevels.free(&root->msg_levels); + m_option_type_msglevels.copy(NULL, &root->msg_levels, + &global->opts->msg_levels); if (!root->log_file && opts->log_file && opts->log_file[0]) root->log_file = fopen(opts->log_file, "wb"); @@ -506,6 +505,7 @@ void mp_msg_uninit(struct mpv_global *global) fclose(root->stats_file); if (root->log_file) fclose(root->log_file); + m_option_type_msglevels.free(&root->msg_levels); talloc_free(root); global->log = NULL; } @@ -639,26 +639,11 @@ const int mp_mpv_log_levels[MSGL_MAX + 1] = { [MSGL_STATS] = 0, // never used }; -int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level) +int mp_msg_find_level(const char *s) { - if (s->len == 0) - return 0; - bstr elem, rest; - bstr_split_tok(*s, ":", &elem, &rest); - bstr mod, level; - if (!bstr_split_tok(elem, "=", &mod, &level) || mod.len == 0) - return -1; - int ilevel = -1; for (int n = 0; n < MP_ARRAY_SIZE(mp_log_levels); n++) { - if (mp_log_levels[n] && bstr_equals0(level, mp_log_levels[n])) { - ilevel = n; - break; - } + if (mp_log_levels[n] && mp_log_levels[n] && !strcmp(s, mp_log_levels[n])) + return n; } - if (ilevel < 0 && !bstr_equals0(level, "no")) - return -1; - *s = rest; - *out_mod = mod; - *out_level = ilevel; - return 1; + return -1; } -- cgit v1.2.3