summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authornicm <nicm>2015-04-24 23:17:11 +0000
committernicm <nicm>2015-04-24 23:17:11 +0000
commitaeedb464a6ee038289ddcfefae437928ab020cb1 (patch)
tree0428a0446bd50d08e4b0fe6741644e36d8b1a071 /cmd.c
parent583b4ab72b7bf66fda8ab63a08fe435483de5e5a (diff)
Convert clients list into a TAILQ.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/cmd.c b/cmd.c
index 991e079b..b81ffb36 100644
--- a/cmd.c
+++ b/cmd.c
@@ -116,10 +116,12 @@ const struct cmd_entry *cmd_table[] = {
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 @@ cmd_current_client(struct cmd_q *cmdq)
{
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 @@ cmd_current_client(struct cmd_q *cmdq)
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 @@ cmd_current_client(struct cmd_q *cmdq)
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 @@ cmd_lookup_client(const char *name)
{
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;