2 $Header: /cvs/src/tdl/purge.c,v 1.6.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
25 static void purge_from_bottom_up(struct links *x)/*{{{*/
28 for (y = x->next; y != (struct node *) x; y = ny) {
30 /* Calculate this now in case y gets deleted later */
34 purge_from_bottom_up(&y->kids);
38 /* If the node still has children, just keep quite and don't delete it.
39 * The idea of the 'purge' command is just a fast bulk delete of all
40 * old stuff under certain tasks, so this is OK */
42 /* Just unlink from the chain for now, don't bother about full clean up. */
43 struct node *next, *prev;
46 prev->chain.next = next;
47 next->chain.prev = prev;
53 static void scan_from_top_down(struct links *x, time_t then)/*{{{*/
56 for (y = x->next; y != (struct node *) x; y = y->chain.next) {
57 if ((y->done > 0) && (y->done < then)) y->flag = 1;
58 scan_from_top_down(&y->kids, then);
63 int process_purge(char **x)/*{{{*/
69 struct node *narrow_top;
70 struct links *to_purge_from;
72 narrow_top = get_narrow_top();
73 to_purge_from = narrow_top ? &narrow_top->kids : ⊤
77 fprintf(stderr, "Usage: purge <interval> <entry_index> ...\n");
84 then = parse_date(d, now, 0, &error);
85 if (error < 0) return error;
88 clear_flags(to_purge_from);
92 /* If no indices given, do whole database */
93 scan_from_top_down(to_purge_from, then);
97 n = lookup_node(*x, 0, NULL);
99 if ((n->done > 0) && (n->done < then)) n->flag = 1;
100 scan_from_top_down(&n->kids, then);
105 purge_from_bottom_up(to_purge_from);