=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd.c,v retrieving revision 1.100 retrieving revision 1.101 diff -u -r1.100 -r1.101 --- src/usr.bin/tmux/cmd.c 2015/04/21 22:42:27 1.100 +++ src/usr.bin/tmux/cmd.c 2015/04/24 23:17:11 1.101 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.100 2015/04/21 22:42:27 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.101 2015/04/24 23:17:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -116,10 +116,12 @@ NULL }; +ARRAY_DECL(client_list, struct client *); + int cmd_session_better(struct session *, struct session *, int); struct session *cmd_choose_session_list(struct sessionslist *); struct session *cmd_choose_session(int); -struct client *cmd_choose_client(struct clients *); +struct client *cmd_choose_client(struct client_list *); struct client *cmd_lookup_client(const char *); struct session *cmd_lookup_session(struct cmd_q *, const char *, int *); struct session *cmd_lookup_session_id(const char *); @@ -452,8 +454,7 @@ { struct session *s; struct client *c; - struct clients cc; - u_int i; + struct client_list cc; if (cmdq->client != NULL && cmdq->client->session != NULL) return (cmdq->client); @@ -465,9 +466,7 @@ s = cmd_current_session(cmdq, 0); if (s != NULL && !(s->flags & SESSION_UNATTACHED)) { ARRAY_INIT(&cc); - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - if ((c = ARRAY_ITEM(&clients, i)) == NULL) - continue; + TAILQ_FOREACH(c, &clients, entry) { if (s == c->session) ARRAY_ADD(&cc, c); } @@ -478,12 +477,17 @@ return (c); } - return (cmd_choose_client(&clients)); + ARRAY_INIT(&cc); + TAILQ_FOREACH(c, &clients, entry) + ARRAY_ADD(&cc, c); + c = cmd_choose_client(&cc); + ARRAY_FREE(&cc); + return (c); } /* Choose the most recently used client from a list. */ struct client * -cmd_choose_client(struct clients *cc) +cmd_choose_client(struct client_list *cc) { struct client *c, *cbest; struct timeval *tv = NULL; @@ -615,11 +619,9 @@ { struct client *c; const char *path; - u_int i; - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c == NULL || c->session == NULL || c->tty.path == NULL) + TAILQ_FOREACH(c, &clients, entry) { + if (c->session == NULL || c->tty.path == NULL) continue; path = c->tty.path;