summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-01 03:19:50 +0200
committerJan Ekström <jeebjp@gmail.com>2018-05-03 01:20:01 +0300
commit9fa0e6bf6af287814d1d2e75634544df8eafafef (patch)
treecdc3882dbbce61c2debf1f836eb18d3ee537f870
parente5f884e68cc58913a4d8f6409c474f917e2fd975 (diff)
downloadmpv-9fa0e6bf6af287814d1d2e75634544df8eafafef.tar.bz2
mpv-9fa0e6bf6af287814d1d2e75634544df8eafafef.tar.xz
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.
-rw-r--r--input/cmd.c56
-rw-r--r--input/cmd.h32
-rw-r--r--input/cmd_list.c83
-rw-r--r--input/cmd_list.h59
-rw-r--r--input/input.h1
-rw-r--r--player/client.c2
-rw-r--r--wscript_build.py1
7 files changed, 88 insertions, 146 deletions
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 <stdbool.h>
+
#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 <http://www.gnu.org/licenses/>.
- */
-
-#include <limits.h>
-
-#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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MP_COMMAND_LIST_H
-#define MP_COMMAND_LIST_H
-
-#include <stdbool.h>
-#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 <stdbool.h>
#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" ),