Make key trees and some other bits static.

This commit is contained in:
nicm 2018-08-02 11:44:07 +00:00
parent f12b857415
commit 6048b0f483
6 changed files with 71 additions and 22 deletions

View File

@ -35,6 +35,7 @@ static int cmd_find_best_winlink_with_window(struct cmd_find_state *);
static const char *cmd_find_map_table(const char *[][2], const char *);
static void cmd_find_log_state(const char *, struct cmd_find_state *);
static int cmd_find_get_session(struct cmd_find_state *, const char *);
static int cmd_find_get_window(struct cmd_find_state *, const char *, int);
static int cmd_find_get_window_with_session(struct cmd_find_state *,
@ -716,7 +717,7 @@ cmd_find_copy_state(struct cmd_find_state *dst, struct cmd_find_state *src)
}
/* Log the result. */
void
static void
cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
{
if (fs->s != NULL)

View File

@ -75,10 +75,14 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
repeat = 0;
tablewidth = keywidth = 0;
RB_FOREACH(table, key_tables, &key_tables) {
if (tablename != NULL && strcmp(table->name, tablename) != 0)
table = key_bindings_first_table ();
while (table != NULL) {
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
table = key_bindings_next_table(table);
continue;
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
}
bd = key_bindings_first(table);
while (bd != NULL) {
key = key_string_lookup_key(bd->key);
if (bd->flags & KEY_BINDING_REPEAT)
@ -90,13 +94,20 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
width = utf8_cstrwidth(key);
if (width > keywidth)
keywidth = width;
bd = key_bindings_next(table, bd);
}
table = key_bindings_next_table(table);
}
RB_FOREACH(table, key_tables, &key_tables) {
if (tablename != NULL && strcmp(table->name, tablename) != 0)
table = key_bindings_first_table ();
while (table != NULL) {
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
table = key_bindings_next_table(table);
continue;
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
}
bd = key_bindings_first(table);
while (bd != NULL) {
key = key_string_lookup_key(bd->key);
if (!repeat)
@ -122,7 +133,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
free(cp);
cmdq_print(item, "bind-key %s", tmp);
bd = key_bindings_next(table, bd);
}
table = key_bindings_next_table(table);
}
return (CMD_RETURN_NORMAL);

View File

@ -61,7 +61,7 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
struct window_pane *wp = item->target.wp;
struct session *s = item->target.s;
struct key_table *table;
struct key_binding *bd, bd_find;
struct key_binding *bd;
if (wp->mode == NULL || wp->mode->key_table == NULL) {
if (options_get_number(wp->window->options, "xterm-keys"))
@ -71,8 +71,7 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
}
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
bd_find.key = (key & ~KEYC_XTERM);
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
bd = key_bindings_get(table, key & ~KEYC_XTERM);
if (bd != NULL) {
table->references++;
key_bindings_dispatch(bd, item, c, NULL, &item->target);

View File

@ -24,17 +24,19 @@
#include "tmux.h"
RB_GENERATE(key_bindings, key_binding, entry, key_bindings_cmp);
RB_GENERATE(key_tables, key_table, entry, key_table_cmp);
struct key_tables key_tables = RB_INITIALIZER(&key_tables);
static int key_bindings_cmp(struct key_binding *, struct key_binding *);
RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp);
static int key_table_cmp(struct key_table *, struct key_table *);
RB_GENERATE_STATIC(key_tables, key_table, entry, key_table_cmp);
static struct key_tables key_tables = RB_INITIALIZER(&key_tables);
int
key_table_cmp(struct key_table *e1, struct key_table *e2)
static int
key_table_cmp(struct key_table *table1, struct key_table *table2)
{
return (strcmp(e1->name, e2->name));
return (strcmp(table1->name, table2->name));
}
int
static int
key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
{
if (bd1->key < bd2->key)
@ -64,6 +66,18 @@ key_bindings_get_table(const char *name, int create)
return (table);
}
struct key_table *
key_bindings_first_table(void)
{
return (RB_MIN(key_tables, &key_tables));
}
struct key_table *
key_bindings_next_table(struct key_table *table)
{
return (RB_NEXT(key_tables, &key_tables, table));
}
void
key_bindings_unref_table(struct key_table *table)
{
@ -83,6 +97,27 @@ key_bindings_unref_table(struct key_table *table)
free(table);
}
struct key_binding *
key_bindings_get(struct key_table *table, key_code key)
{
struct key_binding bd;
bd.key = key;
return (RB_FIND(key_bindings, &table->key_bindings, &bd));
}
struct key_binding *
key_bindings_first(struct key_table *table)
{
return (RB_MIN(key_bindings, &table->key_bindings));
}
struct key_binding *
key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
{
return (RB_NEXT(key_bindings, &table->key_bindings, bd));
}
void
key_bindings_add(const char *name, key_code key, int repeat,
struct cmd_list *cmdlist)

View File

@ -192,7 +192,7 @@ mode_tree_clear_tagged(struct mode_tree_list *mtl)
}
}
void
static void
mode_tree_up(struct mode_tree_data *mtd, int wrap)
{
if (mtd->current == 0) {

View File

@ -43,6 +43,8 @@ static void server_client_check_redraw(struct client *);
static void server_client_set_title(struct client *);
static void server_client_reset_state(struct client *);
static int server_client_assume_paste(struct session *);
static void server_client_clear_identify(struct client *,
struct window_pane *);
static void server_client_dispatch(struct imsg *, void *);
static void server_client_dispatch_command(struct client *, struct imsg *);
@ -93,7 +95,7 @@ server_client_set_identify(struct client *c, u_int delay)
}
/* Clear identify mode on client. */
void
static void
server_client_clear_identify(struct client *c, struct window_pane *wp)
{
if (~c->flags & CLIENT_IDENTIFY)
@ -815,7 +817,7 @@ server_client_handle_key(struct client *c, key_code key)
struct window_pane *wp;
struct timeval tv;
struct key_table *table, *first;
struct key_binding bd_find, *bd;
struct key_binding *bd;
int xtimeout, flags;
struct cmd_find_state fs;
key_code key0;
@ -928,8 +930,7 @@ table_changed:
try_again:
/* Try to see if there is a key binding in the current table. */
bd_find.key = key0;
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
bd = key_bindings_get(table, key0);
if (bd != NULL) {
/*
* Key was matched in this table. If currently repeating but a