eel

formatter for ii(1) logs
Log | Files | Refs | README

commit 8325bc6914f114a3f2e64d369a82e00a5d1b1524
parent 80cc205a8fe5107ef2ea40395e7b14a089313e98
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  8 Oct 2017 21:24:01 +0200

eel.c: print the nick and date.

Diffstat:
Meel.c | 60+++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 45 insertions(+), 15 deletions(-)

diff --git a/eel.c b/eel.c @@ -1,24 +1,49 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <string.h> + +#define NICK_MAX 256 +#define NICK_COL 10 + +void +print_message(time_t time, char *nick, int same, char *message) +{ + char time_str[6]; + int i; + char *m = message; + + nick = same ? "" : nick; + strftime(time_str, 6, "%02H:%02M", localtime(&time)); + i = printf("%s%s %*s \n", same ? "" : "\n", time_str, NICK_COL, nick); + + for (;;) { + for (; message < message + COL; m++) { + switch (*m) { + case ' ': + blank = m; + break; + case '\0': + goto tail; + } + } + } + +tail: + fputs(message); +} int parse_message(char *line, time_t *time, char **nick, char **message) { - *time = atoi(line); - - while (*line && *line != ' ') - line++; - if (!*line) - return 0; + for (*time = atoi(line); *line != ' '; line++) + if (!*line) + return 0; *line++ = '\0'; - *nick = line; - - while (*line && *line != ' ') - line++; - if (!*line) - return 0; + for (*nick = line; *line != ' '; line++) + if (!*line) + return 0; *line = '\0'; *message = line; @@ -33,11 +58,16 @@ main(void) char *line = NULL; time_t time = 0; char *nick = NULL; - char *last = NULL; char *message = NULL; + char last[NICK_MAX]; - while (getline(&line, &len, stdin) != -1) - parse_message(line, &time, &nick, &message); + last[0] = '\0'; + while (getline(&line, &len, stdin) != -1) { + if (!parse_message(line, &time, &nick, &message)) + continue; + print_message(time, nick, !strcmp(nick, last), message); + strcpy(last, nick); + } free(line); return 0;