2 * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /* Merge events and todos */
29 static void add_event(event_t **first, event_t **last, event_t **next)
32 (*last)->next = *next;
36 (*next) = (*next)->next;
39 static void add_todo(todo_t **first, todo_t **last, todo_t **next)
42 (*last)->next = *next;
46 (*next) = (*next)->next;
49 static event_t *merge_events(event_t *a, event_t *b)
51 event_t *first = NULL, *last = NULL;
53 if (compare(&a->start, &b->start) <= 0)
54 add_event(&first, &last, &a);
56 add_event(&first, &last, &b);
57 while (a) add_event(&first, &last, &a);
58 while (b) add_event(&first, &last, &b);
62 static todo_t *merge_todos(todo_t *a, todo_t *b)
64 todo_t *first = NULL, *last = NULL;
66 if (compare(&a->start, &b->start) <= 0)
67 add_todo(&first, &last, &a);
69 add_todo(&first, &last, &b);
70 while (a) add_todo(&first, &last, &a);
71 while (b) add_todo(&first, &last, &b);
78 EVENTS = cal_events(2012, JAN, 0, 366);
79 TODOS = cal_todos(2012, JAN, 0, 366);
82 for (event_t *e = EVENTS; e; e = e->next)
83 debug("event: %04d-%02d-%02d %02d:%02d: %s - %s",
84 e->start.year, e->start.month, e->start.day,
85 e->start.hour, e->start.min, e->name, e->desc);
86 for (todo_t *e = TODOS; e; e = e->next)
87 debug("todo: %04d-%02d-%02d %02d:%02d: %s - %s",
88 e->start.year, e->start.month, e->start.day,
89 e->start.hour, e->start.min, e->name, e->desc);
93 event_t *cal_events(year_t year, month_t month, day_t day, int days)
95 event_t *dummy = dummy_events(0, year, month, day, days);
96 event_t *ical = ical_events(0, year, month, day, days);
97 return merge_events(dummy, ical);
101 todo_t *cal_todos(year_t year, month_t month, day_t day, int days)
103 todo_t *dummy = dummy_todos(0, year, month, day, days);
104 todo_t *ical = ical_todos(0, year, month, day, days);
105 return merge_todos(dummy, ical);