Esempio n. 1
0
int
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		ctx->error(ctx, "unknown key table: %s", tablename);
		return (-1);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
	if (cmd == MODEKEY_NONE) {
		ctx->error(ctx, "unknown command: %s", args->argv[1]);
		return (-1);
	}

	mtmp.key = key;
	mtmp.mode = !!args_has(args, 'c');
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
		mbind->cmd = cmd;
		return (0);
	}
	mbind = xmalloc(sizeof *mbind);
	mbind->key = mtmp.key;
	mbind->mode = mtmp.mode;
	mbind->cmd = cmd;
	RB_INSERT(mode_key_tree, mtab->tree, mbind);
	return (0);
}
Esempio n. 2
0
int
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_bind_key_data	*data = self->data;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;

	if ((mtab = mode_key_findtable(data->tablename)) == NULL) {
		ctx->error(ctx, "unknown key table: %s", data->tablename);
		return (-1);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, data->modecmd);
	if (cmd == MODEKEY_NONE) {
		ctx->error(ctx, "unknown command: %s", data->modecmd);
		return (-1);
	}

	mtmp.key = data->key & ~KEYC_PREFIX;
	mtmp.mode = data->command_key ? 1 : 0;
	if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
		mbind->cmd = cmd;
		return (0);
	}
	mbind = xmalloc(sizeof *mbind);
	mbind->key = mtmp.key;
	mbind->mode = mtmp.mode;
	mbind->cmd = cmd;
	SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
	return (0);
}
Esempio n. 3
0
static enum cmd_retval
cmd_bind_key_mode_table(struct cmd *self, struct cmdq_item *item, key_code key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		cmdq_error(item, "unknown key table: %s", tablename);
		return (CMD_RETURN_ERROR);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
	if (cmd == MODEKEY_NONE) {
		cmdq_error(item, "unknown command: %s", args->argv[1]);
		return (CMD_RETURN_ERROR);
	}

	if (args->argc != 2) {
		cmdq_error(item, "no argument allowed");
		return (CMD_RETURN_ERROR);
	}

	mtmp.key = key;
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
		mbind = xmalloc(sizeof *mbind);
		mbind->key = mtmp.key;
		RB_INSERT(mode_key_tree, mtab->tree, mbind);
	}
	mbind->cmd = cmd;
	return (CMD_RETURN_NORMAL);
}
Esempio n. 4
0
enum cmd_retval
cmd_bind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;
	const char			*arg;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		cmdq_error(cmdq, "unknown key table: %s", tablename);
		return (CMD_RETURN_ERROR);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
	if (cmd == MODEKEY_NONE) {
		cmdq_error(cmdq, "unknown command: %s", args->argv[1]);
		return (CMD_RETURN_ERROR);
	}

	if (cmd != MODEKEYCOPY_COPYPIPE) {
		if (args->argc != 2) {
			cmdq_error(cmdq, "no argument allowed");
			return (CMD_RETURN_ERROR);
		}
		arg = NULL;
	} else {
		if (args->argc != 3) {
			cmdq_error(cmdq, "no argument given");
			return (CMD_RETURN_ERROR);
		}
		arg = args->argv[2];
	}

	mtmp.key = key;
	mtmp.mode = !!args_has(args, 'c');
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
		mbind = xmalloc(sizeof *mbind);
		mbind->key = mtmp.key;
		mbind->mode = mtmp.mode;
		RB_INSERT(mode_key_tree, mtab->tree, mbind);
	}
	mbind->cmd = cmd;
	mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
	return (CMD_RETURN_NORMAL);
}
Esempio n. 5
0
enum cmd_retval
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;
	const char			*arg;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		cmdq_error(cmdq, "unknown key table: %s", tablename);
		return (CMD_RETURN_ERROR);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
	if (cmd == MODEKEY_NONE) {
		cmdq_error(cmdq, "unknown command: %s", args->argv[1]);
		return (CMD_RETURN_ERROR);
	}

	switch (cmd) {
	case MODEKEYCOPY_APPENDSELECTION:
	case MODEKEYCOPY_COPYSELECTION:
	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;
	}

	mtmp.key = key;
	mtmp.mode = !!args_has(args, 'c');
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
		mbind = xmalloc(sizeof *mbind);
		mbind->key = mtmp.key;
		mbind->mode = mtmp.mode;
		RB_INSERT(mode_key_tree, mtab->tree, mbind);
	}
	mbind->cmd = cmd;
	mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
	return (CMD_RETURN_NORMAL);
}