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/todo.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/todo.c')
-rw-r--r-- | src/todo.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -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. */ |