summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-20 14:46:23 +0100
committerwm4 <wm4@nowhere>2014-02-20 14:46:23 +0100
commit98dc8206ae61a857db6017e7244a9af0e578adc6 (patch)
treeb3a5028a0f75bfa187089e7048f897cb42c7cb50 /player/command.c
parent857952dce3e78e678bf6d14046e2290e7016d6b8 (diff)
downloadmpv-98dc8206ae61a857db6017e7244a9af0e578adc6.tar.bz2
mpv-98dc8206ae61a857db6017e7244a9af0e578adc6.tar.xz
options: handle escape sequences in e.g. --playing-msg differently
M_OPT_PARSE_ESCAPES was pretty stupid, and broke the (useful) assumption that string variables contain exactly the same value as set by the option. Simplify it, and move escape handling to the place where it's used. Escape handling itself is not terribly useful, but still allows useful things like multiline custom OSD with "\n".
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index d9984fc8cb..96b9484781 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2221,6 +2221,27 @@ char *mp_property_expand_string(struct MPContext *mpctx, const char *str)
return m_properties_expand_string(mp_properties, str, mpctx);
}
+// Before expanding properties, parse C-style escapes like "\n"
+char *mp_property_expand_escaped_string(struct MPContext *mpctx, const char *str)
+{
+ void *tmp = talloc_new(NULL);
+ bstr strb = bstr0(str);
+ bstr dst = {0};
+ while (strb.len) {
+ if (!mp_append_escaped_string(tmp, &dst, &strb)) {
+ talloc_free(tmp);
+ return talloc_strdup(NULL, "(broken escape sequences)");
+ }
+ // pass " through literally
+ if (!bstr_eatstart0(&strb, "\""))
+ break;
+ bstr_xappend(tmp, &dst, bstr0("\""));
+ }
+ char *r = mp_property_expand_string(mpctx, dst.start);
+ talloc_free(tmp);
+ return r;
+}
+
void property_print_help(struct mp_log *log)
{
m_properties_print_help_list(log, mp_properties);