version 1.30, 2016/10/14 22:14:22 |
version 1.31, 2016/10/16 19:04:05 |
|
|
* Bind a key to a command, this recurses through cmd_*. |
* Bind a key to a command, this recurses through cmd_*. |
*/ |
*/ |
|
|
static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *); |
static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmdq_item *); |
|
|
static enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, |
static enum cmd_retval cmd_bind_key_mode_table(struct cmd *, |
key_code); |
struct cmdq_item *, key_code); |
|
|
const struct cmd_entry cmd_bind_key_entry = { |
const struct cmd_entry cmd_bind_key_entry = { |
.name = "bind-key", |
.name = "bind-key", |
|
|
}; |
}; |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) |
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
char *cause; |
char *cause; |
|
|
|
|
if (args_has(args, 't')) { |
if (args_has(args, 't')) { |
if (args->argc != 2 && args->argc != 3) { |
if (args->argc != 2 && args->argc != 3) { |
cmdq_error(cmdq, "not enough arguments"); |
cmdq_error(item, "not enough arguments"); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
} else { |
} else { |
if (args->argc < 2) { |
if (args->argc < 2) { |
cmdq_error(cmdq, "not enough arguments"); |
cmdq_error(item, "not enough arguments"); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
} |
} |
|
|
key = key_string_lookup_string(args->argv[0]); |
key = key_string_lookup_string(args->argv[0]); |
if (key == KEYC_NONE || key == KEYC_UNKNOWN) { |
if (key == KEYC_NONE || key == KEYC_UNKNOWN) { |
cmdq_error(cmdq, "unknown key: %s", args->argv[0]); |
cmdq_error(item, "unknown key: %s", args->argv[0]); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
if (args_has(args, 't')) |
if (args_has(args, 't')) |
return (cmd_bind_key_mode_table(self, cmdq, key)); |
return (cmd_bind_key_mode_table(self, item, key)); |
|
|
if (args_has(args, 'T')) |
if (args_has(args, 'T')) |
tablename = args_get(args, 'T'); |
tablename = args_get(args, 'T'); |
|
|
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0, |
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0, |
&cause); |
&cause); |
if (cmdlist == NULL) { |
if (cmdlist == NULL) { |
cmdq_error(cmdq, "%s", cause); |
cmdq_error(item, "%s", cause); |
free(cause); |
free(cause); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
} |
} |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) |
cmd_bind_key_mode_table(struct cmd *self, struct cmdq_item *item, key_code key) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
const char *tablename; |
const char *tablename; |
|
|
|
|
tablename = args_get(args, 't'); |
tablename = args_get(args, 't'); |
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
cmdq_error(cmdq, "unknown key table: %s", tablename); |
cmdq_error(item, "unknown key table: %s", tablename); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]); |
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]); |
if (cmd == MODEKEY_NONE) { |
if (cmd == MODEKEY_NONE) { |
cmdq_error(cmdq, "unknown command: %s", args->argv[1]); |
cmdq_error(item, "unknown command: %s", args->argv[1]); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
if (args->argc != 2) { |
if (args->argc != 2) { |
cmdq_error(cmdq, "no argument allowed"); |
cmdq_error(item, "no argument allowed"); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|