summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-20 22:53:06 +0200
committerwm4 <wm4@nowhere>2013-09-20 23:09:43 +0200
commitf988c6300344492c4a8d8db11c47a4ebed4e858b (patch)
treec4cda2ccf8f4861cc633d9a0fdef84f7af0b6080 /mpvcore
parentab706f996908bf7de3774f36af70ed485e1a0eb9 (diff)
downloadmpv-f988c6300344492c4a8d8db11c47a4ebed4e858b.tar.bz2
mpv-f988c6300344492c4a8d8db11c47a4ebed4e858b.tar.xz
m_property: add a way to switch on property values in property expansion
Allows for example: --status-msg='${?pause==yes:(Paused) } ...' to emulate the normal terminal status line. It's useful in other situations too. I'm a bit worried about extending this mini-DSL, and sure hope nobody will implement a generic formula evaluator at some point in the future. But for now we're probably safe.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/m_property.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/mpvcore/m_property.c b/mpvcore/m_property.c
index 83c6ea1018..6e25bf4e43 100644
--- a/mpvcore/m_property.c
+++ b/mpvcore/m_property.c
@@ -219,14 +219,20 @@ static int expand_property(const m_option_t *prop_list, char **ret, int *ret_len
{
bool cond_yes = bstr_eatstart0(&prop, "?");
bool cond_no = !cond_yes && bstr_eatstart0(&prop, "!");
+ bool test = cond_yes || cond_no;
bool raw = bstr_eatstart0(&prop, "=");
- int method =
- (raw || cond_yes || cond_no) ? M_PROPERTY_GET_STRING : M_PROPERTY_PRINT;
+ bstr comp_with = {0};
+ bool comp = test && bstr_split_tok(prop, "==", &prop, &comp_with);
+ if (test && !comp)
+ raw = true;
+ int method = raw ? M_PROPERTY_GET_STRING : M_PROPERTY_PRINT;
char *s = NULL;
int r = m_property_do_bstr(prop_list, prop, method, &s, ctx);
bool skip;
- if (cond_yes || cond_no) {
+ if (comp) {
+ skip = ((s && bstr_equals0(comp_with, s)) != cond_yes);
+ } else if (test) {
skip = (!!s != cond_yes);
} else {
skip = !!s;