eel

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

commit fc944fb514fe39fa9de9bc179ddeea2919689104
parent 8325bc6914f114a3f2e64d369a82e00a5d1b1524
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  8 Oct 2017 23:00:49 +0200

eel.c: first working version

Diffstat:
Meel.c | 76++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/eel.c b/eel.c @@ -4,49 +4,69 @@ #include <string.h> #define NICK_MAX 256 -#define NICK_COL 10 +#define NICK 10 +#define TIME 6 +#define COLS 80 -void -print_message(time_t time, char *nick, int same, char *message) +char * +print_row(char *time, char *nick, 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); + char *blank = NULL; + char *m = message; + int offset = printf("%*s %*s ", TIME, time, NICK, nick); - for (;;) { - for (; message < message + COL; m++) { - switch (*m) { - case ' ': - blank = m; - break; - case '\0': + for (; offset + (m - message) < COLS; m++) { + if (*m == ' ') + blank = m; + if (!*m) + goto tail; + } + if (!blank) { + for (; *m != ' '; m++) + if (m == '\0') goto tail; - } - } + blank = m; } + *blank = '\0'; + puts(message); + return blank + 1; tail: - fputs(message); + fputs(message, stdout); + return NULL; +} + +void +print_message(time_t time, char *nick, int same, char *message) +{ + char time_str[TIME]; + + if (same) + nick = ""; + else + putchar('\n'); + + strftime(time_str, TIME, "%02H:%02M", localtime(&time)); + while ((message = print_row(time_str, nick, message))) { + time_str[0] = '\0'; + nick = ""; + } } int -parse_message(char *line, time_t *time, char **nick, char **message) +parse_message(char *str, time_t *time, char **nick, char **message) { - for (*time = atoi(line); *line != ' '; line++) - if (!*line) + for (*time = atoi(str); *str != ' '; str++) + if (!*str) return 0; - *line++ = '\0'; + *str++ = '\0'; - for (*nick = line; *line != ' '; line++) - if (!*line) + for (*nick = str; *str != ' '; str++) + if (!*str) return 0; - *line = '\0'; + *str = '\0'; - *message = line; + *message = str + 1; return 1; }