From c0cfeaa333eff5c05d5c75e5a91329936b69d46d Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 27 Apr 2019 03:49:04 -0300 Subject: [PATCH] add basic emotion topic --- Makefile | 8 ++++---- src/journal/emotion.c | 7 +++++++ src/journal/emotion.h | 6 ++++++ src/journal/main.c | 28 +++++++++++++++++++++++++++- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/journal/emotion.c create mode 100644 src/journal/emotion.h diff --git a/Makefile b/Makefile index 2902d0a..ab0e30e 100644 --- a/Makefile +++ b/Makefile @@ -22,9 +22,11 @@ uninstall: rm $(DESTDIR)$(PREFIX)/bin/journal # currently we only have one journal util, others may come later -journal: src/journal/main.o - $(CC) $(LDFLAGS) -o bin/journal src/journal/main.o $(LDLIBS) +journal: src/journal/main.o src/journal/emotion.o + $(CC) $(LDFLAGS) -o bin/journal \ + src/journal/main.o src/journal/emotion.o $(LDLIBS) +src/journal/emotion.o: src/journal/emotion.c src/journal/main.o: src/journal/main.c clean: @@ -32,6 +34,4 @@ clean: .SUFFIXES: .c .o .c.o: - # $< mean the prereqs - # $@ means the target $(CC) $(CFLAGS) -c $< -o $@ diff --git a/src/journal/emotion.c b/src/journal/emotion.c new file mode 100644 index 0000000..31382c2 --- /dev/null +++ b/src/journal/emotion.c @@ -0,0 +1,7 @@ +#include + +void handle_emotion() +{ + printf("test\n"); + return; +} diff --git a/src/journal/emotion.h b/src/journal/emotion.h new file mode 100644 index 0000000..4f2cf78 --- /dev/null +++ b/src/journal/emotion.h @@ -0,0 +1,6 @@ +#ifndef __EMOTION_H__ +#define __EMOTION_H__ + +void handle_emotion(); + +#endif diff --git a/src/journal/main.c b/src/journal/main.c index d96b7e9..6674c24 100644 --- a/src/journal/main.c +++ b/src/journal/main.c @@ -1,4 +1,9 @@ #include +#include + +#include "emotion.h" + +#define TOPICS 10 int main(int argc, char** argv) { @@ -9,7 +14,28 @@ int main(int argc, char** argv) } char *topic = argv[1]; - printf("%s\n", topic); + printf("load topic %s\n", topic); + + const char* topics[TOPICS] = { + "emotion" + }; + + void (*handlers[])() = { + handle_emotion, + }; + + for(int i = 0; i < TOPICS; i++) + { + const char* cur_topic = topics[i]; + if(strcmp(topic, cur_topic) == 0) + { + void (*fun_ptr)() = handlers[i]; + fun_ptr(); + return 0; + } + } + + printf("topic %s not found\n", topic); return 0; }