summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2018-08-02 11:44:08 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2018-08-02 11:44:08 +0000
commit924aa77b8e2ecb14ecf7bf69a06a923addea022e (patch)
tree5d9113dcf4e4af4d5b29f96b91f5c407c69e259c
parentf6d0e683c295297f990b38b0d7387619243b12f5 (diff)
Make key trees and some other bits static.
-rw-r--r--usr.bin/tmux/cmd-find.c5
-rw-r--r--usr.bin/tmux/cmd-list-keys.c27
-rw-r--r--usr.bin/tmux/cmd-send-keys.c7
-rw-r--r--usr.bin/tmux/key-bindings.c51
-rw-r--r--usr.bin/tmux/mode-tree.c4
-rw-r--r--usr.bin/tmux/server-client.c11
-rw-r--r--usr.bin/tmux/tmux.h15
7 files changed, 83 insertions, 37 deletions
diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c
index 22a0161c68b..bf08acb4c1c 100644
--- a/usr.bin/tmux/cmd-find.c
+++ b/usr.bin/tmux/cmd-find.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-find.c,v 1.66 2018/06/26 13:21:28 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.67 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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)
diff --git a/usr.bin/tmux/cmd-list-keys.c b/usr.bin/tmux/cmd-list-keys.c
index 919571f15e8..897def1e0c5 100644
--- a/usr.bin/tmux/cmd-list-keys.c
+++ b/usr.bin/tmux/cmd-list-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-list-keys.c,v 1.44 2017/05/01 12:20:55 nicm Exp $ */
+/* $OpenBSD: cmd-list-keys.c,v 1.45 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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/usr.bin/tmux/cmd-send-keys.c b/usr.bin/tmux/cmd-send-keys.c
index 2d602bac226..bafeff05931 100644
--- a/usr.bin/tmux/cmd-send-keys.c
+++ b/usr.bin/tmux/cmd-send-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-send-keys.c,v 1.42 2017/06/28 11:36:39 nicm Exp $ */
+/* $OpenBSD: cmd-send-keys.c,v 1.43 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index b41fa391326..67c4e6b01f7 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.85 2018/02/28 08:55:44 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.86 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c
index 8b6ba887252..a1261e54190 100644
--- a/usr.bin/tmux/mode-tree.c
+++ b/usr.bin/tmux/mode-tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mode-tree.c,v 1.23 2018/02/28 08:55:44 nicm Exp $ */
+/* $OpenBSD: mode-tree.c,v 1.24 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 41ac6edc4b5..59f513423b3 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.253 2018/07/17 18:02:40 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.254 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index bc0ce3068ae..5f5e93009d9 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.833 2018/08/02 11:18:34 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.834 2018/08/02 11:44:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1741,7 +1741,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 *,
@@ -1810,13 +1809,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 *);
@@ -1850,7 +1849,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 *);
@@ -2214,7 +2212,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,