terom@37: #include "irc_cmd.h" terom@37: terom@37: #include terom@37: #include terom@37: terom@37: void irc_cmd_init (irc_cmd_handlers_t *handlers) terom@37: { terom@37: CHAIN_INIT(handlers); terom@37: } terom@37: terom@37: err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg) terom@37: { terom@37: return chain_add(handlers, list, arg); terom@37: } terom@37: terom@37: void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line) terom@37: { terom@37: struct chain_head *head; terom@37: const struct irc_cmd_handler *handler; terom@37: terom@37: CHAIN_FOREACH(handlers, head) { terom@37: // look up appropriate handler terom@37: for (handler = head->chain; handler->command; handler++) { terom@37: // the command is alpha-only, so normal case-insensitive cmp is fine terom@37: if (strcasecmp(handler->command, line->command) == 0) { terom@37: // invoke the func terom@37: handler->func(line, head->arg); terom@37: terom@37: // ...only one per chain terom@37: break; terom@37: } terom@37: } terom@37: } terom@37: } terom@37: terom@69: void irc_cmd_remove (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg) terom@69: { terom@69: chain_remove(handlers, list, arg); terom@69: } terom@69: terom@37: void irc_cmd_free (irc_cmd_handlers_t *handlers) terom@37: { terom@37: chain_free(handlers); terom@37: }