]> Joshua Wise's Git repositories - tdl.git/blame - remove.c
Fix such that dashed args are allowed for things like 'tdll'.
[tdl.git] / remove.c
CommitLineData
7024e37b
JW
1/*
2 $Header: /cvs/src/tdl/remove.c,v 1.5.2.1 2004/01/07 00:09:05 richard Exp $
3
4 tdl - A console program for managing to-do lists
5 Copyright (C) 2001-2004 Richard P. Curnow
6
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.
11
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.
16
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
20 */
21
22#include <string.h>
23#include "tdl.h"
24
25static void delete_from_bottom_up(struct links *x)/*{{{*/
26{
27 struct node *y, *ny;
28 for (y = x->next; y != (struct node *) x; y = ny) {
29
30 /* Calculate this now in case y gets deleted later */
31 ny = y->chain.next;
32
33 if (has_kids(y)) {
34 delete_from_bottom_up(&y->kids);
35 }
36
37 if (y->flag) {
38 if (has_kids(y)) {
39 fprintf(stderr, "Cannot delete %s, it has sub-tasks\n", y->scratch);
40 } else {
41 /* Just unlink from the chain for now, don't bother about full clean up. */
42 struct node *next, *prev;
43 next = y->chain.next;
44 prev = y->chain.prev;
45 prev->chain.next = next;
46 next->chain.prev = prev;
47 free(y->text);
48 free(y);
49 }
50 }
51 }
52}
53/*}}}*/
54int process_remove(char **x)/*{{{*/
55{
56 struct node *n;
57 int do_descendents;
58
59 clear_flags(&top);
60
61 while (*x) {
62 do_descendents = include_descendents(*x); /* May modify *x */
63 n = lookup_node(*x, 0, NULL);
64 if (!n) return -1;
65 n->flag = 1;
66 if (do_descendents) {
67 mark_all_descendents(n);
68 }
69 n->scratch = *x; /* *x has long lifetime => OK to alias */
70 ++x;
71 }
72
73 delete_from_bottom_up(&top);
74
75 return 0;
76}
77/*}}}*/
This page took 0.028016 seconds and 4 git commands to generate.