diff options
author | June McEnroe <june@causal.agency> | 2019-02-22 15:49:55 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-02-22 15:49:55 -0500 |
commit | 2c07d5041540239fb6fe25af7748aa463a98ed6e (patch) | |
tree | 51f74deb73a7dadc5c6f3200359f3511abfef9fb | |
parent | Fix name of <raw> window in man page (diff) | |
download | catgirl-2c07d5041540239fb6fe25af7748aa463a98ed6e.tar.gz catgirl-2c07d5041540239fb6fe25af7748aa463a98ed6e.zip |
Reorganize input.c
-rw-r--r-- | input.c | 154 |
1 files changed, 74 insertions, 80 deletions
diff --git a/input.c b/input.c index 32c7e2b..370d757 100644 --- a/input.c +++ b/input.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Curtis McEnroe <june@causal.agency> +/* Copyright (C) 2018 C. McEnroe <june@causal.agency> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -25,7 +25,6 @@ #include "chat.h" static void privmsg(struct Tag tag, bool action, const char *mesg) { - if (tag.id == TagStatus.id || tag.id == TagRaw.id) return; char *line; int send; asprintf( @@ -39,26 +38,10 @@ static void privmsg(struct Tag tag, bool action, const char *mesg) { free(line); } -static char * -param(struct Tag tag, const char *command, char **params, const char *name) { - char *param = strsep(params, " "); - if (param) return param; - uiFmt(tag, UIHot, "%s requires a %s", command, name); - return NULL; -} - typedef void Handler(struct Tag tag, char *params); -static void inputRaw(struct Tag tag, char *params) { - (void)tag; - if (!params || !self.raw) { - self.raw ^= true; - uiFmt( - TagRaw, UIWarm, "Raw window is %s", - self.raw ? "enabled" : "disabled" - ); - } - if (params) ircFmt("%s\r\n", params); +static void inputJoin(struct Tag tag, char *params) { + ircFmt("JOIN :%s\r\n", params ? params : tag.name); } static void inputMe(struct Tag tag, char *params) { @@ -66,17 +49,11 @@ static void inputMe(struct Tag tag, char *params) { } static void inputNick(struct Tag tag, char *params) { - (void)tag; - char *nick = param(tag, "/nick", ¶ms, "name"); - if (!nick) return; - ircFmt("NICK %s\r\n", nick); -} - -static void inputJoin(struct Tag tag, char *params) { - (void)tag; - char *chan = param(tag, "/join", ¶ms, "channel"); - if (!chan) return; - ircFmt("JOIN %s\r\n", chan); + if (params) { + ircFmt("NICK :%s\r\n", params); + } else { + uiLog(tag, UIHot, L"/nick requires a nickname"); + } } static void inputPart(struct Tag tag, char *params) { @@ -84,24 +61,19 @@ static void inputPart(struct Tag tag, char *params) { } static void inputQuery(struct Tag tag, char *params) { - (void)tag; - char *nick = param(tag, "/query", ¶ms, "nick"); - if (!nick) return; - tabTouch(TagNone, nick); - uiShowTag(tagFor(nick)); - logReplay(tagFor(nick)); -} - -static void inputWho(struct Tag tag, char *params) { - (void)params; - ircFmt("WHO %s\r\n", tag.name); + char *nick = strsep(¶ms, " "); + if (nick) { + tabTouch(TagNone, nick); + uiShowTag(tagFor(nick)); + logReplay(tagFor(nick)); + } else { + uiLog(tag, UIHot, L"/query requires a nickname"); + } } -static void inputWhois(struct Tag tag, char *params) { +static void inputQuit(struct Tag tag, char *params) { (void)tag; - char *nick = param(tag, "/whois", ¶ms, "nick"); - if (!nick) return; - ircFmt("WHOIS %s\r\n", nick); + ircQuit(params ? params : "Goodbye"); } static void inputTopic(struct Tag tag, char *params) { @@ -112,15 +84,31 @@ static void inputTopic(struct Tag tag, char *params) { } } -static void inputQuit(struct Tag tag, char *params) { - (void)tag; - ircQuit(params ? params : "Goodbye"); +static void inputWho(struct Tag tag, char *params) { + (void)params; + ircFmt("WHO :%s\r\n", tag.name); } -static void inputURL(struct Tag tag, char *params) { +static void inputWhois(struct Tag tag, char *params) { + if (params) { + ircFmt("WHOIS :%s\r\n", params); + } else { + uiLog(tag, UIHot, L"/whois requires a nick"); + } +} + +static void inputClose(struct Tag tag, char *params) { (void)params; - urlList(tag); + uiCloseTag(tag); + tabRemove(TagNone, tag.name); } + +static void inputMan(struct Tag tag, char *params) { + (void)tag; + (void)params; + eventWait((const char *[]) { "man", "1", "catgirl", NULL }); +} + static void inputOpen(struct Tag tag, char *params) { if (params && !isdigit(params[0])) { urlOpenMatch(tag, params); @@ -131,33 +119,39 @@ static void inputOpen(struct Tag tag, char *params) { } } -static void inputWindow(struct Tag tag, char *params) { +static void inputRaw(struct Tag tag, char *params) { (void)tag; - char *name = param(tag, "/window", ¶ms, "name or number"); - if (!name) return; - int num = strtol(name, &name, 0); - if (!name[0]) { - uiShowNum(num); - } else { - struct Tag tag = tagFind(name); - if (tag.id != TagNone.id) { - uiShowTag(tag); - } else { - uiFmt(tag, UIHot, "No window for %s", name); - } + if (!self.raw || !params) { + self.raw ^= true; + uiFmt( + TagRaw, UIWarm, "%s window is %s", + TagRaw.name, (self.raw ? "enabled" : "disabled") + ); } + if (params) ircFmt("%s\r\n", params); } -static void inputClose(struct Tag tag, char *params) { +static void inputURL(struct Tag tag, char *params) { (void)params; - uiCloseTag(tag); - tabRemove(TagNone, tag.name); + urlList(tag); } -static void inputMan(struct Tag tag, char *params) { - (void)tag; - (void)params; - eventWait((const char *[]) { "man", "1", "catgirl", NULL }); +static void inputWindow(struct Tag tag, char *params) { + if (!params) { + uiLog(tag, UIHot, L"/window requires a name or number"); + return; + } + int num = strtol(params, ¶ms, 0); + if (!params[0]) { + uiShowNum(num); + } else { + struct Tag name = tagFind(params); + if (name.id != TagNone.id) { + uiShowTag(name); + } else { + uiFmt(tag, UIHot, "No window for %s", params); + } + } } static const struct { @@ -184,6 +178,12 @@ static const struct { }; static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]); +void inputTab(void) { + for (size_t i = 0; i < CommandsLen; ++i) { + tabTouch(TagNone, Commands[i].command); + } +} + void input(struct Tag tag, char *input) { bool slash = (input[0] == '/'); if (slash) { @@ -195,7 +195,7 @@ void input(struct Tag tag, char *input) { if (!slash) { if (tag.id == TagRaw.id) { ircFmt("%s\r\n", input); - } else { + } else if (tag.id != TagStatus.id) { privmsg(tag, false, input); } return; @@ -213,7 +213,7 @@ void input(struct Tag tag, char *input) { const char *command = word; const char *uniq = tabNext(TagNone, command); - if (uniq && uniq == tabNext(TagNone, command)) { + if (uniq && tabNext(TagNone, command) == uniq) { command = uniq; tabAccept(); } else { @@ -225,11 +225,5 @@ void input(struct Tag tag, char *input) { Commands[i].handler(tag, input); return; } - uiFmt(tag, UICold, "%s isn't a recognized command", command); -} - -void inputTab(void) { - for (size_t i = 0; i < CommandsLen; ++i) { - tabTouch(TagNone, Commands[i].command); - } + uiFmt(tag, UIHot, "%s isn't a recognized command", command); } |