options: const annotate all m_opt_choice_alternatives accessors

Constant data, most accessors are good but some were missing the
explicit notation.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
This commit is contained in:
Emil Velikov 2021-10-03 18:31:45 +01:00 committed by Dudemanguy
parent f09396ab7d
commit b44f522dba
3 changed files with 17 additions and 16 deletions

View File

@ -858,7 +858,7 @@ void m_config_print_option_list(const struct m_config *config, const char *name)
MP_INFO(config, " %s%-30s", prefix, co->name);
if (opt->type == &m_option_type_choice) {
MP_INFO(config, " Choices:");
struct m_opt_choice_alternatives *alt = opt->priv;
const struct m_opt_choice_alternatives *alt = opt->priv;
for (int n = 0; alt[n].name; n++)
MP_INFO(config, " %s", alt[n].name);
if (opt->min < opt->max)

View File

@ -111,7 +111,7 @@ int m_option_required_params(const m_option_t *opt)
if (opt->flags & M_OPT_OPTIONAL_PARAM)
return 0;
if (opt->type == &m_option_type_choice) {
struct m_opt_choice_alternatives *alt;
const struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++) {
if (strcmp(alt->name, "yes") == 0)
return 0;
@ -620,7 +620,7 @@ const char *m_opt_choice_str(const struct m_opt_choice_alternatives *choices,
static void print_choice_values(struct mp_log *log, const struct m_option *opt)
{
struct m_opt_choice_alternatives *alt = opt->priv;
const struct m_opt_choice_alternatives *alt = opt->priv;
for ( ; alt->name; alt++)
mp_info(log, " %s\n", alt->name[0] ? alt->name : "(passing nothing)");
if (opt->min < opt->max)
@ -630,7 +630,7 @@ static void print_choice_values(struct mp_log *log, const struct m_option *opt)
static int parse_choice(struct mp_log *log, const struct m_option *opt,
struct bstr name, struct bstr param, void *dst)
{
struct m_opt_choice_alternatives *alt = opt->priv;
const struct m_opt_choice_alternatives *alt = opt->priv;
for ( ; alt->name; alt++) {
if (!bstrcmp0(param, alt->name))
break;
@ -677,7 +677,7 @@ static void choice_get_min_max(const struct m_option *opt, int *min, int *max)
assert(opt->type == &m_option_type_choice);
*min = INT_MAX;
*max = INT_MIN;
for (struct m_opt_choice_alternatives *alt = opt->priv; alt->name; alt++) {
for (const struct m_opt_choice_alternatives *alt = opt->priv; alt->name; alt++) {
*min = MPMIN(*min, alt->value);
*max = MPMAX(*max, alt->value);
}
@ -721,7 +721,7 @@ static void add_choice(const m_option_t *opt, void *val, double add, bool wrap)
}
}
for (struct m_opt_choice_alternatives *alt = opt->priv; alt->name; alt++)
for (const struct m_opt_choice_alternatives *alt = opt->priv; alt->name; alt++)
check_choice(dir, ival, &found, &best, alt->value);
if (!found) {
@ -754,11 +754,12 @@ static int choice_set(const m_option_t *opt, void *dst, struct mpv_node *src)
return r;
}
static struct m_opt_choice_alternatives *get_choice(const m_option_t *opt,
const void *val, int *out_val)
static const struct m_opt_choice_alternatives *get_choice(const m_option_t *opt,
const void *val,
int *out_val)
{
int v = *(int *)val;
struct m_opt_choice_alternatives *alt;
const struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++) {
if (alt->value == v)
return alt;
@ -776,7 +777,7 @@ static int choice_get(const m_option_t *opt, void *ta_parent,
struct mpv_node *dst, void *src)
{
int ival = 0;
struct m_opt_choice_alternatives *alt = get_choice(opt, src, &ival);
const struct m_opt_choice_alternatives *alt = get_choice(opt, src, &ival);
// If a choice string looks like a number, return it as number
if (alt) {
char *end = NULL;
@ -808,7 +809,7 @@ static int choice_get(const m_option_t *opt, void *ta_parent,
static char *print_choice(const m_option_t *opt, const void *val)
{
int ival = 0;
struct m_opt_choice_alternatives *alt = get_choice(opt, val, &ival);
const struct m_opt_choice_alternatives *alt = get_choice(opt, val, &ival);
return alt ? talloc_strdup(NULL, alt->name)
: talloc_asprintf(NULL, "%d", ival);
}
@ -828,7 +829,7 @@ const struct m_option_type m_option_type_choice = {
static int apply_flag(const struct m_option *opt, int *val, bstr flag)
{
struct m_opt_choice_alternatives *alt;
const struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++) {
if (bstr_equals0(flag, alt->name)) {
if (*val & alt->value)
@ -842,8 +843,8 @@ static int apply_flag(const struct m_option *opt, int *val, bstr flag)
static const char *find_next_flag(const struct m_option *opt, int *val)
{
struct m_opt_choice_alternatives *best = NULL;
struct m_opt_choice_alternatives *alt;
const struct m_opt_choice_alternatives *best = NULL;
const struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++) {
if (alt->value && (alt->value & (*val)) == alt->value) {
if (!best || av_popcount64(alt->value) > av_popcount64(best->value))
@ -870,7 +871,7 @@ static int parse_flags(struct mp_log *log, const struct m_option *opt,
mp_fatal(log, "Invalid flag for option %.*s: %.*s\n",
BSTR_P(name), BSTR_P(flag));
mp_info(log, "Valid flags are:\n");
struct m_opt_choice_alternatives *alt;
const struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++)
mp_info(log, " %s\n", alt->name);
mp_info(log, "Flags can usually be combined with '+'.\n");

View File

@ -3388,7 +3388,7 @@ static int mp_property_option_info(void *ctx, struct m_property *prop,
char **choices = NULL;
if (opt->type == &m_option_type_choice) {
struct m_opt_choice_alternatives *alt = opt->priv;
const struct m_opt_choice_alternatives *alt = opt->priv;
int num = 0;
for ( ; alt->name; alt++)
MP_TARRAY_APPEND(NULL, choices, num, alt->name);