eel

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

commit 636a27b68cce13178b15da7bc18300a03bcb17a4
parent c9596a22b7f839a59d4be405399e19fe0bc2759f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 11 Dec 2017 03:24:47 +0100

coding style and fflush

Diffstat:
Meel.c | 47+++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/eel.c b/eel.c @@ -11,28 +11,30 @@ char * print_row(char *time, char *nick, char *message) { - char *blank = NULL; - char *m = message; - int offset = printf("%*s %*s ", TIME_COL, time, NICK_COL, nick); + char *blank, *m; + int offset; - for (; offset + (m - message) < COLS_MAX; m++) { + blank = NULL; + offset = printf("%*s %*s ", TIME_COL, time, NICK_COL, nick); + for (m = message; offset + (m - message) < COLS_MAX; m++) { if (*m == ' ') blank = m; - if (!*m) + if (*m == '\0') goto tail; } - if (!blank) { - for (; *m != ' '; m++) + if (blank == NULL) { + for (; *m != ' '; m++) { if (m == '\0') goto tail; + } blank = m; } *blank = '\0'; puts(message); - return blank + 1; tail: fputs(message, stdout); + fflush(stdout); return NULL; } @@ -56,36 +58,37 @@ print_message(time_t time, char *nick, int same, char *message) int parse_message(char *str, time_t *time, char **nick, char **message) { - for (*time = atoi(str); *str != ' '; str++) + for (*time = atoi(str); *str != ' '; str++) { if (!*str) - return 0; + return -1; + } *str++ = '\0'; - for (*nick = str; *str != ' '; str++) + for (*nick = str; *str != ' '; str++) { if (!*str) - return 0; + return -1; + } *str = '\0'; *message = str + 1; - return 1; + return 0; } int main(void) { - size_t len = 0; - char *line = NULL; - time_t time = 0; - char *nick = NULL; - char *message = NULL; - char last[NICK_MAX]; + size_t len; + time_t time; + char *nick, *message, *line, last[NICK_MAX]; + len = time = 0; + nick = message = line = NULL; last[0] = '\0'; - while (getline(&line, &len, stdin) != -1) { - if (!parse_message(line, &time, &nick, &message)) + while (getline(&line, &len, stdin) > 0) { + if (parse_message(line, &time, &nick, &message) < 0) continue; - print_message(time, nick, !strcmp(nick, last), message); + print_message(time, nick, strcmp(nick, last) == 0, message); strcpy(last, nick); } free(line);