mirror of https://github.com/mpv-player/mpv
command: make options property return the list of all options
This commit is contained in:
parent
38a36fd7ea
commit
4d1575173b
|
@ -708,6 +708,26 @@ void m_config_print_option_list(const struct m_config *config)
|
|||
MP_INFO(config, "\nTotal: %d options\n", count);
|
||||
}
|
||||
|
||||
char **m_config_list_options(void *ta_parent, const struct m_config *config)
|
||||
{
|
||||
char **list = talloc_new(ta_parent);
|
||||
int count = 0;
|
||||
for (int i = 0; i < config->num_opts; i++) {
|
||||
struct m_config_option *co = &config->opts[i];
|
||||
const struct m_option *opt = co->opt;
|
||||
if (opt->type->flags & M_OPT_TYPE_HAS_CHILD)
|
||||
continue;
|
||||
if (co->is_generated)
|
||||
continue;
|
||||
// For use with CONF_TYPE_STRING_LIST, it's important not to set list
|
||||
// as allocation parent.
|
||||
char *s = talloc_strdup(ta_parent, co->name);
|
||||
MP_TARRAY_APPEND(ta_parent, list, count, s);
|
||||
}
|
||||
MP_TARRAY_APPEND(ta_parent, list, count, NULL);
|
||||
return list;
|
||||
}
|
||||
|
||||
struct m_profile *m_config_get_profile(const struct m_config *config, bstr name)
|
||||
{
|
||||
for (struct m_profile *p = config->profiles; p; p = p->next) {
|
||||
|
|
|
@ -170,6 +170,9 @@ const char *m_config_get_positional_option(const struct m_config *config, int n)
|
|||
// Returns: error code (<0), or number of expected params (0, 1)
|
||||
int m_config_option_requires_param(struct m_config *config, bstr name);
|
||||
|
||||
// Return all (visible) option names as NULL terminated string list.
|
||||
char **m_config_list_options(void *ta_parent, const struct m_config *config);
|
||||
|
||||
/* Print a list of all registered options.
|
||||
* \param config The config object.
|
||||
*/
|
||||
|
|
|
@ -1977,14 +1977,8 @@ static int mp_property_alias(m_option_t *prop, int action, void *arg,
|
|||
return mp_property_do(real_property, action, arg, mpctx);
|
||||
}
|
||||
|
||||
static int mp_property_options(m_option_t *prop, int action, void *arg,
|
||||
MPContext *mpctx)
|
||||
static int access_options(struct m_property_action_arg *ka, MPContext *mpctx)
|
||||
{
|
||||
if (action != M_PROPERTY_KEY_ACTION)
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
|
||||
struct m_property_action_arg *ka = arg;
|
||||
|
||||
struct m_config_option *opt = m_config_get_co(mpctx->mconfig,
|
||||
bstr0(ka->key));
|
||||
if (!opt)
|
||||
|
@ -2008,7 +2002,22 @@ static int mp_property_options(m_option_t *prop, int action, void *arg,
|
|||
*(struct m_option *)ka->arg = *opt->opt;
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static int mp_property_options(m_option_t *prop, int action, void *arg,
|
||||
MPContext *mpctx)
|
||||
{
|
||||
switch (action) {
|
||||
case M_PROPERTY_GET_TYPE:
|
||||
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST};
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_GET:
|
||||
*(char ***)arg = m_config_list_options(NULL, mpctx->mconfig);
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_KEY_ACTION:
|
||||
return access_options(arg, mpctx);
|
||||
}
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue