options: change option macros and all option declarations

Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with

   {"name", ...

followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.

I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.

Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.

Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.

In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
This commit is contained in:
wm4
2020-03-14 21:28:01 +01:00
parent cdd6eb0994
commit 26f4f18c06
78 changed files with 1608 additions and 1601 deletions

View File

@@ -152,7 +152,4 @@ struct mp_cmd *mp_cmd_clone(struct mp_cmd *cmd);
extern const struct m_option_type m_option_type_cycle_dir;
#define OPT_CYCLEDIR(...) \
OPT_GENERAL(double, __VA_ARGS__, .type = &m_option_type_cycle_dir)
#endif

View File

@@ -183,26 +183,27 @@ struct input_opts {
const struct m_sub_options input_config = {
.opts = (const m_option_t[]) {
OPT_STRING("input-conf", config_file, M_OPT_FILE),
OPT_INT("input-ar-delay", ar_delay, 0),
OPT_INT("input-ar-rate", ar_rate, 0),
OPT_PRINT("input-keylist", mp_print_key_list),
OPT_PRINT("input-cmdlist", mp_print_cmd_list),
OPT_FLAG("input-default-bindings", default_bindings, 0),
OPT_FLAG("input-test", test, 0),
OPT_INTRANGE("input-doubleclick-time", doubleclick_time, 0, 0, 1000),
OPT_FLAG("input-right-alt-gr", use_alt_gr, 0),
OPT_INTRANGE("input-key-fifo-size", key_fifo_size, 0, 2, 65000),
OPT_FLAG("input-cursor", enable_mouse_movements, 0),
OPT_FLAG("input-vo-keyboard", vo_key_input, 0),
OPT_FLAG("input-media-keys", use_media_keys, 0),
{"input-conf", OPT_STRING(config_file), .flags = M_OPT_FILE},
{"input-ar-delay", OPT_INT(ar_delay)},
{"input-ar-rate", OPT_INT(ar_rate)},
{"input-keylist", OPT_PRINT(mp_print_key_list)},
{"input-cmdlist", OPT_PRINT(mp_print_cmd_list)},
{"input-default-bindings", OPT_FLAG(default_bindings)},
{"input-test", OPT_FLAG(test)},
{"input-doubleclick-time", OPT_INT(doubleclick_time),
M_RANGE(0, 1000)},
{"input-right-alt-gr", OPT_FLAG(use_alt_gr)},
{"input-key-fifo-size", OPT_INT(key_fifo_size), M_RANGE(2, 65000)},
{"input-cursor", OPT_FLAG(enable_mouse_movements)},
{"input-vo-keyboard", OPT_FLAG(vo_key_input)},
{"input-media-keys", OPT_FLAG(use_media_keys)},
#if HAVE_SDL2_GAMEPAD
OPT_FLAG("input-gamepad", use_gamepad, 0),
{"input-gamepad", OPT_FLAG(use_gamepad)},
#endif
OPT_FLAG("window-dragging", allow_win_drag, 0),
OPT_REPLACED("input-x11-keyboard", "input-vo-keyboard"),
{"window-dragging", OPT_FLAG(allow_win_drag)},
{"input-x11-keyboard", OPT_REPLACED("input-vo-keyboard")},
#if HAVE_COCOA
OPT_REMOVED("input-appleremote", "replaced by MediaPlayer support"),
{"input-appleremote", OPT_REMOVED("replaced by MediaPlayer support")},
#endif
{0}
},