diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-01-11 20:02:37 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-01-13 17:39:44 +0100 |
commit | d118beceee701580948eb3c23fb0677920042422 (patch) | |
tree | a5ec5b1fa5103cc8da0ca906778745f12a144869 /src/apoint.c | |
parent | ab54c861dc857522747264f7494793e1d1589ff2 (diff) | |
download | calcurse-d118beceee701580948eb3c23fb0677920042422.zip |
Implement {apoint,event,todo}_tostr()
Add functions to serialize non-recurrent objects without immediately
writing them to stdout.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/apoint.c')
-rw-r--r-- | src/apoint.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/apoint.c b/src/apoint.c index c169c07..263db9d 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -136,30 +136,42 @@ void apoint_sec2str(struct apoint *o, long day, char *start, char *end) } } -void apoint_write(struct apoint *o, FILE * f) +char *apoint_tostr(struct apoint *o) { + struct string s; struct tm lt; time_t t; + string_init(&s); + t = o->start; localtime_r(&t, <); - fprintf(f, "%02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday, - 1900 + lt.tm_year, lt.tm_hour, lt.tm_min); + string_catf(&s, "%02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, + lt.tm_mday, 1900 + lt.tm_year, lt.tm_hour, lt.tm_min); t = o->start + o->dur; localtime_r(&t, <); - fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ", lt.tm_mon + 1, + string_catf(&s, " -> %02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday, 1900 + lt.tm_year, lt.tm_hour, lt.tm_min); - if (o->note != NULL) - fprintf(f, ">%s ", o->note); + if (o->note) + string_catf(&s, ">%s ", o->note); if (o->state & APOINT_NOTIFY) - fputc('!', f); + string_catf(&s, "%c", '!'); else - fputc('|', f); + string_catf(&s, "%c", '|'); + + string_catf(&s, "%s", o->mesg); - fprintf(f, "%s\n", o->mesg); + return string_buf(&s); +} + +void apoint_write(struct apoint *o, FILE * f) +{ + char *str = apoint_tostr(o); + fprintf(f, "%s\n", str); + mem_free(str); } struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end, |