]> Joshua Wise's Git repositories - tdl.git/blob - report.c
Initial import of tdl-1.6-pre1
[tdl.git] / report.c
1 /*
2    $Header: /cvs/src/tdl/report.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 <time.h>
23 #include "tdl.h"
24
25 static int mark_nodes_done_since(struct links *x, time_t start, time_t end)/*{{{*/
26 {
27   int flag_set = 0;
28   struct node *y;
29
30   for (y = x->next; y != (struct node *) x; y = y->chain.next) {
31     if ((y->done >= start) && (y->done <= end)) {
32       y->flag = 1;
33       flag_set = 1;
34     }
35
36     if (has_kids(y)) {
37       if (mark_nodes_done_since(&y->kids, start, end)) {
38         y->flag = 1;
39         flag_set = 1;
40       }
41     }
42   }
43   return flag_set;
44 }
45 /*}}}*/
46 static void print_report(struct links *x, int indent)/*{{{*/
47 {
48   struct node *y;
49   char *p;
50
51   for (y = x->next; y != (struct node *) x; y = y->chain.next) {
52     if (y->flag) {
53       do_bullet_indent(indent+2);
54       if (!y->done) printf ("[[");
55       for (p = y->text; *p; p++) {
56         putchar(*p);
57         if (*p == '\n') {
58           do_indent(indent + 2);
59         }
60       }
61       if (!y->done) printf ("]]");
62       putchar('\n');
63
64       if (has_kids(y)) {
65         print_report(&y->kids, indent + 3);
66       }
67     }
68   }
69 }
70 /*}}}*/
71 int process_report(char **x)/*{{{*/
72 {
73   time_t now, start, end;
74   int argc;
75   char *d0, *d1;
76   int error;
77
78   argc = count_args(x);
79   start = end = now = time(NULL);
80
81   switch (argc) {
82     case 1:
83       d0 = x[0];
84       if (*d0 == '@') d0++;
85       start = parse_date(d0, now, 0, &error);
86       if (error < 0) return error;
87       break;
88     case 2:
89       d0 = x[0];
90       d1 = x[1];
91       if (*d0 == '@') d0++;
92       if (*d1 == '@') d1++;
93       start = parse_date(d0, now, 0, &error);
94       if (error < 0) return error;
95       end = parse_date(d1, now, 0, &error);
96       if (error < 0) return error;
97       break;
98     default:
99       fprintf(stderr, "Usage: report <start_epoch> [<end_epoch>]\n");
100       break;
101   }
102
103   clear_flags(&top);
104   mark_nodes_done_since(&top, start, end);
105   print_report(&top, 0);
106   return 0;
107 }
108 /*}}}*/
This page took 0.028059 seconds and 4 git commands to generate.