From 3d202351108e537539e8579f62dccd46760c1265 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 16 Jun 2013 21:07:46 +0000 Subject: [PATCH] Make events and todos doubly linked --- src/cal.c | 14 ++++++++++++-- src/cal.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cal.c b/src/cal.c index 565432c..ee574b7 100644 --- 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 } diff --git a/src/cal.h b/src/cal.h index 3741221..72bcd95 100644 --- 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 */ -- 2.43.2