add nicer formatting to output files

This commit is contained in:
Luna 2019-04-30 02:16:19 -03:00
parent 72127b5059
commit 6d80249659
4 changed files with 22 additions and 4 deletions

View file

@ -4,8 +4,6 @@
void handle_emotion(FILE *journal, char* msg)
{
char formatted[512];
sprintf(formatted, "%s\n", msg);
journal_write(journal, formatted);
journal_write_topic(journal, "emotion", msg);
return;
}

0
src/journal/format.h Normal file
View file

View file

@ -1,8 +1,11 @@
// functions to deal with the journal file
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
// functions to deal with the journal file
FILE *journal_open(char *topic)
{
@ -36,3 +39,19 @@ void journal_close(FILE* journal_fd)
{
fclose(journal_fd);
}
void journal_write_topic(FILE *journal_fd, char *topic, char *message)
{
char *tstamp = malloc(128 * sizeof(char));
char fmt_msg[512];
time_t rawtime;
time(&rawtime);
const struct tm *cur_time = gmtime(&rawtime);
strftime(tstamp, 128, "%c", cur_time);
sprintf(fmt_msg, "[%s] [%s]: %s\n", tstamp, topic, message);
free(tstamp);
journal_write(journal_fd, fmt_msg);
}

View file

@ -5,6 +5,7 @@
FILE *journal_open(char *topic);
void journal_write(FILE*, char* message);
void journal_write_topic(FILE*, char *topic, char *message);
void journal_close(FILE*);
#endif