mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
e5f884e68c
commit
9fa0e6bf6a
56
input/cmd.c
56
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)
|
||||
{
|
||||
|
|
32
input/cmd.h
32
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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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" ),
|
||||
|
|
Loading…
Reference in New Issue