2 $Header: /cvs/src/tdl/done.c,v 1.10.2.1 2004/01/07 00:09:05 richard Exp $
4 tdl - A console program for managing to-do lists
5 Copyright (C) 2001-2004 Richard P. Curnow
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 int has_open_child(struct node *y)/*{{{*/
28 for (c = y->kids.next; c != (struct node *) &y->kids; c = c->chain.next) {
38 static void mark_done_from_bottom_up(struct links *x, time_t done_time)/*{{{*/
42 for (y = x->next; y != (struct node *) x; y = y->chain.next) {
45 mark_done_from_bottom_up(&y->kids, done_time);
49 if (has_open_child(y)) {
50 fprintf(stderr, "Cannot mark %s done, it has open sub-tasks\n", y->scratch);
58 static int internal_done(time_t when, char **x)/*{{{*/
66 do_descendents = include_descendents(*x); /* May modify *x */
67 n = lookup_node(*x, 0, NULL);
71 mark_all_descendents(n);
73 n->scratch = *x; /* Safe to alias, *x has long lifetime */
77 mark_done_from_bottom_up(&top, when);
82 int process_done(char **x)/*{{{*/
84 time_t done_time = time(NULL);
86 if (*x && (x[0][0] == '@')) {
88 done_time = parse_date(x[0]+1, done_time, 0, &error);
89 if (error < 0) return error;
93 internal_done(done_time, x);
97 int process_ignore(char **x)/*{{{*/
99 /* (struct node).done == 0 means not done yet. So use 1 to mean ancient
100 * history (never shows up in reports, sure to be purged at next purge) */
101 internal_done(IGNORED_TIME, x);
105 static void undo_descendents(struct node *y)/*{{{*/
108 for (c = y->kids.next; c != (struct node *) &y->kids; c = c->chain.next) {
116 static void undo_ancestors(struct node *y)/*{{{*/
122 parent = parent->parent;
126 int process_undo(char **x)/*{{{*/
132 do_descendents = include_descendents(*x); /* May modify *x */
133 n = lookup_node(*x, 0, NULL);
137 if (do_descendents) {