summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-06 16:48:52 +0100
committerwm4 <wm4@nowhere>2015-02-06 16:48:52 +0100
commitffe894ec0a73ab6a16ce1ca62800bf1612542107 (patch)
tree2ff3877eb428fa191f318d1285ae96f28cb37bb6 /common
parent1a38741dce3e32218521cc2b00819dac1ccebc3a (diff)
downloadmpv-ffe894ec0a73ab6a16ce1ca62800bf1612542107.tar.bz2
mpv-ffe894ec0a73ab6a16ce1ca62800bf1612542107.tar.xz
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.
Diffstat (limited to 'common')
-rw-r--r--common/msg.c47
-rw-r--r--common/msg_control.h4
2 files changed, 17 insertions, 34 deletions
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;
}
diff --git a/common/msg_control.h b/common/msg_control.h
index 57a7d85368..2e1a4ec6bd 100644
--- a/common/msg_control.h
+++ b/common/msg_control.h
@@ -28,9 +28,7 @@ void mp_msg_log_buffer_destroy(struct mp_log_buffer *buffer);
struct mp_log_buffer_entry *mp_msg_log_buffer_read(struct mp_log_buffer *buffer);
int mp_msg_open_stats_file(struct mpv_global *global, const char *path);
-
-struct bstr;
-int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level);
+int mp_msg_find_level(const char *s);
extern const char *const mp_log_levels[MSGL_MAX + 1];
extern const int mp_mpv_log_levels[MSGL_MAX + 1];