diff --git a/cmd-find.c b/cmd-find.c index 643da293..02450d97 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -34,6 +34,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 *, @@ -715,7 +716,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) diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 9e0cac62..5efb0cd2 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -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); diff --git a/cmd-send-keys.c b/cmd-send-keys.c index 8d2c2608..6230ecf7 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -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); diff --git a/key-bindings.c b/key-bindings.c index 83670d2d..41afd99c 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -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) diff --git a/mode-tree.c b/mode-tree.c index 05ec492d..2e4b9072 100644 --- a/mode-tree.c +++ b/mode-tree.c @@ -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) { diff --git a/server-client.c b/server-client.c index 64d894cd..84b93272 100644 --- a/server-client.c +++ b/server-client.c @@ -41,6 +41,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 *); @@ -91,7 +93,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) @@ -813,7 +815,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; @@ -926,8 +928,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 diff --git a/server.c b/server.c index 5aeb4ea6..26a0ce3e 100644 --- a/server.c +++ b/server.c @@ -201,7 +201,6 @@ server_start(struct tmuxproc *client, struct event_base *base, int lockfd, RB_INIT(&all_window_panes); TAILQ_INIT(&clients); RB_INIT(&sessions); - RB_INIT(&session_groups); key_bindings_init(); gettimeofday(&start_time, NULL); diff --git a/session.c b/session.c index 95cbe3e6..9b74326a 100644 --- a/session.c +++ b/session.c @@ -28,7 +28,7 @@ struct sessions sessions; static u_int next_session_id; -struct session_groups session_groups; +struct session_groups session_groups = RB_INITIALIZER(&session_groups); static void session_free(int, short, void *); @@ -40,21 +40,19 @@ static struct winlink *session_previous_alert(struct winlink *); static void session_group_remove(struct session *); static void session_group_synchronize1(struct session *, struct session *); -RB_GENERATE(sessions, session, entry, session_cmp); - int session_cmp(struct session *s1, struct session *s2) { return (strcmp(s1->name, s2->name)); } +RB_GENERATE(sessions, session, entry, session_cmp); -RB_GENERATE(session_groups, session_group, entry, session_group_cmp); - -int +static int session_group_cmp(struct session_group *s1, struct session_group *s2) { return (strcmp(s1->name, s2->name)); } +RB_GENERATE_STATIC(session_groups, session_group, entry, session_group_cmp); /* * Find if session is still alive. This is true if it is still on the global diff --git a/tmux.h b/tmux.h index d1a55011..7e46bfeb 100644 --- a/tmux.h +++ b/tmux.h @@ -1745,7 +1745,6 @@ int cmd_find_empty_state(struct cmd_find_state *); int cmd_find_valid_state(struct cmd_find_state *); void cmd_find_copy_state(struct cmd_find_state *, struct cmd_find_state *); -void cmd_find_log_state(const char *, struct cmd_find_state *); void cmd_find_from_session(struct cmd_find_state *, struct session *, int); void cmd_find_from_winlink(struct cmd_find_state *, @@ -1814,13 +1813,13 @@ void cmd_wait_for_flush(void); int client_main(struct event_base *, int, char **, int); /* key-bindings.c */ -RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp); -RB_PROTOTYPE(key_tables, key_table, entry, key_table_cmp); -extern struct key_tables key_tables; -int key_table_cmp(struct key_table *, struct key_table *); -int key_bindings_cmp(struct key_binding *, struct key_binding *); struct key_table *key_bindings_get_table(const char *, int); +struct key_table *key_bindings_first_table(void); +struct key_table *key_bindings_next_table(struct key_table *); void key_bindings_unref_table(struct key_table *); +struct key_binding *key_bindings_get(struct key_table *, key_code); +struct key_binding *key_bindings_first(struct key_table *); +struct key_binding *key_bindings_next(struct key_table *, struct key_binding *); void key_bindings_add(const char *, key_code, int, struct cmd_list *); void key_bindings_remove(const char *, key_code); void key_bindings_remove_table(const char *); @@ -1854,7 +1853,6 @@ void server_add_accept(int); /* server-client.c */ u_int server_client_how_many(void); void server_client_set_identify(struct client *, u_int); -void server_client_clear_identify(struct client *, struct window_pane *); void server_client_set_key_table(struct client *, const char *); const char *server_client_get_key_table(struct client *); int server_client_check_nested(struct client *); @@ -2218,7 +2216,6 @@ void mode_tree_expand_current(struct mode_tree_data *); void mode_tree_set_current(struct mode_tree_data *, uint64_t); void mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb, struct client *, key_code, int); -void mode_tree_up(struct mode_tree_data *, int); void mode_tree_down(struct mode_tree_data *, int); struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *, mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb, @@ -2288,11 +2285,8 @@ void control_notify_session_window_changed(struct session *); /* session.c */ extern struct sessions sessions; -extern struct session_groups session_groups; int session_cmp(struct session *, struct session *); RB_PROTOTYPE(sessions, session, entry, session_cmp); -int session_group_cmp(struct session_group *, struct session_group *); -RB_PROTOTYPE(session_groups, session_group, entry, session_group_cmp); int session_alive(struct session *); struct session *session_find(const char *); struct session *session_find_by_id_str(const char *);