Annotation of src/usr.bin/tmux/cmd-unbind-key.c, Revision 1.2
1.2 ! nicm 1: /* $OpenBSD: cmd-unbind-key.c,v 1.1 2009/06/01 22:58:49 nicm Exp $ */
1.1 nicm 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:
27: int cmd_unbind_key_parse(struct cmd *, int, char **, char **);
28: int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
29: void cmd_unbind_key_send(struct cmd *, struct buffer *);
30: void cmd_unbind_key_recv(struct cmd *, struct buffer *);
31: void cmd_unbind_key_free(struct cmd *);
32:
33: struct cmd_unbind_key_data {
34: int key;
35: };
36:
37: const struct cmd_entry cmd_unbind_key_entry = {
38: "unbind-key", "unbind",
39: "key",
1.2 ! nicm 40: 0, 0,
1.1 nicm 41: NULL,
42: cmd_unbind_key_parse,
43: cmd_unbind_key_exec,
44: cmd_unbind_key_send,
45: cmd_unbind_key_recv,
46: cmd_unbind_key_free,
47: NULL
48: };
49:
50: int
51: cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
52: {
53: struct cmd_unbind_key_data *data;
54: int opt;
55:
56: self->data = data = xmalloc(sizeof *data);
57:
58: while ((opt = getopt(argc, argv, "")) != -1) {
59: switch (opt) {
60: default:
61: goto usage;
62: }
63: }
64: argc -= optind;
65: argv += optind;
66: if (argc != 1)
67: goto usage;
68:
69: if ((data->key = key_string_lookup_string(argv[0])) == KEYC_NONE) {
70: xasprintf(cause, "unknown key: %s", argv[0]);
71: goto error;
72: }
73:
74: return (0);
75:
76: usage:
77: xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
78:
79: error:
80: xfree(data);
81: return (-1);
82: }
83:
84: int
85: cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
86: {
87: struct cmd_unbind_key_data *data = self->data;
88:
89: if (data == NULL)
90: return (0);
91:
92: key_bindings_remove(data->key);
93:
94: return (0);
95: }
96:
97: void
98: cmd_unbind_key_send(struct cmd *self, struct buffer *b)
99: {
100: struct cmd_unbind_key_data *data = self->data;
101:
102: buffer_write(b, data, sizeof *data);
103: }
104:
105: void
106: cmd_unbind_key_recv(struct cmd *self, struct buffer *b)
107: {
108: struct cmd_unbind_key_data *data;
109:
110: self->data = data = xmalloc(sizeof *data);
111: buffer_read(b, data, sizeof *data);
112: }
113:
114: void
115: cmd_unbind_key_free(struct cmd *self)
116: {
117: struct cmd_unbind_key_data *data = self->data;
118:
119: xfree(data);
120: }