-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.c
108 lines (95 loc) · 2.68 KB
/
report.c
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
/*
$Header: /cvs/src/tdl/report.c,v 1.5.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 <time.h>
#include "tdl.h"
static int mark_nodes_done_since(struct links *x, time_t start, time_t end)/*{{{*/
{
int flag_set = 0;
struct node *y;
for (y = x->next; y != (struct node *) x; y = y->chain.next) {
if ((y->done >= start) && (y->done <= end)) {
y->flag = 1;
flag_set = 1;
}
if (has_kids(y)) {
if (mark_nodes_done_since(&y->kids, start, end)) {
y->flag = 1;
flag_set = 1;
}
}
}
return flag_set;
}
/*}}}*/
static void print_report(struct links *x, int indent)/*{{{*/
{
struct node *y;
char *p;
for (y = x->next; y != (struct node *) x; y = y->chain.next) {
if (y->flag) {
do_bullet_indent(indent+2);
if (!y->done) printf ("[[");
for (p = y->text; *p; p++) {
putchar(*p);
if (*p == '\n') {
do_indent(indent + 2);
}
}
if (!y->done) printf ("]]");
putchar('\n');
if (has_kids(y)) {
print_report(&y->kids, indent + 3);
}
}
}
}
/*}}}*/
int process_report(char **x)/*{{{*/
{
time_t now, start, end;
int argc;
char *d0, *d1;
int error;
argc = count_args(x);
start = end = now = time(NULL);
switch (argc) {
case 1:
d0 = x[0];
if (*d0 == '@') d0++;
start = parse_date(d0, now, 0, &error);
if (error < 0) return error;
break;
case 2:
d0 = x[0];
d1 = x[1];
if (*d0 == '@') d0++;
if (*d1 == '@') d1++;
start = parse_date(d0, now, 0, &error);
if (error < 0) return error;
end = parse_date(d1, now, 0, &error);
if (error < 0) return error;
break;
default:
fprintf(stderr, "Usage: report <start_epoch> [<end_epoch>]\n");
break;
}
clear_flags(&top);
mark_nodes_done_since(&top, start, end);
print_report(&top, 0);
return 0;
}
/*}}}*/