#include #include #include #include #include "common.h" int main(void) { ssize_t bread = 1, tok; size_t pos = 0; char buffer[513]; IRC_Message out; for (; bread > 0;) { if ((tok = get_buffer_line(buffer, &out)) > 0) { if (out.cmd == JOIN || out.cmd == PART || out.cmd == QUIT) { if (out.cmd == JOIN || out.cmd == PART) { printf((out.cmd == JOIN) ? ANSI_COLOR_GREEN "+++" ANSI_COLOR_RESET " %s " ANSI_COLOR_GREEN "joined" ANSI_COLOR_RESET " " ANSI_COLOR_BLUE "%s" ANSI_COLOR_RESET : ANSI_COLOR_YELLOW "---" ANSI_COLOR_RESET " %s " ANSI_COLOR_YELLOW "left" ANSI_COLOR_RESET " " ANSI_COLOR_BLUE "%s" ANSI_COLOR_RESET, out.name.nick, out.args[0]); } else if (out.cmd == QUIT) { printf(ANSI_COLOR_RED "***" ANSI_COLOR_RESET " %s " ANSI_COLOR_RED "quit" ANSI_COLOR_RESET, out.name.nick); } print_local_time(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)); continue; } if ((bread = read(0, buffer + pos, sizeof(buffer) - 1 - pos)) > 0) { pos += (size_t)bread; buffer[pos] = '\0'; } } return 0; }