From d3af793572b1a6624d208ac040fa8d9fad6b1bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net> Date: Mon, 27 May 2019 21:07:52 +0300 Subject: [PATCH] rc: use a table for commands with parameters --- modules/control/oldrc.c | 80 ++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c index eda913de72e6..2aca23e551df 100644 --- a/modules/control/oldrc.c +++ b/modules/control/oldrc.c @@ -1062,6 +1062,43 @@ static const struct { "snapshot", VideoConfig }, }; +static const struct +{ + const char *name; + void (*handler)(vlc_object_t *, const char *, vlc_value_t); +} string_cmds[] = +{ + { "intf", Intf }, + { "add", Playlist }, + { "repeat", Playlist }, + { "loop", Playlist }, + { "random", Playlist }, + { "enqueue", Playlist }, + { "goto", Playlist }, + { "status", Playlist }, + + /* DVD commands */ + { "seek", Input }, + { "title", Input }, + { "chapter", Input }, + + { "atrack", Input }, + { "vtrack", Input }, + { "strack", Input }, + + /* video commands */ + { "vratio", VideoConfig }, + { "vcrop", VideoConfig }, + { "vzoom", VideoConfig }, + + /* audio commands */ + { "volume", Volume }, + { "volup", VolumeMove }, + { "voldown", VolumeMove }, + { "adev", AudioDevice }, + { "achan", AudioChannel }, +}; + static void Process(intf_thread_t *intf, const char *cmd, const char *arg) { intf_thread_t *const p_intf = intf; @@ -1082,44 +1119,15 @@ static void Process(intf_thread_t *intf, const char *cmd, const char *arg) return; } -#define STRING(name, func) \ - if (strcmp(cmd, name) == 0) { \ - vlc_value_t n = { .psz_string = (char *)arg }; \ - func(VLC_OBJECT(intf), cmd, n); \ - } else - - STRING("intf", Intf) - - STRING("add", Playlist) - STRING("repeat", Playlist) - STRING("loop", Playlist) - STRING("random", Playlist) - STRING("enqueue", Playlist) - STRING("goto", Playlist) - STRING("status", Playlist) - - /* DVD commands */ - STRING("seek", Input) - STRING("title", Input) - STRING("chapter", Input) - - STRING("atrack", Input) - STRING("vtrack", Input) - STRING("strack", Input) - - /* video commands */ - STRING("vratio", VideoConfig) - STRING("vcrop", VideoConfig) - STRING("vzoom", VideoConfig) + for (size_t i = 0; i < ARRAY_SIZE(string_cmds); i++) + if (strcmp(cmd, string_cmds[i].name) == 0) + { + vlc_value_t n = { .psz_string = (char *)arg }; - /* audio commands */ - STRING("volume", Volume) - STRING("volup", VolumeMove) - STRING("voldown", VolumeMove) - STRING("adev", AudioDevice) - STRING("achan", AudioChannel) + string_cmds[i].handler(VLC_OBJECT(intf), cmd, n); + return; + } -#undef STRING /* misc menu commands */ if (strcmp(cmd, "stats") == 0) -- GitLab