From d118beceee701580948eb3c23fb0677920042422 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 11 Jan 2016 20:02:37 +0100 Subject: Implement {apoint,event,todo}_tostr() Add functions to serialize non-recurrent objects without immediately writing them to stdout. Signed-off-by: Lukas Fleischer --- src/todo.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/todo.c') diff --git a/src/todo.c b/src/todo.c index 95e591a..152fbaa 100644 --- a/src/todo.c +++ b/src/todo.c @@ -79,13 +79,23 @@ struct todo *todo_add(char *mesg, int id, char *note) return todo; } -void todo_write(struct todo *todo, FILE * f) +char *todo_tostr(struct todo *todo) { + char *res; + if (todo->note) - fprintf(f, "[%d]>%s %s\n", todo->id, todo->note, - todo->mesg); + asprintf(&res, "[%d]>%s %s", todo->id, todo->note, todo->mesg); else - fprintf(f, "[%d] %s\n", todo->id, todo->mesg); + asprintf(&res, "[%d] %s", todo->id, todo->mesg); + + return res; +} + +void todo_write(struct todo *todo, FILE * f) +{ + char *str = todo_tostr(todo); + fprintf(f, "%s\n", str); + mem_free(str); } /* Delete a note previously attached to a todo item. */ -- cgit v1.2.3-54-g00ecf