aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-01-11 20:02:37 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-01-13 17:39:44 +0100
commitd118beceee701580948eb3c23fb0677920042422 (patch)
treea5ec5b1fa5103cc8da0ca906778745f12a144869 /src/event.c
parentab54c861dc857522747264f7494793e1d1589ff2 (diff)
downloadcalcurse-d118beceee701580948eb3c23fb0677920042422.tar.gz
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/event.c')
-rw-r--r--src/event.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/event.c b/src/event.c
index 3918ce3..39224a3 100644
--- a/src/event.c
+++ b/src/event.c
@@ -104,19 +104,30 @@ unsigned event_inday(struct event *i, long *start)
return (i->day < *start + DAYINSEC && i->day >= *start);
}
-/* Write to file the event in user-friendly format */
-void event_write(struct event *o, FILE * f)
+char *event_tostr(struct event *o)
{
+ struct string s;
struct tm lt;
time_t t;
+ string_init(&s);
+
t = o->day;
localtime_r(&t, &lt);
- fprintf(f, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday,
+ string_catf(&s, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday,
1900 + lt.tm_year, o->id);
if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- fprintf(f, "%s\n", o->mesg);
+ string_catf(&s, ">%s ", o->note);
+ string_catf(&s, "%s", o->mesg);
+
+ return string_buf(&s);
+}
+
+void event_write(struct event *o, FILE * f)
+{
+ char *str = event_tostr(o);
+ fprintf(f, "%s\n", str);
+ mem_free(str);
}
/* Load the events from file */