[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.34

1.34    ! nicm        1: /* $OpenBSD: cmd-unbind-key.c,v 1.33 2021/08/20 19:50:17 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.25      nicm        4:  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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:
1.14      nicm       21: #include <stdlib.h>
                     22:
1.1       nicm       23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Unbind key from command.
                     27:  */
                     28:
1.29      nicm       29: static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmdq_item *);
                     30:
1.1       nicm       31: const struct cmd_entry cmd_unbind_key_entry = {
1.24      nicm       32:        .name = "unbind-key",
                     33:        .alias = "unbind",
                     34:
1.34    ! nicm       35:        .args = { "anqT:", 0, 1, NULL },
1.32      nicm       36:        .usage = "[-anq] [-T key-table] key",
1.24      nicm       37:
1.28      nicm       38:        .flags = CMD_AFTERHOOK,
1.24      nicm       39:        .exec = cmd_unbind_key_exec
1.1       nicm       40: };
                     41:
1.26      nicm       42: static enum cmd_retval
1.29      nicm       43: cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       44: {
1.31      nicm       45:        struct args     *args = cmd_get_args(self);
1.22      nicm       46:        key_code         key;
1.33      nicm       47:        const char      *tablename, *keystr = args_string(args, 0);
1.32      nicm       48:        int              quiet = args_has(args, 'q');
1.1       nicm       49:
1.32      nicm       50:        if (args_has(args, 'a')) {
1.33      nicm       51:                if (keystr != NULL) {
1.32      nicm       52:                        if (!quiet)
                     53:                                cmdq_error(item, "key given with -a");
1.17      nicm       54:                        return (CMD_RETURN_ERROR);
                     55:                }
1.13      nicm       56:
1.21      nicm       57:                tablename = args_get(args, 'T');
                     58:                if (tablename == NULL) {
1.32      nicm       59:                        if (args_has(args, 'n'))
                     60:                                tablename = "root";
                     61:                        else
                     62:                                tablename = "prefix";
1.8       nicm       63:                }
1.21      nicm       64:                if (key_bindings_get_table(tablename, 0) == NULL) {
1.32      nicm       65:                        if (!quiet) {
                     66:                                cmdq_error(item, "table %s doesn't exist" ,
                     67:                                    tablename);
                     68:                        }
1.21      nicm       69:                        return (CMD_RETURN_ERROR);
                     70:                }
1.32      nicm       71:
1.21      nicm       72:                key_bindings_remove_table(tablename);
1.15      nicm       73:                return (CMD_RETURN_NORMAL);
1.9       nicm       74:        }
1.1       nicm       75:
1.33      nicm       76:        if (keystr == NULL) {
1.32      nicm       77:                if (!quiet)
                     78:                        cmdq_error(item, "missing key");
                     79:                return (CMD_RETURN_ERROR);
                     80:        }
                     81:
1.33      nicm       82:        key = key_string_lookup_string(keystr);
1.32      nicm       83:        if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
                     84:                if (!quiet)
1.33      nicm       85:                        cmdq_error(item, "unknown key: %s", keystr);
1.32      nicm       86:                return (CMD_RETURN_ERROR);
                     87:        }
                     88:
1.21      nicm       89:        if (args_has(args, 'T')) {
                     90:                tablename = args_get(args, 'T');
                     91:                if (key_bindings_get_table(tablename, 0) == NULL) {
1.32      nicm       92:                        if (!quiet) {
                     93:                                cmdq_error(item, "table %s doesn't exist" ,
                     94:                                    tablename);
                     95:                        }
1.21      nicm       96:                        return (CMD_RETURN_ERROR);
                     97:                }
                     98:        } else if (args_has(args, 'n'))
                     99:                tablename = "root";
                    100:        else
                    101:                tablename = "prefix";
                    102:        key_bindings_remove(tablename, key);
1.15      nicm      103:        return (CMD_RETURN_NORMAL);
1.1       nicm      104: }