version 1.27, 2016/10/10 21:51:39 |
version 1.28, 2016/10/11 07:23:34 |
|
|
.name = "bind-key", |
.name = "bind-key", |
.alias = "bind", |
.alias = "bind", |
|
|
.args = { "cnrR:t:T:", 1, -1 }, |
.args = { "cnrt:T:", 1, -1 }, |
.usage = "[-cnr] [-t mode-table] [-R repeat-count] [-T key-table] key " |
.usage = "[-cnr] [-t mode-table] [-T key-table] key " |
"command [arguments]", |
"command [arguments]", |
|
|
.flags = 0, |
.flags = 0, |
|
|
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) |
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
const char *tablename, *arg; |
const char *tablename; |
const struct mode_key_table *mtab; |
const struct mode_key_table *mtab; |
struct mode_key_binding *mbind, mtmp; |
struct mode_key_binding *mbind, mtmp; |
enum mode_key_cmd cmd; |
enum mode_key_cmd cmd; |
char *cause; |
|
u_int repeat; |
|
|
|
tablename = args_get(args, 't'); |
tablename = args_get(args, 't'); |
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
|
|
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
switch (cmd) { |
if (args->argc != 2) { |
case MODEKEYCOPY_APPENDSELECTION: |
cmdq_error(cmdq, "no argument allowed"); |
case MODEKEYCOPY_COPYSELECTION: |
return (CMD_RETURN_ERROR); |
case MODEKEYCOPY_STARTNAMEDBUFFER: |
|
if (args->argc == 2) |
|
arg = NULL; |
|
else { |
|
arg = args->argv[2]; |
|
if (strcmp(arg, "-x") != 0) { |
|
cmdq_error(cmdq, "unknown argument"); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
} |
|
break; |
|
case MODEKEYCOPY_COPYPIPE: |
|
if (args->argc != 3) { |
|
cmdq_error(cmdq, "no argument given"); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
arg = args->argv[2]; |
|
break; |
|
default: |
|
if (args->argc != 2) { |
|
cmdq_error(cmdq, "no argument allowed"); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
arg = NULL; |
|
break; |
|
} |
} |
|
|
repeat = 1; |
|
if (args_has(args, 'R')) { |
|
repeat = args_strtonum(args, 'R', 1, SHRT_MAX, &cause); |
|
if (cause != NULL) { |
|
cmdq_error(cmdq, "repeat count %s", cause); |
|
free(cause); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
} |
|
|
|
mtmp.key = key; |
mtmp.key = key; |
mtmp.mode = !!args_has(args, 'c'); |
mtmp.mode = !!args_has(args, 'c'); |
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) { |
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) { |
|
|
mbind->mode = mtmp.mode; |
mbind->mode = mtmp.mode; |
RB_INSERT(mode_key_tree, mtab->tree, mbind); |
RB_INSERT(mode_key_tree, mtab->tree, mbind); |
} |
} |
mbind->repeat = repeat; |
|
mbind->cmd = cmd; |
mbind->cmd = cmd; |
mbind->arg = arg != NULL ? xstrdup(arg) : NULL; |
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
} |
} |