+/* Local data */
+static date_t start;
+static date_t end;
+
+/* Merge events and todos */
+static void add_event(event_t **first, event_t **last, event_t **next)
+{
+ if (*last)
+ (*last)->next = *next;
+ else
+ (*first) = *next;
+ (*last) = (*next);
+ (*next) = (*next)->next;
+}
+
+static void add_todo(todo_t **first, todo_t **last, todo_t **next)
+{
+ if (*last)
+ (*last)->next = *next;
+ else
+ (*first) = *next;
+ (*last) = (*next);
+ (*next) = (*next)->next;
+}
+
+static event_t *merge_events(event_t *a, event_t *b)
+{
+ event_t *first = NULL, *last = NULL;
+ while (a && b)
+ if (compare(&a->start, &b->start) <= 0)
+ add_event(&first, &last, &a);
+ else
+ add_event(&first, &last, &b);
+ while (a) add_event(&first, &last, &a);
+ while (b) add_event(&first, &last, &b);
+ return first;
+}
+
+static todo_t *merge_todos(todo_t *a, todo_t *b)
+{
+ todo_t *first = NULL, *last = NULL;
+ while (a && b)
+ if (compare(&a->start, &b->start) <= 0)
+ add_todo(&first, &last, &a);
+ else
+ add_todo(&first, &last, &b);
+ while (a) add_todo(&first, &last, &a);
+ while (b) add_todo(&first, &last, &b);
+ return first;
+}
+