diff --git a/Makefile b/Makefile index e496076..40cede1 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,7 @@ LDLIBS= PREFIX=/usr/local SRC = src/journal/main.o \ - src/journal/journal.o \ - src/journal/emotion.o + src/journal/journal.o all: ensure_bin journal @@ -30,7 +29,6 @@ journal: $(SRC) $(CC) $(LDFLAGS) -o bin/journal $(SRC) $(LDLIBS) src/journal/journal.o: src/journal/journal.c -src/journal/emotion.o: src/journal/emotion.c src/journal/main.o: src/journal/main.c clean: diff --git a/src/journal/emotion.c b/src/journal/emotion.c deleted file mode 100644 index a8c8d50..0000000 --- a/src/journal/emotion.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include "journal.h" - -void handle_emotion(FILE *journal, char* msg) -{ - journal_write_topic(journal, "emotion", msg); - return; -} diff --git a/src/journal/emotion.h b/src/journal/emotion.h deleted file mode 100644 index b9b6393..0000000 --- a/src/journal/emotion.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __EMOTION_H__ -#define __EMOTION_H__ - -#include - -void handle_emotion(FILE*, char*); - -#endif diff --git a/src/journal/main.c b/src/journal/main.c index 640dcfa..d5ad915 100644 --- a/src/journal/main.c +++ b/src/journal/main.c @@ -2,7 +2,6 @@ #include #include -#include "emotion.h" #include "journal.h" #define TOPICS 10 @@ -60,16 +59,19 @@ int main(int argc, char** argv) "emotion" }; + // default handling by journal_write_topic is marked + // as the NULL values in this array. void (*handlers[])(FILE*, char*) = { - handle_emotion, + NULL, }; + // list all topics when arg1 is list if(strcmp(topic, "list") == 0) { - // list all topics for(int i = 0; topics[i] != NULL; i++) printf("%s ", topics[i]); printf("\n"); + return 0; } @@ -84,15 +86,18 @@ int main(int argc, char** argv) FILE* journal_file = journal_open(topic); char *handler_message = extract_handler_msg(argc, argv); - printf("'%s'\n", handler_message); + printf("[%s] said '%s'\n", topic, handler_message); + + if(fun_ptr == NULL) { + journal_write_topic(journal_file, topic, handler_message); + } else { + fun_ptr(journal_file, handler_message); + } - // the joined args[2] and beyond come as the - // second argument - fun_ptr(journal_file, handler_message); journal_close(journal_file); - free(handler_message); - printf("done\n"); + + printf("done!\n"); return 0; } }