]> Pileus Git - lackey/blobdiff - src/cal.c
Convert YEAR/MONTH/DAY to Selection struct
[lackey] / src / cal.c
index 9e36a29db23f80675012fa1d2d2208a1ca9bf48a..b519d588fb4601d6a33470c2b60997e9bee51591 100644 (file)
--- a/src/cal.c
+++ b/src/cal.c
@@ -48,6 +48,7 @@ static void add_event(event_t **first, event_t **last, event_t **next)
                (*last)->next = *next;
        else
                (*first) = *next;
+       (*next)->prev = *last;
        (*last) = (*next);
        (*next) = (*next)->next;
 }
@@ -58,6 +59,7 @@ static void add_todo(todo_t **first, todo_t **last, todo_t **next)
                (*last)->next = *next;
        else
                (*first) = *next;
+       (*next)->prev = *last;
        (*last) = (*next);
        (*next) = (*next)->next;
 }
@@ -109,9 +111,10 @@ void cal_init(void)
                 ical_cals());
 
        /* Load data */
-       cal_load(YEAR, MONTH, DAY, 1);
+       cal_load(SEL.year, SEL.month, SEL.day, 1);
 
        /* Debug */
+#ifdef DEBUG_CALS
        for (event_t *e = EVENTS; e; e = e->next)
                debug("event: %04d-%02d-%02d %02d:%02d: %s - %s",
                                e->start.year, e->start.month, e->start.day,
@@ -120,6 +123,7 @@ void cal_init(void)
                debug("todo: %04d-%02d-%02d %02d:%02d: %s - %s",
                                e->start.year, e->start.month, e->start.day,
                                e->start.hour, e->start.min, e->name, e->desc);
+#endif
 }
 
 /* Load events and todos */
@@ -131,8 +135,8 @@ void cal_load(year_t year, month_t month, day_t day, int days)
        add_days(&eyear, &emonth, &eday, days);
 
        /* Skip if we already loaded enough info */
-       if (!before(&start, year,  month,  day,  0, 0) &&
-            before(&end,  eyear, emonth, eday, 24, 0))
+       if (before(&start, year,  month,  day,  0, 0) &&
+          !before(&end,  eyear, emonth, eday, 24, 0))
                return;
 
        /* Free uneeded data */
@@ -169,6 +173,23 @@ void cal_load(year_t year, month_t month, day_t day, int days)
                dummy_todos(start, end),
                 ical_todos(start, end));
 
+       /* Verify events and todos*/
+#ifdef DEBUG_CALS
+       for (event_t *cur = EVENTS; cur; cur = cur->next) {
+               if (!cur->cal)
+                       error("Missing cal in event '%s'", cur->name);
+               if ((cur->next && cur->next->prev != cur) ||
+                   (cur->prev && cur->prev->next != cur))
+                       error("Broken link in event '%s'", cur->name);
+       }
+       for (todo_t *cur = TODOS; cur; cur = cur->next) {
+               if (!cur->cal)
+                       error("Missing cal in todo '%s'", cur->name);
+               if ((cur->next && cur->next->prev != cur) ||
+                   (cur->prev && cur->prev->next != cur))
+                       error("Broken link in todo '%s'", cur->name);
+       }
+#endif
 }
 
 /* Config parser */