Make message log a TAILQ.

pull/1/head
nicm 2015-04-25 18:33:59 +00:00
parent 6dbd63ba4f
commit 07dfdb974d
6 changed files with 27 additions and 25 deletions

View File

@ -130,7 +130,6 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c; struct client *c;
struct message_entry *msg; struct message_entry *msg;
char *tim; char *tim;
u_int i;
int done; int done;
done = 0; 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) if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { TAILQ_FOREACH(msg, &c->message_log, entry) {
msg = &ARRAY_ITEM(&c->message_log, i);
tim = ctime(&msg->msg_time); tim = ctime(&msg->msg_time);
*strchr(tim, '\n') = '\0'; *strchr(tim, '\n') = '\0';

1
cmd.c
View File

@ -117,6 +117,7 @@ const struct cmd_entry *cmd_table[] = {
}; };
ARRAY_DECL(client_list, struct client *); ARRAY_DECL(client_list, struct client *);
ARRAY_DECL(sessionslist, struct session *);
int cmd_session_better(struct session *, struct session *, int); int cmd_session_better(struct session *, struct session *, int);
struct session *cmd_choose_session_list(struct sessionslist *); struct session *cmd_choose_session_list(struct sessionslist *);

View File

@ -94,7 +94,7 @@ server_client_create(int fd)
RB_INIT(&c->status_old); RB_INIT(&c->status_old);
c->message_string = NULL; c->message_string = NULL;
ARRAY_INIT(&c->message_log); TAILQ_INIT(&c->message_log);
c->prompt_string = NULL; c->prompt_string = NULL;
c->prompt_buffer = NULL; c->prompt_buffer = NULL;
@ -138,8 +138,7 @@ server_client_open(struct client *c, char **cause)
void void
server_client_lost(struct client *c) server_client_lost(struct client *c)
{ {
struct message_entry *msg; struct message_entry *msg, *msg1;
u_int i;
TAILQ_REMOVE(&clients, c, entry); TAILQ_REMOVE(&clients, c, entry);
log_debug("lost client %d", c->ibuf.fd); log_debug("lost client %d", c->ibuf.fd);
@ -175,11 +174,11 @@ server_client_lost(struct client *c)
free(c->message_string); free(c->message_string);
if (event_initialized(&c->message_timer)) if (event_initialized(&c->message_timer))
evtimer_del(&c->message_timer); evtimer_del(&c->message_timer);
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) {
msg = &ARRAY_ITEM(&c->message_log, i);
free(msg->msg); free(msg->msg);
TAILQ_REMOVE(&c->message_log, msg, entry);
free(msg);
} }
ARRAY_FREE(&c->message_log);
free(c->prompt_string); free(c->prompt_string);
free(c->prompt_buffer); free(c->prompt_buffer);

View File

@ -636,10 +636,12 @@ void
status_message_set(struct client *c, const char *fmt, ...) status_message_set(struct client *c, const char *fmt, ...)
{ {
struct timeval tv; struct timeval tv;
struct message_entry *msg; struct message_entry *msg, *msg1;
va_list ap; va_list ap;
int delay; int delay;
u_int i, limit; u_int first, limit;
limit = options_get_number(&global_options, "message-limit");
status_prompt_clear(c); status_prompt_clear(c);
status_message_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); xvasprintf(&c->message_string, fmt, ap);
va_end(ap); va_end(ap);
ARRAY_EXPAND(&c->message_log, 1); msg = xcalloc(1, sizeof *msg);
msg = &ARRAY_LAST(&c->message_log);
msg->msg_time = time(NULL); msg->msg_time = time(NULL);
msg->msg_num = c->message_next++;
msg->msg = xstrdup(c->message_string); msg->msg = xstrdup(c->message_string);
TAILQ_INSERT_TAIL(&c->message_log, msg, entry);
limit = options_get_number(&global_options, "message-limit"); first = c->message_next - limit;
if (ARRAY_LENGTH(&c->message_log) > limit) { TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) {
limit = ARRAY_LENGTH(&c->message_log) - limit; if (msg->msg_num >= first)
for (i = 0; i < limit; i++) { continue;
msg = &ARRAY_FIRST(&c->message_log);
free(msg->msg); free(msg->msg);
ARRAY_REMOVE(&c->message_log, 0); TAILQ_REMOVE(&c->message_log, msg, entry);
} free(msg);
} }
delay = options_get_number(&c->session->options, "display-time"); delay = options_get_number(&c->session->options, "display-time");

7
tmux.h
View File

@ -950,7 +950,6 @@ struct window_pane {
}; };
TAILQ_HEAD(window_panes, window_pane); TAILQ_HEAD(window_panes, window_pane);
RB_HEAD(window_pane_tree, window_pane); RB_HEAD(window_pane_tree, window_pane);
ARRAY_DECL(window_pane_list, struct window_pane *);
/* Window structure. */ /* Window structure. */
struct window { struct window {
@ -1101,7 +1100,6 @@ struct session {
RB_ENTRY(session) entry; RB_ENTRY(session) entry;
}; };
RB_HEAD(sessions, session); RB_HEAD(sessions, session);
ARRAY_DECL(sessionslist, struct session *);
/* TTY information. */ /* TTY information. */
struct tty_key { struct tty_key {
@ -1255,7 +1253,9 @@ struct tty_ctx {
/* Saved message entry. */ /* Saved message entry. */
struct message_entry { struct message_entry {
char *msg; char *msg;
u_int msg_num;
time_t msg_time; time_t msg_time;
TAILQ_ENTRY(message_entry) entry;
}; };
/* Status output data from a job. */ /* Status output data from a job. */
@ -1327,7 +1327,8 @@ struct client {
char *message_string; char *message_string;
struct event message_timer; 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_string;
char *prompt_buffer; char *prompt_buffer;

View File

@ -49,6 +49,8 @@
* it reaches zero. * it reaches zero.
*/ */
ARRAY_DECL(window_pane_list, struct window_pane *);
/* Global window list. */ /* Global window list. */
struct windows windows; struct windows windows;