eel

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

commit 80cc205a8fe5107ef2ea40395e7b14a089313e98
parent 2d4886127ba82aa4e934b28098c8ddfb3dd60b48
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  8 Oct 2017 18:18:45 +0200

parsing message

Diffstat:
MMakefile | 5+++--
Meel.c | 39+++++++++++++++++++++++++++++++++++----
2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,8 @@ -CFLAGS = -g -pedantic -Wall -Wextra -std=c89 -D_POSIX_C_SOURCE=200809L +CFLAGS = -g -Wpedantic -Wall -Wextra -std=c89 -D_POSIX_C_SOURCE=200809L +CC = clang eel: eel.c - cc ${CFLAGS} eel.c -o eel + ${CC} ${CFLAGS} eel.c -o eel clean: rm eel diff --git a/eel.c b/eel.c @@ -1,13 +1,44 @@ #include <stdio.h> +#include <stdlib.h> +#include <time.h> int -main(int argc, char *argv[]) +parse_message(char *line, time_t *time, char **nick, char **message) { - char *line; - size_t len; + *time = atoi(line); + + while (*line && *line != ' ') + line++; + if (!*line) + return 0; + *line++ = '\0'; + + *nick = line; + + while (*line && *line != ' ') + line++; + if (!*line) + return 0; + *line = '\0'; + + *message = line; + + return 1; +} + +int +main(void) +{ + size_t len = 0; + char *line = NULL; + time_t time = 0; + char *nick = NULL; + char *last = NULL; + char *message = NULL; while (getline(&line, &len, stdin) != -1) - fputs(line, stdout); + parse_message(line, &time, &nick, &message); + free(line); return 0; }