Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (89 sloc) 2.769 kb
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
1 /* $Id: cmd-unbind-key.c 2553 2011-07-09 09:42:33Z tcunha $ */
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
2
3 /*
4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/types.h>
20
21 #include "tmux.h"
22
23 /*
24 * Unbind key from command.
25 */
26
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
27 int cmd_unbind_key_check(struct args *);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
28 int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
29
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
30 int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
31
32 const struct cmd_entry cmd_unbind_key_entry = {
33 "unbind-key", "unbind",
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
34 "acnt:", 0, 1,
77c63de6 » orebokech
2010-12-28 Import upstream version 1.4
35 "[-acn] [-t key-table] key",
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
36 0,
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
37 NULL,
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
38 cmd_unbind_key_check,
39 cmd_unbind_key_exec
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
40 };
41
42 int
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
43 cmd_unbind_key_check(struct args *args)
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
44 {
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
45 if (args_has(args, 'a') && (args->argc != 0 || args_has(args, 't')))
46 return (-1);
47 if (!args_has(args, 'a') && args->argc != 1)
48 return (-1);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
49 return (0);
50 }
51
52 int
53 cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
54 {
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
55 struct args *args = self->args;
56 struct key_binding *bd;
57 int key;
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
58
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
59 if (args_has(args, 'a')) {
77c63de6 » orebokech
2010-12-28 Import upstream version 1.4
60 while (!SPLAY_EMPTY(&key_bindings)) {
61 bd = SPLAY_ROOT(&key_bindings);
62 SPLAY_REMOVE(key_bindings, &key_bindings, bd);
63 cmd_list_free(bd->cmdlist);
64 xfree(bd);
65 }
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
66 return (0);
67 }
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
68
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
69 key = key_string_lookup_string(args->argv[0]);
70 if (key == KEYC_NONE) {
71 ctx->error(ctx, "unknown key: %s", args->argv[0]);
72 return (-1);
77c63de6 » orebokech
2010-12-28 Import upstream version 1.4
73 }
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
74
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
75 if (args_has(args, 't'))
76 return (cmd_unbind_key_table(self, ctx, key));
77
78 if (!args_has(args, 'n'))
79 key |= KEYC_PREFIX;
80 key_bindings_remove(key);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
81 return (0);
82 }
83
84 int
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
85 cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
86 {
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
87 struct args *args = self->args;
88 const char *tablename;
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
89 const struct mode_key_table *mtab;
90 struct mode_key_binding *mbind, mtmp;
91
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
92 tablename = args_get(args, 't');
93 if ((mtab = mode_key_findtable(tablename)) == NULL) {
94 ctx->error(ctx, "unknown key table: %s", tablename);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
95 return (-1);
96 }
97
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
98 mtmp.key = key;
99 mtmp.mode = !!args_has(args, 'c');
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
100 if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
101 SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
102 xfree(mbind);
103 }
104 return (0);
105 }
Something went wrong with that request. Please try again.