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/>.
26 event_t *name##_events(cal_t *cal, year_t year, month_t month, day_t day, int days); \
27 todo_t *name##_todos(cal_t *cal, year_t year, month_t month, day_t day, int days)
33 event_t *cal_events(year_t year, month_t month, day_t day, int days);
34 todo_t *cal_todos(year_t year, month_t month, day_t day, int days);
40 /* Merge events and todos */
41 static void add_event(event_t **first, event_t **last, event_t **next)
44 (*last)->next = *next;
48 (*next) = (*next)->next;
51 static void add_todo(todo_t **first, todo_t **last, todo_t **next)
54 (*last)->next = *next;
58 (*next) = (*next)->next;
61 static event_t *merge_events(event_t *a, event_t *b)
63 event_t *first = NULL, *last = NULL;
65 if (compare(&a->start, &b->start) <= 0)
66 add_event(&first, &last, &a);
68 add_event(&first, &last, &b);
69 while (a) add_event(&first, &last, &a);
70 while (b) add_event(&first, &last, &b);
74 static todo_t *merge_todos(todo_t *a, todo_t *b)
76 todo_t *first = NULL, *last = NULL;
78 if (compare(&a->start, &b->start) <= 0)
79 add_todo(&first, &last, &a);
81 add_todo(&first, &last, &b);
82 while (a) add_todo(&first, &last, &a);
83 while (b) add_todo(&first, &last, &b);
90 EVENTS = cal_events(2012, JAN, 0, 366);
91 TODOS = cal_todos(2012, JAN, 0, 366);
94 for (event_t *e = EVENTS; e; e = e->next)
95 debug("event: %04d-%02d-%02d %02d:%02d: %s - %s",
96 e->start.year, e->start.month, e->start.day,
97 e->start.hour, e->start.min, e->name, e->desc);
98 for (todo_t *e = TODOS; e; e = e->next)
99 debug("todo: %04d-%02d-%02d %02d:%02d: %s - %s",
100 e->start.year, e->start.month, e->start.day,
101 e->start.hour, e->start.min, e->name, e->desc);
105 event_t *cal_events(year_t year, month_t month, day_t day, int days)
107 event_t *dummy = dummy_events(0, year, month, day, days);
108 event_t *ical = ical_events(0, year, month, day, days);
109 return merge_events(dummy, ical);
113 todo_t *cal_todos(year_t year, month_t month, day_t day, int days)
115 todo_t *dummy = dummy_todos(0, year, month, day, days);
116 todo_t *ical = ical_todos(0, year, month, day, days);
117 return merge_todos(dummy, ical);