[BACK]Return to cmd-unbind-key.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-unbind-key.c, Revision 1.3

1.3     ! nicm        1: /* $OpenBSD: cmd-unbind-key.c,v 1.2 2009/07/13 23:11:35 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",
1.3     ! nicm       39:        "[-n] 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;
1.3     ! nicm       54:        int                              opt, no_prefix = 0;
1.1       nicm       55:
                     56:        self->data = data = xmalloc(sizeof *data);
                     57:
1.3     ! nicm       58:        while ((opt = getopt(argc, argv, "n")) != -1) {
1.1       nicm       59:                switch (opt) {
1.3     ! nicm       60:                case 'n':
        !            61:                        no_prefix = 1;
        !            62:                        break;
1.1       nicm       63:                default:
                     64:                        goto usage;
                     65:                }
                     66:        }
                     67:        argc -= optind;
                     68:        argv += optind;
                     69:        if (argc != 1)
                     70:                goto usage;
                     71:
                     72:        if ((data->key = key_string_lookup_string(argv[0])) == KEYC_NONE) {
                     73:                xasprintf(cause, "unknown key: %s", argv[0]);
                     74:                goto error;
                     75:        }
1.3     ! nicm       76:        if (!no_prefix)
        !            77:                data->key |= KEYC_PREFIX;
1.1       nicm       78:
                     79:        return (0);
                     80:
                     81: usage:
                     82:        xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
                     83:
                     84: error:
                     85:        xfree(data);
                     86:        return (-1);
                     87: }
                     88:
                     89: int
                     90: cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
                     91: {
                     92:        struct cmd_unbind_key_data      *data = self->data;
                     93:
                     94:        if (data == NULL)
                     95:                return (0);
                     96:
                     97:        key_bindings_remove(data->key);
                     98:
                     99:        return (0);
                    100: }
                    101:
                    102: void
                    103: cmd_unbind_key_send(struct cmd *self, struct buffer *b)
                    104: {
                    105:        struct cmd_unbind_key_data      *data = self->data;
                    106:
                    107:        buffer_write(b, data, sizeof *data);
                    108: }
                    109:
                    110: void
                    111: cmd_unbind_key_recv(struct cmd *self, struct buffer *b)
                    112: {
                    113:        struct cmd_unbind_key_data      *data;
                    114:
                    115:        self->data = data = xmalloc(sizeof *data);
                    116:        buffer_read(b, data, sizeof *data);
                    117: }
                    118:
                    119: void
                    120: cmd_unbind_key_free(struct cmd *self)
                    121: {
                    122:        struct cmd_unbind_key_data      *data = self->data;
                    123:
                    124:        xfree(data);
                    125: }