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>
This commit is contained in:
Lukas Fleischer
2016-01-11 20:02:37 +01:00
parent ab54c861dc
commit d118beceee
4 changed files with 55 additions and 19 deletions

View File

@@ -79,13 +79,23 @@ struct todo *todo_add(char *mesg, int id, char *note)
return todo;
}
char *todo_tostr(struct todo *todo)
{
char *res;
if (todo->note)
asprintf(&res, "[%d]>%s %s", todo->id, todo->note, todo->mesg);
else
asprintf(&res, "[%d] %s", todo->id, todo->mesg);
return res;
}
void todo_write(struct todo *todo, FILE * f)
{
if (todo->note)
fprintf(f, "[%d]>%s %s\n", todo->id, todo->note,
todo->mesg);
else
fprintf(f, "[%d] %s\n", todo->id, todo->mesg);
char *str = todo_tostr(todo);
fprintf(f, "%s\n", str);
mem_free(str);
}
/* Delete a note previously attached to a todo item. */