From 9fa0e6bf6af287814d1d2e75634544df8eafafef Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 May 2018 03:19:50 +0200 Subject: input: merge cmd_list.c with cmd.c It doesn't really make sense to keep a separate cmd_list.c file, which does _not_ contain a command list, but only a few minor helper functions. --- input/cmd.c | 56 +++++++++++++++++++++++++++++++++++++- input/cmd.h | 32 ++++++++++++++++++++++ input/cmd_list.c | 83 -------------------------------------------------------- input/cmd_list.h | 59 ---------------------------------------- input/input.h | 1 - player/client.c | 2 +- wscript_build.py | 1 - 7 files changed, 88 insertions(+), 146 deletions(-) delete mode 100644 input/cmd_list.c delete mode 100644 input/cmd_list.h diff --git a/input/cmd.c b/input/cmd.c index 95f9f9ac50..0bab03d1b8 100644 --- a/input/cmd.c +++ b/input/cmd.c @@ -23,7 +23,6 @@ #include "options/m_option.h" #include "cmd.h" -#include "cmd_list.h" #include "input.h" #include "libmpv/client.h" @@ -444,6 +443,61 @@ void mp_cmd_dump(struct mp_log *log, int msgl, char *header, struct mp_cmd *cmd) mp_msg(log, msgl, "]\n"); } +// 0: no, 1: maybe, 2: sure +static int is_abort_cmd(struct mp_cmd *cmd) +{ + if (cmd->def->is_abort) + return 2; + if (cmd->def->is_soft_abort) + return 1; + if (cmd->def == &mp_cmd_list) { + int r = 0; + for (struct mp_cmd *sub = cmd->args[0].v.p; sub; sub = sub->queue_next) { + int x = is_abort_cmd(sub); + r = MPMAX(r, x); + } + return r; + } + return 0; +} + +bool mp_input_is_maybe_abort_cmd(struct mp_cmd *cmd) +{ + return is_abort_cmd(cmd) >= 1; +} + +bool mp_input_is_abort_cmd(struct mp_cmd *cmd) +{ + return is_abort_cmd(cmd) >= 2; +} + +bool mp_input_is_repeatable_cmd(struct mp_cmd *cmd) +{ + return (cmd->def->allow_auto_repeat) || cmd->def == &mp_cmd_list || + (cmd->flags & MP_ALLOW_REPEAT); +} + +bool mp_input_is_scalable_cmd(struct mp_cmd *cmd) +{ + return cmd->def->scalable; +} + +void mp_print_cmd_list(struct mp_log *out) +{ + for (int i = 0; mp_cmds[i].name; i++) { + const struct mp_cmd_def *def = &mp_cmds[i]; + mp_info(out, "%-20.20s", def->name); + for (int j = 0; j < MP_CMD_DEF_MAX_ARGS && def->args[j].type; j++) { + const char *type = def->args[j].type->name; + if (def->args[j].defval) + mp_info(out, " [%s]", type); + else + mp_info(out, " %s", type); + } + mp_info(out, "\n"); + } +} + static int parse_cycle_dir(struct mp_log *log, const struct m_option *opt, struct bstr name, struct bstr param, void *dst) { diff --git a/input/cmd.h b/input/cmd.h index 13a055ff13..87fdf5fadc 100644 --- a/input/cmd.h +++ b/input/cmd.h @@ -18,14 +18,46 @@ #ifndef MP_PARSE_COMMAND_H #define MP_PARSE_COMMAND_H +#include + #include "misc/bstr.h" +#include "options/m_option.h" + +#define MP_CMD_DEF_MAX_ARGS 9 +#define MP_CMD_OPT_ARG 0x1000 struct mp_log; struct mp_cmd; struct mpv_node; +struct mp_cmd_def { + const char *name; // user-visible name (as used in input.conf) + void (*handler)(void *ctx); + const struct m_option args[MP_CMD_DEF_MAX_ARGS]; + const void *priv; // for free use by handler() + bool allow_auto_repeat; // react to repeated key events + bool on_updown; // always emit it on both up and down key events + bool vararg; // last argument can be given 0 to multiple times + bool scalable; + bool is_abort; + bool is_soft_abort; + bool is_ignore; +}; + +extern const struct mp_cmd_def mp_cmds[]; extern const struct mp_cmd_def mp_cmd_list; +// Executing this command will maybe abort playback (play something else, or quit). +bool mp_input_is_maybe_abort_cmd(struct mp_cmd *cmd); +// This command will definitely abort playback. +bool mp_input_is_abort_cmd(struct mp_cmd *cmd); + +bool mp_input_is_repeatable_cmd(struct mp_cmd *cmd); + +bool mp_input_is_scalable_cmd(struct mp_cmd *cmd); + +void mp_print_cmd_list(struct mp_log *out); + // Parse text and return corresponding struct mp_cmd. // The location parameter is for error messages. struct mp_cmd *mp_input_parse_cmd_(struct mp_log *log, bstr str, const char *loc); diff --git a/input/cmd_list.c b/input/cmd_list.c deleted file mode 100644 index d57b0796e4..0000000000 --- a/input/cmd_list.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#include - -#include "config.h" - -#include "common/common.h" -#include "common/msg.h" -#include "options/m_option.h" - -#include "input.h" -#include "cmd_list.h" -#include "cmd.h" - -// 0: no, 1: maybe, 2: sure -static int is_abort_cmd(struct mp_cmd *cmd) -{ - if (cmd->def->is_abort) - return 2; - if (cmd->def->is_soft_abort) - return 1; - if (cmd->def == &mp_cmd_list) { - int r = 0; - for (struct mp_cmd *sub = cmd->args[0].v.p; sub; sub = sub->queue_next) { - int x = is_abort_cmd(sub); - r = MPMAX(r, x); - } - return r; - } - return 0; -} - -bool mp_input_is_maybe_abort_cmd(struct mp_cmd *cmd) -{ - return is_abort_cmd(cmd) >= 1; -} - -bool mp_input_is_abort_cmd(struct mp_cmd *cmd) -{ - return is_abort_cmd(cmd) >= 2; -} - -bool mp_input_is_repeatable_cmd(struct mp_cmd *cmd) -{ - return (cmd->def->allow_auto_repeat) || cmd->def == &mp_cmd_list || - (cmd->flags & MP_ALLOW_REPEAT); -} - -bool mp_input_is_scalable_cmd(struct mp_cmd *cmd) -{ - return cmd->def->scalable; -} - -void mp_print_cmd_list(struct mp_log *out) -{ - for (int i = 0; mp_cmds[i].name; i++) { - const struct mp_cmd_def *def = &mp_cmds[i]; - mp_info(out, "%-20.20s", def->name); - for (int j = 0; j < MP_CMD_DEF_MAX_ARGS && def->args[j].type; j++) { - const char *type = def->args[j].type->name; - if (def->args[j].defval) - mp_info(out, " [%s]", type); - else - mp_info(out, " %s", type); - } - mp_info(out, "\n"); - } -} diff --git a/input/cmd_list.h b/input/cmd_list.h deleted file mode 100644 index 5f44602907..0000000000 --- a/input/cmd_list.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#ifndef MP_COMMAND_LIST_H -#define MP_COMMAND_LIST_H - -#include -#include "options/m_option.h" - -#define MP_CMD_DEF_MAX_ARGS 9 - -#define MP_CMD_OPT_ARG 0x1000 - -struct mp_cmd_ctx; - -struct mp_cmd_def { - const char *name; // user-visible name (as used in input.conf) - void (*handler)(void *ctx); - const struct m_option args[MP_CMD_DEF_MAX_ARGS]; - const void *priv; // for free use by handler() - bool allow_auto_repeat; // react to repeated key events - bool on_updown; // always emit it on both up and down key events - bool vararg; // last argument can be given 0 to multiple times - bool scalable; - bool is_abort; - bool is_soft_abort; - bool is_ignore; -}; - -extern const struct mp_cmd_def mp_cmds[]; - -// Executing this command will maybe abort playback (play something else, or quit). -struct mp_cmd; -bool mp_input_is_maybe_abort_cmd(struct mp_cmd *cmd); -// This command will definitely abort playback. -bool mp_input_is_abort_cmd(struct mp_cmd *cmd); - -bool mp_input_is_repeatable_cmd(struct mp_cmd *cmd); - -bool mp_input_is_scalable_cmd(struct mp_cmd *cmd); - -struct mp_log; -void mp_print_cmd_list(struct mp_log *out); - -#endif diff --git a/input/input.h b/input/input.h index 6af170319b..d976fcd780 100644 --- a/input/input.h +++ b/input/input.h @@ -21,7 +21,6 @@ #include #include "misc/bstr.h" -#include "cmd_list.h" #include "cmd.h" // For mp_input_put_key(): release all keys that are down. diff --git a/player/client.c b/player/client.c index 0e50d735fc..2c21dd727c 100644 --- a/player/client.c +++ b/player/client.c @@ -28,7 +28,7 @@ #include "common/msg_control.h" #include "common/global.h" #include "input/input.h" -#include "input/cmd_list.h" +#include "input/cmd.h" #include "misc/ctype.h" #include "misc/dispatch.h" #include "misc/rendezvous.h" diff --git a/wscript_build.py b/wscript_build.py index 9c10f296ec..4b9b60e569 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -306,7 +306,6 @@ def build(ctx): ( "filters/user_filters.c" ), ## Input - ( "input/cmd_list.c" ), ( "input/cmd.c" ), ( "input/event.c" ), ( "input/input.c" ), -- cgit v1.2.3