]> Pileus Git - lackey/commitdiff
Make events and todos doubly linked
authorAndy Spencer <andy753421@gmail.com>
Sun, 16 Jun 2013 21:07:46 +0000 (21:07 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 16 Jun 2013 21:07:48 +0000 (21:07 +0000)
src/cal.c
src/cal.h

index 565432c0571b78bceaa20cf40f938861ee60c515..ee574b7b38e76d4d6c0d9bd0a15aa09b9aa51432 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;
 }
@@ -173,12 +175,20 @@ void cal_load(year_t year, month_t month, day_t day, int days)
 
        /* Verify events and todos*/
 #ifdef DEBUG_CALS
-       for (event_t *cur = EVENTS; cur; cur = cur->next)
+       for (event_t *cur = EVENTS; cur; cur = cur->next) {
                if (!cur->cal)
                        error("Missing cal in event '%s'", cur->name);
-       for (todo_t *cur = TODOS; cur; cur = cur->next)
+               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
 }
 
index 37412211115d0c072e675b25014ad39b05a70d01..72bcd955db4825844db259cda32196608f9bb8a6 100644 (file)
--- a/src/cal.h
+++ b/src/cal.h
@@ -39,6 +39,7 @@ typedef struct event_t {
        date_t          end;
        const cal_t    *cal;
        struct event_t *next;
+       struct event_t *prev;
 } event_t;
 
 typedef struct todo_t {
@@ -50,6 +51,7 @@ typedef struct todo_t {
        date_t         due;
        cal_t         *cal;
        struct todo_t *next;
+       struct todo_t *prev;
 } todo_t;
 
 /* Global data */