This repository has been archived on 2021-01-07. You can view files and clone it, but cannot push or open issues or pull requests.
irc-toolkit/irc-list.c

36 lines
983 B
C
Raw Normal View History

2020-10-17 09:48:34 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
2020-10-29 20:12:34 +00:00
#include "common.h"
2020-10-17 09:48:34 +00:00
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) {
2021-01-07 11:49:06 +00:00
if (out.cmd == RPL_LISTSTART || out.cmd == RPL_LIST) {
printf(ANSI_COLOR_YELLOW "%s" ANSI_COLOR_RESET "\nTopic: %s\nUsers: %s\n", out.args[1], out.args[3], out.args[2]);
print_local_time(out.tags.time.value);
putchar('\n');
2021-01-07 11:49:06 +00:00
} else if (out.cmd == RPL_LISTEND) {
printf(ANSI_COLOR_RED "----- END" ANSI_COLOR_RESET "\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;
}
2020-10-17 09:48:34 +00:00
if ((bread = read(0, buffer + pos, sizeof(buffer) - 1 - pos)) > 0) {
pos += (size_t)bread;
buffer[pos] = '\0';
}
}
return 0;
}