Make message log a TAILQ.

This commit is contained in:
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 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';

1
cmd.c
View File

@ -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 *);

View File

@ -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);

View File

@ -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");

7
tmux.h
View File

@ -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;

View File

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