diff options
author | June McEnroe <june@causal.agency> | 2018-08-03 14:12:49 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-08-03 14:12:49 -0400 |
commit | c383f9f3a7c7f712b9183b49e4c554e5b9a6ad46 (patch) | |
tree | 342a277587a7972f31070e59a8bd6d5d65c9bfb9 | |
parent | Link with -lcursesw (diff) | |
download | catgirl-c383f9f3a7c7f712b9183b49e4c554e5b9a6ad46.tar.gz catgirl-c383f9f3a7c7f712b9183b49e4c554e5b9a6ad46.zip |
Add prift function for "prefix shift"
Forgive me.
Diffstat (limited to '')
-rw-r--r-- | chat.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/chat.c b/chat.c index 4955b4b..cea0f11 100644 --- a/chat.c +++ b/chat.c @@ -126,6 +126,9 @@ static void clientFmt(const char *format, ...) { typedef void (*Handler)(char *prefix, char *params); +static char *prift(char **prefix) { + return strsep(prefix, "!@"); +} static char *shift(char **params) { char *rest = *params; if (!rest) errx(EX_PROTOCOL, "expected param"); @@ -147,20 +150,20 @@ static void handlePing(char *prefix, char *params) { } static void handleJoin(char *prefix, char *params) { - char *nick = strsep(&prefix, "!"); + char *nick = prift(&prefix); char *chan = shift(¶ms); uiFmt("--> %s arrived in %s", nick, chan); } static void handlePart(char *prefix, char *params) { - char *nick = strsep(&prefix, "!"); + char *nick = prift(&prefix); char *chan = shift(¶ms); - char *reason = shift(¶ms); - uiFmt("<-- %s left %s, \"%s\"", nick, chan, reason); + char *mesg = shift(¶ms); + uiFmt("<-- %s left %s, \"%s\"", nick, chan, mesg); } static void handleQuit(char *prefix, char *params) { - char *nick = strsep(&prefix, "!"); - char *reason = shift(¶ms); - uiFmt("<-- %s left, \"%s\"", nick, reason); + char *nick = prift(&prefix); + char *mesg = shift(¶ms); + uiFmt("<-- %s left, \"%s\"", nick, mesg); } static void handle332(char *prefix, char *params) { @@ -168,15 +171,15 @@ static void handle332(char *prefix, char *params) { shift(¶ms); char *chan = shift(¶ms); char *topic = shift(¶ms); - uiTopic(topic); uiFmt("--- The sign in %s reads, \"%s\"", chan, topic); + uiTopic(topic); } static void handleTopic(char *prefix, char *params) { - char *nick = strsep(&prefix, "!"); + char *nick = prift(&prefix); char *chan = shift(¶ms); char *topic = shift(¶ms); - uiTopic(topic); uiFmt("--- %s placed a new sign in %s, \"%s\"", nick, chan, topic); + uiTopic(topic); } static void handle353(char *prefix, char *params) { @@ -190,13 +193,13 @@ static void handle353(char *prefix, char *params) { } static void handlePrivmsg(char *prefix, char *params) { - char *nick = strsep(&prefix, "!"); + char *nick = prift(&prefix); shift(¶ms); char *message = shift(¶ms); uiFmt("<%s> %s", nick, message); } static void handleNotice(char *prefix, char *params) { - char *nick = strsep(&prefix, "!"); + char *nick = prift(&prefix); shift(¶ms); char *message = shift(¶ms); uiFmt("-%s- %s", nick, message); |