version 1.105, 2019/12/19 09:22:33 |
version 1.106, 2020/01/05 20:39:25 |
|
|
return (0); |
return (0); |
} |
} |
|
|
|
static void |
|
key_bindings_free(struct key_table *table, struct key_binding *bd) |
|
{ |
|
RB_REMOVE(key_bindings, &table->key_bindings, bd); |
|
cmd_list_free(bd->cmdlist); |
|
free(bd); |
|
} |
|
|
struct key_table * |
struct key_table * |
key_bindings_get_table(const char *name, int create) |
key_bindings_get_table(const char *name, int create) |
{ |
{ |
|
|
if (--table->references != 0) |
if (--table->references != 0) |
return; |
return; |
|
|
RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1) { |
RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1) |
RB_REMOVE(key_bindings, &table->key_bindings, bd); |
key_bindings_free(table, bd); |
cmd_list_free(bd->cmdlist); |
|
free(bd); |
|
} |
|
|
|
free((void *)table->name); |
free((void *)table->name); |
free(table); |
free(table); |
|
|
struct cmd_list *cmdlist) |
struct cmd_list *cmdlist) |
{ |
{ |
struct key_table *table; |
struct key_table *table; |
struct key_binding bd_find, *bd; |
struct key_binding *bd; |
|
|
table = key_bindings_get_table(name, 1); |
table = key_bindings_get_table(name, 1); |
|
|
bd_find.key = (key & ~KEYC_XTERM); |
bd = key_bindings_get(table, key & ~KEYC_XTERM); |
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find); |
if (bd != NULL) |
if (bd != NULL) { |
key_bindings_free(table, bd); |
RB_REMOVE(key_bindings, &table->key_bindings, bd); |
|
cmd_list_free(bd->cmdlist); |
|
free(bd); |
|
} |
|
|
|
bd = xcalloc(1, sizeof *bd); |
bd = xcalloc(1, sizeof *bd); |
bd->key = key; |
bd->key = key; |
|
|
key_bindings_remove(const char *name, key_code key) |
key_bindings_remove(const char *name, key_code key) |
{ |
{ |
struct key_table *table; |
struct key_table *table; |
struct key_binding bd_find, *bd; |
struct key_binding *bd; |
|
|
table = key_bindings_get_table(name, 0); |
table = key_bindings_get_table(name, 0); |
if (table == NULL) |
if (table == NULL) |
return; |
return; |
|
|
bd_find.key = (key & ~KEYC_XTERM); |
bd = key_bindings_get(table, key & ~KEYC_XTERM); |
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find); |
|
if (bd == NULL) |
if (bd == NULL) |
return; |
return; |
|
key_bindings_free(table, bd); |
RB_REMOVE(key_bindings, &table->key_bindings, bd); |
|
cmd_list_free(bd->cmdlist); |
|
free(bd); |
|
|
|
if (RB_EMPTY(&table->key_bindings)) { |
if (RB_EMPTY(&table->key_bindings)) { |
RB_REMOVE(key_tables, &key_tables, table); |
RB_REMOVE(key_tables, &key_tables, table); |