diff options
author | June McEnroe <june@causal.agency> | 2020-02-01 02:26:35 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-02-01 02:26:35 -0500 |
commit | 2b3a8bfb9c022269307feed01419c903ba754508 (patch) | |
tree | 67f588e8b1abe4563af08fa6ab92a528d74cdca0 /irc.c | |
parent | Fix CapNames array indices (diff) | |
download | catgirl-2b3a8bfb9c022269307feed01419c903ba754508.tar.gz catgirl-2b3a8bfb9c022269307feed01419c903ba754508.zip |
Add -v flag
Diffstat (limited to 'irc.c')
-rw-r--r-- | irc.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/irc.c b/irc.c index c1c0e7a..cf8aab7 100644 --- a/irc.c +++ b/irc.c @@ -101,6 +101,18 @@ int ircConnect(const char *host, const char *port) { return sock; } +static void debug(char dir, const char *line) { + if (!self.debug) return; + size_t len = strcspn(line, "\r\n"); + /*uiFormat( + Debug, Cold, NULL, "\3%02d%c%c\3 %.*s", + Gray, dir, dir, (int)len, line + );*/ + if (!isatty(STDERR_FILENO)) { + fprintf(stderr, "%c%c %.*s\n", dir, dir, (int)len, line); + } +} + void ircSend(const char *ptr, size_t len) { assert(client); while (len) { @@ -119,6 +131,7 @@ void ircFormat(const char *format, ...) { int len = vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); assert((size_t)len < sizeof(buf)); + debug('<', buf); ircSend(buf, len); } @@ -196,6 +209,7 @@ void ircRecv(void) { crlf = memmem(line, &buf[len] - line, "\r\n", 2); if (!crlf) break; *crlf = '\0'; + debug('>', line); handle(parse(line)); line = crlf + 2; } |