summaryrefslogtreecommitdiffstats
path: root/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-23 23:00:54 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:10:32 +0200
commit32c5a87a0131e33e592a2986a8d2d98f2ca963b9 (patch)
treed9917a9fe65b691c2472cf557b1602a8234855b1 /command.c
parentdf2b0f99485e065224af89b910370c394d0ef8d0 (diff)
downloadmpv-32c5a87a0131e33e592a2986a8d2d98f2ca963b9.tar.bz2
mpv-32c5a87a0131e33e592a2986a8d2d98f2ca963b9.tar.xz
commands: change property expansion format string
This affects property format strings like they are used in the "show_text" input command, for --playing-msg, and other places. To quote the documentation comment on m_properties_expand_string(): ${NAME} is expanded to the value of property NAME. If NAME starts with '=', use the raw value of the property. ${NAME:STR} expands to the property, or STR if the property is not available. ${?NAME:STR} expands to STR if the property is available. ${!NAME:STR} expands to STR if the property is not available. STR is recursively expanded using the same rules. "$$" can be used to escape "$", and "$}" to escape "}". "$>" disables parsing of "$" for the rest of the string. Most importantly, "?(property:str)" becomes "${?property:str}". Make the simple fallback case easier, e.g. "${property:fallback}" instead of "${property}?(!property:fallback)". Add the ability to escape the format meta characters. "$" is used for escaping, because escaping with "\" is taken by the commands parser in the layer below. "$>" can be used to disable interpretation of format strings (of course escapes by the commands parser can't be canceled). By default, properties which are unavailable or don't exist are turned into a string signaling the status (e.g. "(unavailable)"), instead of an empty string. If an empty string is desired, this has to be done explicitly: "${property:}" (the fallback part is an empty string). Raw properties still return an empty string on error. m_properties_expand_string() now returns a talloc'ed pointer, instead of a malloc'ed one.
Diffstat (limited to 'command.c')
-rw-r--r--command.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/command.c b/command.c
index 2fcaf2a8bb..a5717961a2 100644
--- a/command.c
+++ b/command.c
@@ -1525,7 +1525,7 @@ char *mp_property_print(const char *name, struct MPContext *ctx)
return ret;
}
-char *property_expand_string(MPContext *mpctx, char *str)
+char *mp_property_expand_string(struct MPContext *mpctx, char *str)
{
return m_properties_expand_string(mp_properties, str, mpctx);
}
@@ -1931,15 +1931,13 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
}
case MP_CMD_SHOW_TEXT: {
- char *txt = m_properties_expand_string(mp_properties,
- cmd->args[0].v.s,
- mpctx);
- // if no argument supplied use default osd_duration, else <arg> ms.
+ char *txt = mp_property_expand_string(mpctx, cmd->args[0].v.s);
if (txt) {
+ // if no argument supplied use default osd_duration, else <arg> ms.
set_osd_msg(mpctx, OSD_MSG_TEXT, cmd->args[2].v.i,
(cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
"%s", txt);
- free(txt);
+ talloc_free(txt);
}
break;
}
@@ -2198,10 +2196,10 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_RUN:
#ifndef __MINGW32__
if (!fork()) {
- char *exp_cmd = property_expand_string(mpctx, cmd->args[0].v.s);
- if (exp_cmd) {
- execl("/bin/sh", "sh", "-c", exp_cmd, NULL);
- free(exp_cmd);
+ char *s = mp_property_expand_string(mpctx, cmd->args[0].v.s);
+ if (s) {
+ execl("/bin/sh", "sh", "-c", s, NULL);
+ talloc_free(s);
}
exit(0);
}