aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-01-17 22:46:24 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-01-18 18:08:34 +0100
commitbeea88e5feb6f14b4912c6aa4878c39a7632977c (patch)
tree6559c7090a687a4b96319b9bc1539050f913f27a /src/io.c
parent1a4bf2b0a2a54393c401522611f85c2637d1de88 (diff)
downloadcalcurse-beea88e5feb6f14b4912c6aa4878c39a7632977c.tar.gz
calcurse-beea88e5feb6f14b4912c6aa4878c39a7632977c.zip
Use a separate field for the completed status
Add a new field that indicates whether a todo item is completed or not instead of encoding completed todo items by negative priorities. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/io.c b/src/io.c
index b0eca77..4ff16cd 100644
--- a/src/io.c
+++ b/src/io.c
@@ -630,7 +630,7 @@ void io_load_todo(struct item_filter *filter)
FILE *data_file;
char *newline;
int nb_tod = 0;
- int c, id;
+ int c, id, completed;
char buf[BUFSIZ], e_todo[BUFSIZ], note[MAX_NOTESIZ + 1];
unsigned line = 0;
@@ -642,7 +642,15 @@ void io_load_todo(struct item_filter *filter)
c = getc(data_file);
if (c == EOF) {
break;
- } else if (c == '[') { /* new style with id */
+ } else if (c == '[') {
+ /* new style with id */
+ c = getc(data_file);
+ if (c == '-') {
+ completed = 1;
+ } else {
+ completed = 0;
+ ungetc(c, data_file);
+ }
if (fscanf(data_file, " %d ", &id) != 1
|| getc(data_file) != ']')
io_load_error(path_todo, line,
@@ -651,6 +659,7 @@ void io_load_todo(struct item_filter *filter)
ungetc(c, data_file);
} else {
id = 9;
+ completed = 0;
ungetc(c, data_file);
}
/* Now read the attached note, if any. */
@@ -678,13 +687,13 @@ void io_load_todo(struct item_filter *filter)
continue;
if (filter->priority && id != filter->priority)
continue;
- if (filter->completed && id > 0)
+ if (filter->completed && !completed)
continue;
- if (filter->uncompleted && id < 0)
+ if (filter->uncompleted && completed)
continue;
}
- struct todo *todo = todo_add(e_todo, id, note);
+ struct todo *todo = todo_add(e_todo, id, completed, note);
/* Filter by hash. */
if (filter && filter->hash) {