add nicer formatting to output files
This commit is contained in:
parent
72127b5059
commit
6d80249659
4 changed files with 22 additions and 4 deletions
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
void handle_emotion(FILE *journal, char* msg)
|
void handle_emotion(FILE *journal, char* msg)
|
||||||
{
|
{
|
||||||
char formatted[512];
|
journal_write_topic(journal, "emotion", msg);
|
||||||
sprintf(formatted, "%s\n", msg);
|
|
||||||
journal_write(journal, formatted);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
0
src/journal/format.h
Normal file
0
src/journal/format.h
Normal file
|
@ -1,8 +1,11 @@
|
||||||
// functions to deal with the journal file
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
// functions to deal with the journal file
|
||||||
|
|
||||||
|
|
||||||
FILE *journal_open(char *topic)
|
FILE *journal_open(char *topic)
|
||||||
{
|
{
|
||||||
|
@ -36,3 +39,19 @@ void journal_close(FILE* journal_fd)
|
||||||
{
|
{
|
||||||
fclose(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);
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
FILE *journal_open(char *topic);
|
FILE *journal_open(char *topic);
|
||||||
void journal_write(FILE*, char* message);
|
void journal_write(FILE*, char* message);
|
||||||
|
void journal_write_topic(FILE*, char *topic, char *message);
|
||||||
void journal_close(FILE*);
|
void journal_close(FILE*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue