#include #include #include #include #include "common.h" #define UIRC_IRCV3 #include "uirc/functions.h" #include "uirc/mappings.h" #include "uirc/types.h" #define ANSI_COLOR_RED "\x1b[31m" #define ANSI_COLOR_GREEN "\x1b[32m" #define ANSI_COLOR_YELLOW "\x1b[33m" #define ANSI_COLOR_BLUE "\x1b[34m" #define ANSI_COLOR_GRAY "\x1b[90m" #define ANSI_COLOR_RESET "\x1b[0m" int main(void) { ssize_t bread = 1, tok; size_t pos = 0; char buffer[513]; IRC_Message out; for (; bread > 0;) { if ((bread = read(0, buffer + pos, sizeof(buffer) - 1 - pos)) > 0) { pos += (size_t)bread; buffer[pos] = '\0'; if ((tok = get_buffer_line(buffer, &out)) > 0) { if (out.cmd == PRIVMSG || out.cmd == NOTICE) { printf((out.name.nick != NULL) ? ANSI_COLOR_RED "%s" ANSI_COLOR_RESET : ANSI_COLOR_GRAY "%s" ANSI_COLOR_RESET, (out.name.nick != NULL) ? out.name.nick : "unknown"); if (out.name.host != NULL) printf("@" ANSI_COLOR_GREEN "%s" ANSI_COLOR_RESET, out.name.host); putchar('\n'); if (out.args[0] != NULL) { printf(ANSI_COLOR_YELLOW "%s" ANSI_COLOR_RESET, strchr("#+&!", *out.args[0]) != NULL ? out.args[0] : "direct"); } if (out.args[1] != NULL) printf(ANSI_COLOR_GREEN " >" ANSI_COLOR_RESET " %s\n", out.args[1]); if (out.tags.time.value != NULL) printf(ANSI_COLOR_BLUE "(%s)\n" ANSI_COLOR_RESET, out.tags.time.value); putchar('\n'); } for (long unsigned int x = 0; x < sizeof(buffer) && *(buffer + tok + x); x++) *(buffer + x) = *(buffer + x + tok); pos -= (unsigned long)tok; *(buffer + pos) = '\0'; memset(&out, '\0', sizeof(out)); } } } return 0; }