#define LIST_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next)
#define LIST_FOREACH_SAFE(pos, n, head) for (pos = (head), n = pos ? pos->next : NULL; pos != NULL; pos = n, n = pos ? pos->next : NULL)
#define LIST_FOREACH_PREV(pos, head) for (pos = (head); pos != NULL; pos = pos->prev)
-#define LIST_SIZE(list) list->elements
+#define LIST_SIZE(list) (list)->elements
typedef struct _node node_t;
typedef struct _list list_t;
#include "stats.h"
-static list_t *COMMANDS; /* List of active commands */
+static list_t COMMANDS; /* List of active commands */
/* cmd_check
}
}
-/* command_init
- *
- * Do command initialization
- *
- * Parameters: NONE
- * Return: NONE
- *
- */
-void
-command_init(void)
-{
- if (COMMANDS == NULL)
- COMMANDS = list_create();
-}
-
/* command_create
*
* Create a Command struct.
source_p->irc_nick, target->name);
/* Only allow COMMANDMAX commands in the queue */
- if (LIST_SIZE(COMMANDS) >= COMMANDMAX)
+ if (LIST_SIZE(&COMMANDS) >= COMMANDMAX)
return;
/*
/* Queue this command */
struct Command *command = command_create(tab, param, source_p->irc_nick, target);
- list_add(COMMANDS, node_create(command));
+ list_add(&COMMANDS, node_create(command));
break;
}
}
time(&present);
- LIST_FOREACH_SAFE(node, node_next, COMMANDS->head)
+ LIST_FOREACH_SAFE(node, node_next, COMMANDS.head)
{
struct Command *command = node->data;
if ((present - command->added) > COMMANDTIMEOUT)
{
command_free(command);
- list_remove(COMMANDS, node);
+ list_remove(&COMMANDS, node);
node_free(node);
}
else /* Since the queue is in order, it's also ordered by time, no nodes after this will be timed out */
*(tmp) = '\0';
/* Find any queued commands that match this user */
- LIST_FOREACH_SAFE(node, node_next, COMMANDS->head)
+ LIST_FOREACH_SAFE(node, node_next, COMMANDS.head)
{
struct Command *command = node->data;
/* Cleanup the command */
command_free(command);
- list_remove(COMMANDS, node);
+ list_remove(&COMMANDS, node);
node_free(node);
}
}