mirror of https://github.com/mpv-player/mpv
input: more mp_msg conversion
It appears the last run missed all mp_tmsg(). Since the command parser also prints messages, it needs a new parameter to pass a log context. We go the easy way and just require the input_ctx to be passed, and use its mp_log.
This commit is contained in:
parent
9f149717a6
commit
0d90dd07ff
|
@ -483,6 +483,7 @@ struct key_name modifier_names[] = {
|
||||||
#define MP_MAX_FDS 10
|
#define MP_MAX_FDS 10
|
||||||
|
|
||||||
struct input_fd {
|
struct input_fd {
|
||||||
|
struct mp_log *log;
|
||||||
int fd;
|
int fd;
|
||||||
int (*read_key)(void *ctx, int fd);
|
int (*read_key)(void *ctx, int fd);
|
||||||
int (*read_cmd)(int fd, char *dest, int size);
|
int (*read_cmd)(int fd, char *dest, int size);
|
||||||
|
@ -735,12 +736,13 @@ static struct mp_cmd *queue_peek_tail(struct cmd_queue *queue)
|
||||||
static struct input_fd *mp_input_add_fd(struct input_ctx *ictx)
|
static struct input_fd *mp_input_add_fd(struct input_ctx *ictx)
|
||||||
{
|
{
|
||||||
if (ictx->num_fds == MP_MAX_FDS) {
|
if (ictx->num_fds == MP_MAX_FDS) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many file descriptors.\n");
|
MP_ERR(ictx, "Too many file descriptors.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct input_fd *fd = &ictx->fds[ictx->num_fds];
|
struct input_fd *fd = &ictx->fds[ictx->num_fds];
|
||||||
*fd = (struct input_fd){
|
*fd = (struct input_fd){
|
||||||
|
.log = ictx->log,
|
||||||
.fd = -1,
|
.fd = -1,
|
||||||
};
|
};
|
||||||
ictx->num_fds++;
|
ictx->num_fds++;
|
||||||
|
@ -887,7 +889,8 @@ error:
|
||||||
|
|
||||||
// If dest is non-NULL when calling this function, append the command to the
|
// If dest is non-NULL when calling this function, append the command to the
|
||||||
// list formed by dest->queue_next, otherwise just set *dest = new_cmd;
|
// list formed by dest->queue_next, otherwise just set *dest = new_cmd;
|
||||||
static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str,
|
||||||
|
const char *loc)
|
||||||
{
|
{
|
||||||
int pausing = 0;
|
int pausing = 0;
|
||||||
int on_osd = MP_ON_OSD_AUTO;
|
int on_osd = MP_ON_OSD_AUTO;
|
||||||
|
@ -903,9 +906,8 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
bool silent = bstr_eatstart0(&old, "!");
|
bool silent = bstr_eatstart0(&old, "!");
|
||||||
if (bstrcasecmp(bstr_splice(str, 0, old.len), old) == 0) {
|
if (bstrcasecmp(bstr_splice(str, 0, old.len), old) == 0) {
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Warning: command '%.*s' is "
|
MP_WARN(ictx, "Warning: command '%.*s' is deprecated, replaced "
|
||||||
"deprecated, replaced with '%s' at %s.\n",
|
"with '%s' at %s.\n", BSTR_P(old), entry->new, loc);
|
||||||
BSTR_P(old), entry->new, loc);
|
|
||||||
}
|
}
|
||||||
bstr s = bstr_cut(str, old.len);
|
bstr s = bstr_cut(str, old.len);
|
||||||
str = bstr0(talloc_asprintf(tmp, "%s%.*s", entry->new, BSTR_P(s)));
|
str = bstr0(talloc_asprintf(tmp, "%s%.*s", entry->new, BSTR_P(s)));
|
||||||
|
@ -950,8 +952,7 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mp_cmds[cmd_idx].name == NULL) {
|
if (mp_cmds[cmd_idx].name == NULL) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command '%.*s' not found.\n",
|
MP_ERR(ictx, "Command '%.*s' not found.\n", BSTR_P(str));
|
||||||
BSTR_P(str));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,13 +977,13 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
bstr arg = {0};
|
bstr arg = {0};
|
||||||
if (bstr_eatstart0(&str, "\"")) {
|
if (bstr_eatstart0(&str, "\"")) {
|
||||||
if (!read_escaped_string(tmp, &str, &arg)) {
|
if (!read_escaped_string(tmp, &str, &arg)) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s: argument %d "
|
MP_ERR(ictx, "Command %s: argument %d has broken string escapes.\n",
|
||||||
"has broken string escapes.\n", cmd->name, i + 1);
|
cmd->name, i + 1);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!bstr_eatstart0(&str, "\"")) {
|
if (!bstr_eatstart0(&str, "\"")) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s: argument %d is "
|
MP_ERR(ictx, "Command %s: argument %d is unterminated.\n",
|
||||||
"unterminated.\n", cmd->name, i + 1);
|
cmd->name, i + 1);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -995,9 +996,8 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
cmdarg->v = ((struct mp_cmd_arg) {{0}}).v;
|
cmdarg->v = ((struct mp_cmd_arg) {{0}}).v;
|
||||||
int r = m_option_parse(&cmdarg->type, bstr0(cmd->name), arg, &cmdarg->v);
|
int r = m_option_parse(&cmdarg->type, bstr0(cmd->name), arg, &cmdarg->v);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s: argument %d "
|
MP_ERR(ictx, "Command %s: argument %d can't be parsed: %s.\n",
|
||||||
"can't be parsed: %s.\n", cmd->name, i + 1,
|
cmd->name, i + 1, m_option_strerror(r));
|
||||||
m_option_strerror(r));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (cmdarg->type.type == &m_option_type_string)
|
if (cmdarg->type.type == &m_option_type_string)
|
||||||
|
@ -1011,8 +1011,8 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
|
|
||||||
bstr dummy;
|
bstr dummy;
|
||||||
if (read_token(str, &dummy, &dummy)) {
|
if (read_token(str, &dummy, &dummy)) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s has trailing unused "
|
MP_ERR(ictx, "Command %s has trailing unused arguments: '%.*s'.\n",
|
||||||
"arguments: '%.*s'.\n", cmd->name, BSTR_P(str));
|
cmd->name, BSTR_P(str));
|
||||||
// Better make it fatal to make it clear something is wrong.
|
// Better make it fatal to make it clear something is wrong.
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -1024,9 +1024,8 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
min_args++;
|
min_args++;
|
||||||
}
|
}
|
||||||
if (cmd->nargs < min_args) {
|
if (cmd->nargs < min_args) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s requires at least %d "
|
MP_ERR(ictx, "Command %s requires at least %d arguments, we found "
|
||||||
"arguments, we found only %d so far.\n", cmd->name, min_args,
|
"only %d so far.\n", cmd->name, min_args, cmd->nargs);
|
||||||
cmd->nargs);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1039,7 +1038,7 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
|
|
||||||
next = bstr_strip(next);
|
next = bstr_strip(next);
|
||||||
if (next.len) {
|
if (next.len) {
|
||||||
if (parse_cmd(dest, next, loc) < 0) {
|
if (parse_cmd(ictx, dest, next, loc) < 0) {
|
||||||
*dest = NULL;
|
*dest = NULL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -1049,16 +1048,16 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command was defined at %s.\n", loc);
|
MP_ERR(ictx, "Command was defined at %s.\n", loc);
|
||||||
talloc_free(cmd);
|
talloc_free(cmd);
|
||||||
talloc_free(tmp);
|
talloc_free(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_cmd_t *mp_input_parse_cmd(bstr str, const char *loc)
|
mp_cmd_t *mp_input_parse_cmd(struct input_ctx *ictx, bstr str, const char *loc)
|
||||||
{
|
{
|
||||||
struct mp_cmd *cmd = NULL;
|
struct mp_cmd *cmd = NULL;
|
||||||
if (parse_cmd(&cmd, str, loc) < 0) {
|
if (parse_cmd(ictx, &cmd, str, loc) < 0) {
|
||||||
assert(!cmd);
|
assert(!cmd);
|
||||||
}
|
}
|
||||||
// Other input.c code uses queue_next for its own purposes, so explicitly
|
// Other input.c code uses queue_next for its own purposes, so explicitly
|
||||||
|
@ -1103,9 +1102,8 @@ static int read_cmd(struct input_fd *mp_fd, char **ret)
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case MP_INPUT_ERROR:
|
case MP_INPUT_ERROR:
|
||||||
case MP_INPUT_DEAD:
|
case MP_INPUT_DEAD:
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Error while reading "
|
MP_ERR(mp_fd, "Error while reading command file descriptor %d: %s\n",
|
||||||
"command file descriptor %d: %s\n",
|
mp_fd->fd, strerror(errno));
|
||||||
mp_fd->fd, strerror(errno));
|
|
||||||
case MP_INPUT_NOTHING:
|
case MP_INPUT_NOTHING:
|
||||||
return r;
|
return r;
|
||||||
case MP_INPUT_RETRY:
|
case MP_INPUT_RETRY:
|
||||||
|
@ -1134,9 +1132,8 @@ static int read_cmd(struct input_fd *mp_fd, char **ret)
|
||||||
if (!end) {
|
if (!end) {
|
||||||
// If buffer is full we must drop all until the next \n
|
// If buffer is full we must drop all until the next \n
|
||||||
if (mp_fd->size - mp_fd->pos <= 1) {
|
if (mp_fd->size - mp_fd->pos <= 1) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command buffer of file "
|
MP_ERR(mp_fd, "Command buffer of file descriptor %d is full: "
|
||||||
"descriptor %d is full: dropping content.\n",
|
"dropping content.\n", mp_fd->fd);
|
||||||
mp_fd->fd);
|
|
||||||
mp_fd->pos = 0;
|
mp_fd->pos = 0;
|
||||||
mp_fd->drop = 1;
|
mp_fd->drop = 1;
|
||||||
}
|
}
|
||||||
|
@ -1193,10 +1190,12 @@ static int read_wakeup(void *ctx, int fd)
|
||||||
|
|
||||||
static bool bind_matches_key(struct cmd_bind *bind, int n, const int *keys);
|
static bool bind_matches_key(struct cmd_bind *bind, int n, const int *keys);
|
||||||
|
|
||||||
static void append_bind_info(char **pmsg, struct cmd_bind *bind)
|
static void append_bind_info(struct input_ctx *ictx, char **pmsg,
|
||||||
|
struct cmd_bind *bind)
|
||||||
{
|
{
|
||||||
char *msg = *pmsg;
|
char *msg = *pmsg;
|
||||||
struct mp_cmd *cmd = mp_input_parse_cmd(bstr0(bind->cmd), bind->location);
|
struct mp_cmd *cmd = mp_input_parse_cmd(ictx, bstr0(bind->cmd),
|
||||||
|
bind->location);
|
||||||
bstr stripped = cmd ? cmd->original : bstr0(bind->cmd);
|
bstr stripped = cmd ? cmd->original : bstr0(bind->cmd);
|
||||||
msg = talloc_asprintf_append(msg, " '%.*s'", BSTR_P(stripped));
|
msg = talloc_asprintf_append(msg, " '%.*s'", BSTR_P(stripped));
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
|
@ -1226,7 +1225,7 @@ static mp_cmd_t *handle_test(struct input_ctx *ictx, int n, int *keys)
|
||||||
if (bind_matches_key(&bs->binds[i], n, keys)) {
|
if (bind_matches_key(&bs->binds[i], n, keys)) {
|
||||||
count++;
|
count++;
|
||||||
msg = talloc_asprintf_append(msg, "%d. ", count);
|
msg = talloc_asprintf_append(msg, "%d. ", count);
|
||||||
append_bind_info(&msg, &bs->binds[i]);
|
append_bind_info(ictx, &msg, &bs->binds[i]);
|
||||||
msg = talloc_asprintf_append(msg, "\n");
|
msg = talloc_asprintf_append(msg, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1236,7 @@ static mp_cmd_t *handle_test(struct input_ctx *ictx, int n, int *keys)
|
||||||
|
|
||||||
MP_VERBOSE(ictx, "%s\n", msg);
|
MP_VERBOSE(ictx, "%s\n", msg);
|
||||||
|
|
||||||
mp_cmd_t *res = mp_input_parse_cmd(bstr0("show_text \"\""), "");
|
mp_cmd_t *res = mp_input_parse_cmd(ictx, bstr0("show_text \"\""), "");
|
||||||
res->args[0].v.s = talloc_steal(res, msg);
|
res->args[0].v.s = talloc_steal(res, msg);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1377,11 +1376,11 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
|
||||||
keys[0] == MP_KEY_MOUSE_LEAVE))
|
keys[0] == MP_KEY_MOUSE_LEAVE))
|
||||||
msgl = MSGL_DBG2;
|
msgl = MSGL_DBG2;
|
||||||
char *key_buf = get_key_combo_name(keys, n);
|
char *key_buf = get_key_combo_name(keys, n);
|
||||||
mp_tmsg(MSGT_INPUT, msgl, "No bind found for key '%s'.\n", key_buf);
|
MP_MSG(ictx, msgl, "No bind found for key '%s'.\n", key_buf);
|
||||||
talloc_free(key_buf);
|
talloc_free(key_buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mp_cmd_t *ret = mp_input_parse_cmd(bstr0(cmd->cmd), cmd->location);
|
mp_cmd_t *ret = mp_input_parse_cmd(ictx, bstr0(cmd->cmd), cmd->location);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret->input_section = cmd->owner->section;
|
ret->input_section = cmd->owner->section;
|
||||||
if (mp_msg_test_log(ictx->log, MSGL_DBG2)) {
|
if (mp_msg_test_log(ictx->log, MSGL_DBG2)) {
|
||||||
|
@ -1392,8 +1391,8 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *key_buf = get_key_combo_name(keys, n);
|
char *key_buf = get_key_combo_name(keys, n);
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR,
|
MP_ERR(ictx, "Invalid command for bound key '%s': '%s'\n",
|
||||||
"Invalid command for bound key '%s': '%s'\n", key_buf, cmd->cmd);
|
key_buf, cmd->cmd);
|
||||||
talloc_free(key_buf);
|
talloc_free(key_buf);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1496,8 +1495,7 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(code & MP_KEY_STATE_UP) && ictx->num_key_down >= MP_MAX_KEY_DOWN) {
|
if (!(code & MP_KEY_STATE_UP) && ictx->num_key_down >= MP_MAX_KEY_DOWN) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key down events "
|
MP_ERR(ictx, "Too many key down events at the same time\n");
|
||||||
"at the same time\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1538,7 +1536,7 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale)
|
||||||
// Press of key with no separate down/up events
|
// Press of key with no separate down/up events
|
||||||
if (key_was_down) {
|
if (key_was_down) {
|
||||||
// Mixing press events and up/down with the same key is not allowed
|
// Mixing press events and up/down with the same key is not allowed
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Mixing key presses and up/down.\n");
|
MP_WARN(ictx, "Mixing key presses and up/down.\n");
|
||||||
}
|
}
|
||||||
update_mouse_section(ictx);
|
update_mouse_section(ictx);
|
||||||
// Add temporarily (include ongoing down/up events)
|
// Add temporarily (include ongoing down/up events)
|
||||||
|
@ -1645,7 +1643,7 @@ void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y)
|
||||||
struct mp_cmd *cmd =
|
struct mp_cmd *cmd =
|
||||||
get_cmd_from_keys(ictx, NULL, 1, (int[]){MP_KEY_MOUSE_MOVE});
|
get_cmd_from_keys(ictx, NULL, 1, (int[]){MP_KEY_MOUSE_MOVE});
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
cmd = mp_input_parse_cmd(bstr0("ignore"), "<internal>");
|
cmd = mp_input_parse_cmd(ictx, bstr0("ignore"), "<internal>");
|
||||||
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
cmd->mouse_move = true;
|
cmd->mouse_move = true;
|
||||||
|
@ -1673,7 +1671,7 @@ static void read_cmd_fd(struct input_ctx *ictx, struct input_fd *cmd_fd)
|
||||||
char *text;
|
char *text;
|
||||||
while ((r = read_cmd(cmd_fd, &text)) >= 0) {
|
while ((r = read_cmd(cmd_fd, &text)) >= 0) {
|
||||||
ictx->got_new_events = true;
|
ictx->got_new_events = true;
|
||||||
struct mp_cmd *cmd = mp_input_parse_cmd(bstr0(text), "<pipe>");
|
struct mp_cmd *cmd = mp_input_parse_cmd(ictx, bstr0(text), "<pipe>");
|
||||||
talloc_free(text);
|
talloc_free(text);
|
||||||
if (cmd)
|
if (cmd)
|
||||||
queue_add_tail(&ictx->cmd_queue, cmd);
|
queue_add_tail(&ictx->cmd_queue, cmd);
|
||||||
|
@ -1681,8 +1679,7 @@ static void read_cmd_fd(struct input_ctx *ictx, struct input_fd *cmd_fd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (r == MP_INPUT_ERROR)
|
if (r == MP_INPUT_ERROR)
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Error on command file descriptor %d\n",
|
MP_ERR(ictx, "Error on command file descriptor %d\n", cmd_fd->fd);
|
||||||
cmd_fd->fd);
|
|
||||||
else if (r == MP_INPUT_DEAD)
|
else if (r == MP_INPUT_DEAD)
|
||||||
cmd_fd->dead = true;
|
cmd_fd->dead = true;
|
||||||
}
|
}
|
||||||
|
@ -1696,11 +1693,9 @@ static void read_key_fd(struct input_ctx *ictx, struct input_fd *key_fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code == MP_INPUT_ERROR)
|
if (code == MP_INPUT_ERROR)
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR,
|
MP_ERR(ictx, "Error on key input file descriptor %d\n", key_fd->fd);
|
||||||
"Error on key input file descriptor %d\n", key_fd->fd);
|
|
||||||
else if (code == MP_INPUT_DEAD) {
|
else if (code == MP_INPUT_DEAD) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR,
|
MP_ERR(ictx, "Dead key input on file descriptor %d\n", key_fd->fd);
|
||||||
"Dead key input on file descriptor %d\n", key_fd->fd);
|
|
||||||
key_fd->dead = true;
|
key_fd->dead = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1745,8 +1740,7 @@ static void input_wait_read(struct input_ctx *ictx, int time)
|
||||||
input_unlock(ictx);
|
input_unlock(ictx);
|
||||||
if (select(max_fd + 1, &fds, NULL, NULL, time_val) < 0) {
|
if (select(max_fd + 1, &fds, NULL, NULL, time_val) < 0) {
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Select error: %s\n",
|
MP_ERR(ictx, "Select error: %s\n", strerror(errno));
|
||||||
strerror(errno));
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
}
|
}
|
||||||
input_lock(ictx);
|
input_lock(ictx);
|
||||||
|
@ -1859,7 +1853,7 @@ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only)
|
||||||
{
|
{
|
||||||
input_lock(ictx);
|
input_lock(ictx);
|
||||||
if (async_quit_request) {
|
if (async_quit_request) {
|
||||||
struct mp_cmd *cmd = mp_input_parse_cmd(bstr0("quit 1"), "");
|
struct mp_cmd *cmd = mp_input_parse_cmd(ictx, bstr0("quit 1"), "");
|
||||||
queue_add_head(&ictx->cmd_queue, cmd);
|
queue_add_head(&ictx->cmd_queue, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2056,9 +2050,8 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
|
||||||
struct bstr keyname = bstr_split(line, WHITESPACE, &command);
|
struct bstr keyname = bstr_split(line, WHITESPACE, &command);
|
||||||
command = bstr_strip(command);
|
command = bstr_strip(command);
|
||||||
if (command.len == 0) {
|
if (command.len == 0) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR,
|
MP_ERR(ictx, "Unfinished key binding: %.*s at %s\n", BSTR_P(line),
|
||||||
"Unfinished key binding: %.*s at %s\n", BSTR_P(line),
|
cur_loc);
|
||||||
cur_loc);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char *name = bstrdup0(NULL, keyname);
|
char *name = bstrdup0(NULL, keyname);
|
||||||
|
@ -2066,8 +2059,7 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
|
||||||
int num_keys = 0;
|
int num_keys = 0;
|
||||||
if (!get_input_from_name(name, &num_keys, keys)) {
|
if (!get_input_from_name(name, &num_keys, keys)) {
|
||||||
talloc_free(name);
|
talloc_free(name);
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR,
|
MP_ERR(ictx, "Unknown key '%.*s' at %s\n", BSTR_P(keyname), cur_loc);
|
||||||
"Unknown key '%.*s' at %s\n", BSTR_P(keyname), cur_loc);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
talloc_free(name);
|
talloc_free(name);
|
||||||
|
@ -2087,7 +2079,7 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
|
||||||
n_binds++;
|
n_binds++;
|
||||||
|
|
||||||
// Print warnings if invalid commands are encountered.
|
// Print warnings if invalid commands are encountered.
|
||||||
talloc_free(mp_input_parse_cmd(command, cur_loc));
|
talloc_free(mp_input_parse_cmd(ictx, command, cur_loc));
|
||||||
}
|
}
|
||||||
|
|
||||||
talloc_free(cur_loc);
|
talloc_free(cur_loc);
|
||||||
|
@ -2305,7 +2297,7 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
||||||
if (input_conf->use_joystick) {
|
if (input_conf->use_joystick) {
|
||||||
int fd = mp_input_joystick_init(input_conf->js_dev);
|
int fd = mp_input_joystick_init(input_conf->js_dev);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't init input joystick\n");
|
MP_ERR(ictx, "Can't init input joystick\n");
|
||||||
else
|
else
|
||||||
mp_input_add_key_fd(ictx, fd, 1, mp_input_joystick_read,
|
mp_input_add_key_fd(ictx, fd, 1, mp_input_joystick_read,
|
||||||
close, NULL);
|
close, NULL);
|
||||||
|
@ -2356,8 +2348,8 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
||||||
if (in_file_fd >= 0)
|
if (in_file_fd >= 0)
|
||||||
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL, close);
|
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL, close);
|
||||||
else
|
else
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't open %s: %s\n",
|
MP_ERR(ictx, "Can't open %s: %s\n", input_conf->in_file,
|
||||||
input_conf->in_file, strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ictx;
|
return ictx;
|
||||||
|
@ -2439,8 +2431,8 @@ void mp_input_wakeup(struct input_ctx *ictx)
|
||||||
static bool test_abort(struct input_ctx *ictx)
|
static bool test_abort(struct input_ctx *ictx)
|
||||||
{
|
{
|
||||||
if (async_quit_request || queue_has_abort_cmds(&ictx->cmd_queue)) {
|
if (async_quit_request || queue_has_abort_cmds(&ictx->cmd_queue)) {
|
||||||
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Received command to move to "
|
MP_WARN(ictx, "Received command to move to another file. "
|
||||||
"another file. Aborting current processing.\n");
|
"Aborting current processing.\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -216,7 +216,8 @@ struct mp_cmd *mp_input_get_cmd(struct input_ctx *ictx, int time,
|
||||||
|
|
||||||
// Parse text and return corresponding struct mp_cmd.
|
// Parse text and return corresponding struct mp_cmd.
|
||||||
// The location parameter is for error messages.
|
// The location parameter is for error messages.
|
||||||
struct mp_cmd *mp_input_parse_cmd(bstr str, const char *location);
|
struct mp_cmd *mp_input_parse_cmd(struct input_ctx *ictx, bstr str,
|
||||||
|
const char *location);
|
||||||
|
|
||||||
// After getting a command from mp_input_get_cmd you need to free it using this
|
// After getting a command from mp_input_get_cmd you need to free it using this
|
||||||
// function
|
// function
|
||||||
|
|
|
@ -370,7 +370,7 @@ static int script_send_command(lua_State *L)
|
||||||
struct MPContext *mpctx = get_mpctx(L);
|
struct MPContext *mpctx = get_mpctx(L);
|
||||||
const char *s = luaL_checkstring(L, 1);
|
const char *s = luaL_checkstring(L, 1);
|
||||||
|
|
||||||
mp_cmd_t *cmd = mp_input_parse_cmd(bstr0((char*)s), "<lua>");
|
mp_cmd_t *cmd = mp_input_parse_cmd(mpctx->input, bstr0((char*)s), "<lua>");
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
luaL_error(L, "error parsing command");
|
luaL_error(L, "error parsing command");
|
||||||
mp_input_queue_cmd(mpctx->input, cmd);
|
mp_input_queue_cmd(mpctx->input, cmd);
|
||||||
|
|
Loading…
Reference in New Issue