1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*;
$Header: /cvs/src/tdl/done.c,v 1.10.2.1 2004/01/07 00:09:05 richard Exp $
tdl - A console program for managing to-do lists
Copyright (C) 2001-2004 Richard P. Curnow
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include "tdl.h"
int has_open_child(struct node *y)/*{{{*/
{
struct node *c;
int result = 0;
for (c = y->kids.next; c != (struct node *) &y->kids; c = c->chain.next) {
if (c->done == 0) {
result = 1;
break;
}
}
return result;
}
/*}}}*/
static void mark_done_from_bottom_up(struct links *x, time_t done_time)/*{{{*/
{
struct node *y;
for (y = x->next; y != (struct node *) x; y = y->chain.next) {
if (has_kids(y)) {
mark_done_from_bottom_up(&y->kids, done_time);
}
if (y->flag) {
if (has_open_child(y)) {
fprintf(stderr, "Cannot mark %s done, it has open sub-tasks\n", y->scratch);
} else {
y->done = done_time;
}
}
}
}
/*}}}*/
static int internal_done(time_t when, char **x)/*{{{*/
{
struct node *n;
int do_descendents;
clear_flags(&top);
while (*x) {
do_descendents = include_descendents(*x); /* May modify *x */
n = lookup_node(*x, 0, NULL);
if (!n) return -1;
n->flag = 1;
if (do_descendents) {
mark_all_descendents(n);
}
n->scratch = *x; /* Safe to alias, *x has long lifetime */
x++;
}
mark_done_from_bottom_up(&top, when);
return 0;
}
/*}}}*/
int process_done(char **x)/*{{{*/
{
time_t done_time = time(NULL);
if (*x && (x[0][0] == '@')) {
int error;
done_time = parse_date(x[0]+1, done_time, 0, &error);
if (error < 0) return error;
x++;
}
internal_done(done_time, x);
return 0;
}
/*}}}*/
int process_ignore(char **x)/*{{{*/
{
/* (struct node).done == 0 means not done yet. So use 1 to mean ancient
* history (never shows up in reports, sure to be purged at next purge) */
internal_done(IGNORED_TIME, x);
return 0;
}
/*}}}*/
static void undo_descendents(struct node *y)/*{{{*/
{
struct node *c;
for (c = y->kids.next; c != (struct node *) &y->kids; c = c->chain.next) {
c->done = 0;
if (has_kids(c)) {
undo_descendents(c);
}
}
}
/*}}}*/
static void undo_ancestors(struct node *y)/*{{{*/
{
struct node *parent;
parent = y->parent;
while (parent) {
parent->done = 0;
parent = parent->parent;
}
}
/*}}}*/
int process_undo(char **x)/*{{{*/
{
struct node *n;
int do_descendents;
while (*x) {
do_descendents = include_descendents(*x); /* May modify *x */
n = lookup_node(*x, 0, NULL);
if (!n) return -1;
n->done = 0;
undo_ancestors(n);
if (do_descendents) {
undo_descendents(n);
}
x++;
}
return 0;
}
/*}}}*/
|