lunabot/src/journal/main.c

49 lines
909 B
C
Raw Normal View History

2019-04-27 05:37:22 +00:00
#include <stdio.h>
2019-04-27 06:49:04 +00:00
#include <string.h>
#include "emotion.h"
2019-04-29 03:42:44 +00:00
#include "journal.h"
2019-04-27 06:49:04 +00:00
#define TOPICS 10
2019-04-27 05:37:22 +00:00
int main(int argc, char** argv)
{
if(argc < 2)
{
printf("usage: %s topic message\n", argv[0]);
return 0;
}
char *topic = argv[1];
2019-04-27 06:49:04 +00:00
printf("load topic %s\n", topic);
const char* topics[TOPICS] = {
"emotion"
};
2019-04-29 03:42:44 +00:00
void (*handlers[])(FILE*, char*) = {
2019-04-27 06:49:04 +00:00
handle_emotion,
};
for(int i = 0; i < TOPICS; i++)
{
const char* cur_topic = topics[i];
2019-04-29 03:42:44 +00:00
2019-04-27 06:49:04 +00:00
if(strcmp(topic, cur_topic) == 0)
{
2019-04-29 03:42:44 +00:00
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");
2019-04-27 06:49:04 +00:00
return 0;
}
}
printf("topic %s not found\n", topic);
2019-04-27 05:37:22 +00:00
return 0;
}