mirror of
https://github.com/mpv-player/mpv
synced 2024-11-07 01:47:00 +01:00
m_option: remove preset mechanism
Was very complicated to use, and its uses have been removed in the previous commits. (While this feature sounded kind of useful, it could be rewritten in a much simpler way, like storing presets as strings, and then using the option parser to apply a preset. The removed code did some major pointer juggling to handle raw values, which made it hard to use.)
This commit is contained in:
parent
bfaebd26ee
commit
5374e26f9e
@ -2189,82 +2189,6 @@ const m_option_type_t m_option_type_obj_settings_list = {
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int parse_obj_presets(const m_option_t *opt, struct bstr name,
|
||||
struct bstr param, void *dst)
|
||||
{
|
||||
m_obj_presets_t *obj_p = (m_obj_presets_t *)opt->priv;
|
||||
const m_struct_t *in_desc;
|
||||
const m_struct_t *out_desc;
|
||||
int s, i;
|
||||
const unsigned char *pre;
|
||||
char *pre_name = NULL;
|
||||
|
||||
if (!obj_p) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: Presets need a "
|
||||
"pointer to a m_obj_presets_t in the priv field.\n",
|
||||
BSTR_P(name));
|
||||
return M_OPT_PARSER_ERR;
|
||||
}
|
||||
|
||||
if (param.len == 0)
|
||||
return M_OPT_MISSING_PARAM;
|
||||
|
||||
pre = obj_p->presets;
|
||||
in_desc = obj_p->in_desc;
|
||||
out_desc = obj_p->out_desc ? obj_p->out_desc : obj_p->in_desc;
|
||||
s = in_desc->size;
|
||||
|
||||
if (!bstrcmp0(param, "help")) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available presets for %s->%.*s:",
|
||||
out_desc->name, BSTR_P(name));
|
||||
for (pre = obj_p->presets;
|
||||
(pre_name = M_ST_MB(char *, pre, obj_p->name_off)); pre += s)
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s", pre_name);
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n");
|
||||
return M_OPT_EXIT - 1;
|
||||
}
|
||||
|
||||
for (pre_name = M_ST_MB(char *, pre, obj_p->name_off); pre_name;
|
||||
pre += s, pre_name = M_ST_MB(char *, pre, obj_p->name_off))
|
||||
if (!bstrcmp0(param, pre_name))
|
||||
break;
|
||||
if (!pre_name) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option %.*s: There is no preset named %.*s\n"
|
||||
"Available presets are:", BSTR_P(name), BSTR_P(param));
|
||||
for (pre = obj_p->presets;
|
||||
(pre_name = M_ST_MB(char *, pre, obj_p->name_off)); pre += s)
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s", pre_name);
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n");
|
||||
return M_OPT_INVALID;
|
||||
}
|
||||
|
||||
if (!dst)
|
||||
return 1;
|
||||
|
||||
for (i = 0; in_desc->fields[i].name; i++) {
|
||||
const m_option_t *out_opt = m_option_list_find(out_desc->fields,
|
||||
in_desc->fields[i].name);
|
||||
if (!out_opt) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option %.*s: Unable to find the target option for field %s.\n"
|
||||
"Please report this to the developers.\n",
|
||||
BSTR_P(name), in_desc->fields[i].name);
|
||||
return M_OPT_PARSER_ERR;
|
||||
}
|
||||
m_option_copy(out_opt, M_ST_MB_P(dst, out_opt->p),
|
||||
M_ST_MB_P(pre, in_desc->fields[i].p));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const m_option_type_t m_option_type_obj_presets = {
|
||||
.name = "Object presets",
|
||||
.parse = parse_obj_presets,
|
||||
};
|
||||
|
||||
static int parse_custom_url(const m_option_t *opt, struct bstr name,
|
||||
struct bstr url, void *dst)
|
||||
{
|
||||
|
@ -118,27 +118,6 @@ typedef struct m_obj_settings {
|
||||
*/
|
||||
extern const m_option_type_t m_option_type_obj_settings_list;
|
||||
|
||||
// Extra definition needed for \ref m_option_type_obj_presets options.
|
||||
typedef struct {
|
||||
// Description of the struct holding the presets.
|
||||
const struct m_struct_st *in_desc;
|
||||
// Description of the struct that should be set by the presets.
|
||||
const struct m_struct_st *out_desc;
|
||||
// Pointer to an array of structs defining the various presets.
|
||||
const void *presets;
|
||||
// Offset of the preset's name inside the in_struct.
|
||||
void *name_off;
|
||||
} m_obj_presets_t;
|
||||
|
||||
// Set several fields in a struct at once.
|
||||
/** For this two struct descriptions are used. One for the struct holding the
|
||||
* preset and one for the struct beeing set. Every field present in both
|
||||
* structs will be copied from the preset struct to the destination one.
|
||||
* The option priv field (\ref m_option::priv) must point to a correctly
|
||||
* filled \ref m_obj_presets_t.
|
||||
*/
|
||||
extern const m_option_type_t m_option_type_obj_presets;
|
||||
|
||||
// Parse an URL into a struct.
|
||||
/** The option priv field (\ref m_option::priv) must point to a
|
||||
* \ref m_struct_st describing which fields of the URL must be used.
|
||||
@ -196,7 +175,6 @@ struct m_sub_options {
|
||||
#define CONF_TYPE_AFMT (&m_option_type_afmt)
|
||||
#define CONF_TYPE_SPAN (&m_option_type_span)
|
||||
#define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list)
|
||||
#define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets)
|
||||
#define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url)
|
||||
#define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params)
|
||||
#define CONF_TYPE_TIME (&m_option_type_time)
|
||||
|
Loading…
Reference in New Issue
Block a user