lunabot/src/journal/main.c

49 lines
909 B
C

#include <stdio.h>
#include <string.h>
#include "emotion.h"
#include "journal.h"
#define TOPICS 10
int main(int argc, char** argv)
{
if(argc < 2)
{
printf("usage: %s topic message\n", argv[0]);
return 0;
}
char *topic = argv[1];
printf("load topic %s\n", topic);
const char* topics[TOPICS] = {
"emotion"
};
void (*handlers[])(FILE*, char*) = {
handle_emotion,
};
for(int i = 0; i < TOPICS; i++)
{
const char* cur_topic = topics[i];
if(strcmp(topic, cur_topic) == 0)
{
void (*fun_ptr)(FILE*, char*) = handlers[i];
FILE* journal_file = journal_open(topic);
fun_ptr(journal_file, "hello world");
journal_close(journal_file);
printf("done\n");
return 0;
}
}
printf("topic %s not found\n", topic);
return 0;
}