2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \file
|
|
|
|
/// \ingroup Properties
|
|
|
|
|
2006-03-22 00:19:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
2012-09-21 10:15:47 +00:00
|
|
|
#include <assert.h>
|
2006-03-22 00:19:02 +00:00
|
|
|
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2011-07-03 17:04:21 +00:00
|
|
|
#include "talloc.h"
|
2006-03-22 00:19:02 +00:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_property.h"
|
2006-03-22 16:35:17 +00:00
|
|
|
#include "mp_msg.h"
|
2011-01-03 19:39:31 +00:00
|
|
|
#include "mpcommon.h"
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2012-09-26 21:56:29 +00:00
|
|
|
const struct m_option_type m_option_type_dummy = {
|
|
|
|
.name = "Unknown",
|
|
|
|
};
|
|
|
|
|
2012-09-27 01:12:32 +00:00
|
|
|
struct legacy_prop {
|
|
|
|
const char *old, *new;
|
|
|
|
};
|
|
|
|
static const struct legacy_prop legacy_props[] = {
|
|
|
|
{"switch_video", "video"},
|
|
|
|
{"switch_audio", "audio"},
|
|
|
|
{"switch_program", "program"},
|
|
|
|
{"framedropping", "framedrop"},
|
|
|
|
{"osdlevel", "osd-level"},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool translate_legacy_property(const char *name, char *buffer,
|
|
|
|
size_t buffer_size)
|
|
|
|
{
|
|
|
|
if (strlen(name) + 1 > buffer_size)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const char *old_name = name;
|
|
|
|
|
|
|
|
for (int n = 0; legacy_props[n].new; n++) {
|
|
|
|
if (strcmp(name, legacy_props[n].old) == 0) {
|
|
|
|
name = legacy_props[n].new;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buffer, buffer_size, "%s", name);
|
|
|
|
|
|
|
|
// Old names used "_" instead of "-"
|
|
|
|
for (int n = 0; buffer[n]; n++) {
|
|
|
|
if (buffer[n] == '_')
|
|
|
|
buffer[n] = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(old_name, buffer) != 0) {
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_V, "Warning: property '%s' is deprecated, "
|
|
|
|
"replaced with '%s'. Fix your input.conf!\n", old_name, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
static int do_action(const m_option_t *prop_list, const char *name,
|
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
|
|
|
const char *sep;
|
|
|
|
const m_option_t *prop;
|
|
|
|
if ((sep = strchr(name, '/')) && sep[1]) {
|
|
|
|
int len = sep - name;
|
|
|
|
char base[len + 1];
|
|
|
|
memcpy(base, name, len);
|
2007-05-29 21:49:39 +00:00
|
|
|
base[len] = 0;
|
|
|
|
prop = m_option_list_find(prop_list, base);
|
2012-09-22 04:15:36 +00:00
|
|
|
struct m_property_action_arg ka = {
|
2012-09-21 10:19:59 +00:00
|
|
|
.key = sep + 1,
|
|
|
|
.action = action,
|
|
|
|
.arg = arg,
|
|
|
|
};
|
2007-05-29 21:49:39 +00:00
|
|
|
action = M_PROPERTY_KEY_ACTION;
|
|
|
|
arg = &ka;
|
|
|
|
} else
|
|
|
|
prop = m_option_list_find(prop_list, name);
|
2011-07-03 12:42:04 +00:00
|
|
|
if (!prop)
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
2012-09-21 10:15:47 +00:00
|
|
|
int (*control)(const m_option_t*, int, void*, void*) = prop->p;
|
2012-09-21 10:19:59 +00:00
|
|
|
int r = control(prop, action, arg, ctx);
|
2012-09-26 21:56:29 +00:00
|
|
|
if (action == M_PROPERTY_GET_TYPE && r < 0 &&
|
|
|
|
prop->type != &m_option_type_dummy)
|
|
|
|
{
|
2012-09-21 12:05:52 +00:00
|
|
|
*(struct m_option *)arg = *prop;
|
2007-05-29 21:49:39 +00:00
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
2007-05-29 21:49:39 +00:00
|
|
|
return r;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 01:12:32 +00:00
|
|
|
int m_property_do(const m_option_t *prop_list, const char *in_name,
|
2011-07-03 12:42:04 +00:00
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
2012-09-18 14:08:17 +00:00
|
|
|
union m_option_value val = {0};
|
2006-03-22 00:19:02 +00:00
|
|
|
int r;
|
2012-09-21 10:15:47 +00:00
|
|
|
|
2012-09-27 01:12:32 +00:00
|
|
|
char name[64];
|
|
|
|
if (!translate_legacy_property(in_name, name, sizeof(name)))
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
|
2012-09-21 12:05:52 +00:00
|
|
|
struct m_option opt = {0};
|
2012-09-21 10:15:47 +00:00
|
|
|
r = do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx);
|
|
|
|
if (r <= 0)
|
|
|
|
return r;
|
2012-09-21 12:05:52 +00:00
|
|
|
assert(opt.type);
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
switch (action) {
|
2012-09-21 10:15:47 +00:00
|
|
|
case M_PROPERTY_PRINT: {
|
2011-07-03 12:42:04 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_PRINT, arg, ctx)) >= 0)
|
2007-05-29 21:49:39 +00:00
|
|
|
return r;
|
2012-09-18 14:08:17 +00:00
|
|
|
// Fallback to m_option
|
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
2012-09-18 13:31:46 +00:00
|
|
|
return r;
|
2012-09-21 12:05:52 +00:00
|
|
|
char *str = m_option_pretty_print(&opt, &val);
|
|
|
|
m_option_free(&opt, &val);
|
2012-09-18 13:31:46 +00:00
|
|
|
*(char **)arg = str;
|
|
|
|
return str != NULL;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
2012-09-22 06:04:08 +00:00
|
|
|
case M_PROPERTY_GET_STRING: {
|
2012-09-18 14:08:17 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
2007-05-29 21:49:39 +00:00
|
|
|
return r;
|
2012-09-21 12:05:52 +00:00
|
|
|
char *str = m_option_print(&opt, &val);
|
|
|
|
m_option_free(&opt, &val);
|
2011-07-03 17:04:21 +00:00
|
|
|
*(char **)arg = str;
|
|
|
|
return str != NULL;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
2012-09-22 06:04:08 +00:00
|
|
|
case M_PROPERTY_SET_STRING: {
|
2012-09-21 10:15:47 +00:00
|
|
|
// (reject 0 return value: success, but empty string with flag)
|
2012-09-22 06:04:08 +00:00
|
|
|
if (m_option_parse(&opt, bstr0(name), bstr0(arg), &val) <= 0)
|
2012-09-21 10:15:47 +00:00
|
|
|
return M_PROPERTY_ERROR;
|
2012-09-18 14:08:17 +00:00
|
|
|
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
|
2012-09-21 12:05:52 +00:00
|
|
|
m_option_free(&opt, &val);
|
2006-03-22 00:19:02 +00:00
|
|
|
return r;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
|
|
|
case M_PROPERTY_SWITCH: {
|
2012-09-22 04:15:36 +00:00
|
|
|
struct m_property_switch_arg *sarg = arg;
|
2012-09-18 12:00:08 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_SWITCH, arg, ctx)) !=
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED)
|
|
|
|
return r;
|
|
|
|
// Fallback to m_option
|
2012-09-21 12:05:52 +00:00
|
|
|
if (!opt.type->add)
|
2012-09-18 12:00:08 +00:00
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
2012-09-18 14:08:17 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
2012-09-18 12:00:08 +00:00
|
|
|
return r;
|
2012-09-22 04:15:36 +00:00
|
|
|
opt.type->add(&opt, &val, sarg->inc, sarg->wrap);
|
2012-09-18 14:08:17 +00:00
|
|
|
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
|
2012-09-21 12:05:52 +00:00
|
|
|
m_option_free(&opt, &val);
|
2012-09-18 12:00:08 +00:00
|
|
|
return r;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
|
|
|
case M_PROPERTY_SET: {
|
2012-09-21 12:05:52 +00:00
|
|
|
if (!opt.type->clamp) {
|
2012-09-18 15:05:11 +00:00
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_WARN, "Property '%s' without clamp().\n",
|
|
|
|
name);
|
|
|
|
} else {
|
2012-09-21 12:05:52 +00:00
|
|
|
m_option_copy(&opt, &val, arg);
|
|
|
|
r = opt.type->clamp(&opt, arg);
|
|
|
|
m_option_free(&opt, &val);
|
2012-09-18 15:05:11 +00:00
|
|
|
if (r != 0) {
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_ERR,
|
|
|
|
"Property '%s': invalid value.\n", name);
|
|
|
|
return M_PROPERTY_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return do_action(prop_list, name, M_PROPERTY_SET, arg, ctx);
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
2012-09-21 10:15:47 +00:00
|
|
|
default:
|
|
|
|
return do_action(prop_list, name, action, arg, ctx);
|
|
|
|
}
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
static int m_property_do_bstr(const m_option_t *prop_list, bstr name,
|
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
|
|
|
char name0[64];
|
|
|
|
if (name.len >= sizeof(name0))
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
snprintf(name0, sizeof(name0), "%.*s", BSTR_P(name));
|
|
|
|
return m_property_do(prop_list, name0, action, arg, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void append_str(char **s, int *len, bstr append)
|
|
|
|
{
|
|
|
|
MP_TARRAY_GROW(NULL, *s, *len + append.len);
|
|
|
|
memcpy(*s + *len, append.start, append.len);
|
|
|
|
*len = *len + append.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *m_properties_expand_string(const m_option_t *prop_list, char *str0,
|
2011-07-03 12:42:04 +00:00
|
|
|
void *ctx)
|
|
|
|
{
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
int ret_len = 0;
|
|
|
|
bool skip = false;
|
|
|
|
int level = 0, skip_level = 0;
|
|
|
|
bstr str = bstr0(str0);
|
|
|
|
|
|
|
|
while (str.len) {
|
|
|
|
if (level > 0 && bstr_eatstart0(&str, "}")) {
|
|
|
|
if (skip && level <= skip_level)
|
|
|
|
skip = false;
|
|
|
|
level--;
|
|
|
|
} else if (bstr_startswith0(str, "${") && bstr_find0(str, "}") >= 0) {
|
|
|
|
str = bstr_cut(str, 2);
|
|
|
|
level++;
|
|
|
|
|
|
|
|
// Assume ":" and "}" can't be part of the property name
|
|
|
|
// => if ":" comes before "}", it must be for the fallback
|
|
|
|
int term_pos = bstrcspn(str, ":}");
|
|
|
|
bstr name = bstr_splice(str, 0, term_pos < 0 ? str.len : term_pos);
|
|
|
|
str = bstr_cut(str, term_pos);
|
|
|
|
bool have_fallback = bstr_eatstart0(&str, ":");
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
if (!skip) {
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
bool cond_yes = bstr_eatstart0(&name, "?");
|
|
|
|
bool cond_no = !cond_yes && bstr_eatstart0(&name, "!");
|
|
|
|
bool raw = bstr_eatstart0(&name, "=");
|
|
|
|
int method = (raw || cond_yes || cond_no)
|
|
|
|
? M_PROPERTY_GET_STRING : M_PROPERTY_PRINT;
|
|
|
|
|
|
|
|
char *s = NULL;
|
|
|
|
int r = m_property_do_bstr(prop_list, name, method, &s, ctx);
|
|
|
|
if (cond_yes || cond_no) {
|
|
|
|
skip = (!!s != cond_yes);
|
|
|
|
} else {
|
|
|
|
skip = !!s;
|
|
|
|
char *append = s;
|
|
|
|
if (!s && !have_fallback && !raw) {
|
|
|
|
append = r == M_PROPERTY_UNAVAILABLE
|
|
|
|
? "(unavailable)" : "(error)";
|
|
|
|
}
|
|
|
|
append_str(&ret, &ret_len, bstr0(append));
|
|
|
|
}
|
|
|
|
talloc_free(s);
|
|
|
|
if (skip)
|
|
|
|
skip_level = level;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
} else if (level == 0 && bstr_eatstart0(&str, "$>")) {
|
|
|
|
append_str(&ret, &ret_len, str);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
char c;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
// Other combinations, e.g. "$x", are added verbatim
|
|
|
|
if (bstr_eatstart0(&str, "$$")) {
|
|
|
|
c = '$';
|
|
|
|
} else if (bstr_eatstart0(&str, "$}")) {
|
|
|
|
c = '}';
|
|
|
|
} else {
|
|
|
|
c = str.start[0];
|
|
|
|
str = bstr_cut(str, 1);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
if (!skip)
|
|
|
|
MP_TARRAY_APPEND(NULL, ret, ret_len, c);
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
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.
2012-09-23 21:00:54 +00:00
|
|
|
MP_TARRAY_APPEND(NULL, ret, ret_len, '\0');
|
2006-03-22 00:19:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
void m_properties_print_help_list(const m_option_t *list)
|
|
|
|
{
|
|
|
|
char min[50], max[50];
|
|
|
|
int i, count = 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
mp_tmsg(MSGT_CFGPARSER, MSGL_INFO,
|
|
|
|
"\n Name Type Min Max\n\n");
|
|
|
|
for (i = 0; list[i].name; i++) {
|
|
|
|
const m_option_t *opt = &list[i];
|
|
|
|
if (opt->flags & M_OPT_MIN)
|
|
|
|
sprintf(min, "%-8.0f", opt->min);
|
2006-03-22 16:35:17 +00:00
|
|
|
else
|
2011-07-03 12:42:04 +00:00
|
|
|
strcpy(min, "No");
|
|
|
|
if (opt->flags & M_OPT_MAX)
|
|
|
|
sprintf(max, "%-8.0f", opt->max);
|
2006-03-22 16:35:17 +00:00
|
|
|
else
|
2011-07-03 12:42:04 +00:00
|
|
|
strcpy(max, "No");
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_INFO,
|
|
|
|
" %-20.20s %-15.15s %-10.10s %-10.10s\n",
|
2006-03-22 16:35:17 +00:00
|
|
|
opt->name,
|
|
|
|
opt->type->name,
|
|
|
|
min,
|
2006-03-23 00:41:22 +00:00
|
|
|
max);
|
2006-03-22 16:35:17 +00:00
|
|
|
count++;
|
|
|
|
}
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d properties\n", count);
|
2006-03-22 16:35:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
int m_property_int_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, int var)
|
|
|
|
{
|
2012-09-18 18:07:24 +00:00
|
|
|
if (action == M_PROPERTY_GET) {
|
2011-07-03 12:42:04 +00:00
|
|
|
*(int *)arg = var;
|
2012-09-18 18:07:24 +00:00
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-10-14 21:08:39 +00:00
|
|
|
int m_property_int64_ro(const struct m_option* prop, int action, void* arg,
|
|
|
|
int64_t var)
|
|
|
|
{
|
|
|
|
if (action == M_PROPERTY_GET) {
|
|
|
|
*(int64_t *)arg = var;
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
int m_property_float_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, float var)
|
|
|
|
{
|
2012-09-18 18:07:24 +00:00
|
|
|
if (action == M_PROPERTY_GET) {
|
2011-07-03 12:42:04 +00:00
|
|
|
*(float *)arg = var;
|
2012-09-18 18:07:24 +00:00
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
int m_property_double_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, double var)
|
|
|
|
{
|
2012-09-18 18:07:24 +00:00
|
|
|
if (action == M_PROPERTY_GET) {
|
2011-07-03 12:42:04 +00:00
|
|
|
*(double *)arg = var;
|
2012-09-18 18:07:24 +00:00
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
2012-10-14 21:08:39 +00:00
|
|
|
|
|
|
|
int m_property_strdup_ro(const struct m_option* prop, int action, void* arg,
|
|
|
|
const char *var)
|
|
|
|
{
|
|
|
|
if (action == M_PROPERTY_GET) {
|
|
|
|
*(char **)arg = talloc_strdup(NULL, var);
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|