diff options
author | wm4 <wm4@nowhere> | 2012-09-23 23:00:54 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-10-12 10:10:32 +0200 |
commit | 32c5a87a0131e33e592a2986a8d2d98f2ca963b9 (patch) | |
tree | d9917a9fe65b691c2472cf557b1602a8234855b1 /screenshot.c | |
parent | df2b0f99485e065224af89b910370c394d0ef8d0 (diff) | |
download | mpv-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 'screenshot.c')
-rw-r--r-- | screenshot.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/screenshot.c b/screenshot.c index 7fb5fd9507..1f2b0694fc 100644 --- a/screenshot.c +++ b/screenshot.c @@ -66,19 +66,6 @@ static char *stripext(void *talloc_ctx, const char *s) return talloc_asprintf(talloc_ctx, "%.*s", end - s, s); } -static char *do_format_property(struct MPContext *mpctx, struct bstr s) { - struct bstr prop_name = s; - int fallbackpos = bstrchr(s, ':'); - if (fallbackpos >= 0) - prop_name = bstr_splice(prop_name, 0, fallbackpos); - char *pn = bstrdup0(NULL, prop_name); - char *res = mp_property_print(pn, mpctx); - talloc_free(pn); - if (!res && fallbackpos >= 0) - res = bstrdup0(NULL, bstr_cut(s, fallbackpos + 1)); - return res; -} - #ifdef _WIN32 #define ILLEGAL_FILENAME_CHARS "?\"/\\<>*|:" #else @@ -186,11 +173,13 @@ static char *create_fname(struct MPContext *mpctx, char *template, if (!end) goto error_exit; struct bstr prop = bstr_splice(bstr0(template), 0, end - template); - template = end + 1; - char *s = do_format_property(mpctx, prop); + char *tmp = talloc_asprintf(NULL, "${%.*s}", BSTR_P(prop)); + char *s = mp_property_expand_string(mpctx, tmp); + talloc_free(tmp); if (s) append_filename(&res, s); talloc_free(s); + template = end + 1; break; } case '%': |