From 86788aa8adc87e5a274ecc5bcaeca1c838b5e1b6 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 25 Apr 2015 18:33:59 +0000 Subject: [PATCH] Make message log a TAILQ. --- usr.bin/tmux/cmd-show-messages.c | 7 ++----- usr.bin/tmux/cmd.c | 3 ++- usr.bin/tmux/server-client.c | 13 ++++++------- usr.bin/tmux/status.c | 28 +++++++++++++++------------- usr.bin/tmux/tmux.h | 9 +++++---- usr.bin/tmux/window.c | 4 +++- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/usr.bin/tmux/cmd-show-messages.c b/usr.bin/tmux/cmd-show-messages.c index 2ce8f8a1753..e71aa43a879 100644 --- a/usr.bin/tmux/cmd-show-messages.c +++ b/usr.bin/tmux/cmd-show-messages.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-messages.c,v 1.10 2014/10/20 22:29:25 nicm Exp $ */ +/* $OpenBSD: cmd-show-messages.c,v 1.11 2015/04/25 18:33:59 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -130,7 +130,6 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq) struct client *c; struct message_entry *msg; char *tim; - u_int i; int done; done = 0; @@ -156,9 +155,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq) if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL) return (CMD_RETURN_ERROR); - for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { - msg = &ARRAY_ITEM(&c->message_log, i); - + TAILQ_FOREACH(msg, &c->message_log, entry) { tim = ctime(&msg->msg_time); *strchr(tim, '\n') = '\0'; diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index f1c3fa69fca..44a265275c6 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.102 2015/04/25 18:09:28 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.103 2015/04/25 18:33:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -117,6 +117,7 @@ const struct cmd_entry *cmd_table[] = { }; ARRAY_DECL(client_list, struct client *); +ARRAY_DECL(sessionslist, struct session *); int cmd_session_better(struct session *, struct session *, int); struct session *cmd_choose_session_list(struct sessionslist *); diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 49080528751..c126fc3b40f 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.135 2015/04/24 23:17:11 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.136 2015/04/25 18:33:59 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -94,7 +94,7 @@ server_client_create(int fd) RB_INIT(&c->status_old); c->message_string = NULL; - ARRAY_INIT(&c->message_log); + TAILQ_INIT(&c->message_log); c->prompt_string = NULL; c->prompt_buffer = NULL; @@ -138,8 +138,7 @@ server_client_open(struct client *c, char **cause) void server_client_lost(struct client *c) { - struct message_entry *msg; - u_int i; + struct message_entry *msg, *msg1; TAILQ_REMOVE(&clients, c, entry); log_debug("lost client %d", c->ibuf.fd); @@ -175,11 +174,11 @@ server_client_lost(struct client *c) free(c->message_string); if (event_initialized(&c->message_timer)) evtimer_del(&c->message_timer); - for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { - msg = &ARRAY_ITEM(&c->message_log, i); + TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) { free(msg->msg); + TAILQ_REMOVE(&c->message_log, msg, entry); + free(msg); } - ARRAY_FREE(&c->message_log); free(c->prompt_string); free(c->prompt_buffer); diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 8ef0bdc0139..9cd04e196d9 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.126 2015/04/24 22:19:36 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.127 2015/04/25 18:33:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -636,10 +636,12 @@ void status_message_set(struct client *c, const char *fmt, ...) { struct timeval tv; - struct message_entry *msg; + struct message_entry *msg, *msg1; va_list ap; int delay; - u_int i, limit; + u_int first, limit; + + limit = options_get_number(&global_options, "message-limit"); status_prompt_clear(c); status_message_clear(c); @@ -648,19 +650,19 @@ status_message_set(struct client *c, const char *fmt, ...) xvasprintf(&c->message_string, fmt, ap); va_end(ap); - ARRAY_EXPAND(&c->message_log, 1); - msg = &ARRAY_LAST(&c->message_log); + msg = xcalloc(1, sizeof *msg); msg->msg_time = time(NULL); + msg->msg_num = c->message_next++; msg->msg = xstrdup(c->message_string); + TAILQ_INSERT_TAIL(&c->message_log, msg, entry); - limit = options_get_number(&global_options, "message-limit"); - if (ARRAY_LENGTH(&c->message_log) > limit) { - limit = ARRAY_LENGTH(&c->message_log) - limit; - for (i = 0; i < limit; i++) { - msg = &ARRAY_FIRST(&c->message_log); - free(msg->msg); - ARRAY_REMOVE(&c->message_log, 0); - } + first = c->message_next - limit; + TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) { + if (msg->msg_num >= first) + continue; + free(msg->msg); + TAILQ_REMOVE(&c->message_log, msg, entry); + free(msg); } delay = options_get_number(&c->session->options, "display-time"); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 1af1c2861ab..5d060b9f6f5 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.500 2015/04/25 18:09:28 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.501 2015/04/25 18:33:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -950,7 +950,6 @@ struct window_pane { }; TAILQ_HEAD(window_panes, window_pane); RB_HEAD(window_pane_tree, window_pane); -ARRAY_DECL(window_pane_list, struct window_pane *); /* Window structure. */ struct window { @@ -1101,7 +1100,6 @@ struct session { RB_ENTRY(session) entry; }; RB_HEAD(sessions, session); -ARRAY_DECL(sessionslist, struct session *); /* TTY information. */ struct tty_key { @@ -1255,7 +1253,9 @@ struct tty_ctx { /* Saved message entry. */ struct message_entry { char *msg; + u_int msg_num; time_t msg_time; + TAILQ_ENTRY(message_entry) entry; }; /* Status output data from a job. */ @@ -1327,7 +1327,8 @@ struct client { char *message_string; struct event message_timer; - ARRAY_DECL(, struct message_entry) message_log; + u_int message_next; + TAILQ_HEAD(, message_entry) message_log; char *prompt_string; char *prompt_buffer; diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index c151127a624..bd2a421a70c 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.123 2015/04/25 18:09:28 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.124 2015/04/25 18:33:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -49,6 +49,8 @@ * it reaches zero. */ +ARRAY_DECL(window_pane_list, struct window_pane *); + /* Global window list. */ struct windows windows; -- 2.20.1