commit 3b037c41f6b6551533cabed8a8e691c7f5cac494
parent 01537d014b9c7d4a534244531b5230d0d415d396
Author: Santtu Lakkala <inz@inz.fi>
Date: Wed, 9 Mar 2022 15:41:47 +0200
Rework list handling
Diffstat:
M | ii.c | | | 24 | +++++++----------------- |
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/ii.c b/ii.c
@@ -36,11 +36,11 @@ enum { TOK_NICKSRV = 0, TOK_USER, TOK_CMD, TOK_CHAN, TOK_ARG, TOK_TEXT, TOK_LAST
typedef struct Channel Channel;
struct Channel {
+ Channel *next;
int fdin;
char name[IRC_CHANNEL_MAX]; /* channel name (normalized) */
char inpath[PATH_MAX]; /* input path */
char outpath[PATH_MAX]; /* output path */
- Channel *next;
};
static Channel * channel_add(const char *);
@@ -271,12 +271,8 @@ channel_add(const char *name)
free(c);
return NULL;
}
- if (!channels) {
- channels = c;
- } else {
- c->next = channels;
- channels = c;
- }
+ c->next = channels;
+ channels = c;
return c;
}
@@ -293,16 +289,10 @@ channel_join(const char *name)
static void
channel_rm(Channel *c)
{
- Channel *p;
-
- if (channels == c) {
- channels = channels->next;
- } else {
- for (p = channels; p && p->next != c; p = p->next)
- ;
- if (p && p->next == c)
- p->next = c->next;
- }
+ Channel *i;
+ for (i = (Channel *)&channels; i->next && i->next != c; i = i->next)
+ ;
+ i->next = i->next->next;
free(c);
}