/* Macros */
#define CAL(name) \
+ void name##_config(const char *group, const char *name, const char *key, const char *value); \
+ cal_t *name##_cals(void); \
event_t *name##_events(date_t start, date_t end); \
todo_t *name##_todos(date_t start, date_t end)
CAL(ical);
/* Global data */
+cal_t *CALS;
event_t *EVENTS;
todo_t *TODOS;
(*next) = (*next)->next;
}
+static cal_t *merge_cals(cal_t *a, cal_t *b)
+{
+ // TODO - we should sort these
+ if (!a) return b;
+ if (!b) return a;
+ cal_t *last = a;
+ while (last->next)
+ last = last->next;
+ last->next = b;
+ return a;
+}
+
static event_t *merge_events(event_t *a, event_t *b)
{
event_t *first = NULL, *last = NULL;
/* Initialize */
void cal_init(void)
{
- /* Load a year's worth of data */
- cal_load(YEAR-1, DEC, 31-7, 366+7+7);
+ /* Load calendars */
+ CALS = merge_cals(
+ dummy_cals(),
+ ical_cals());
+
+ /* Load data */
+ cal_load(YEAR, MONTH, DAY, 1);
/* Debug */
for (event_t *e = EVENTS; e; e = e->next)
return;
/* Free uneeded data */
- // TODO
+ for (event_t *next, *cur = EVENTS; cur; cur = next) {
+ next = cur->next;
+ if (cur->name) free(cur->name);
+ if (cur->desc) free(cur->desc);
+ if (cur->loc) free(cur->loc);
+ if (cur->cat) free(cur->cat);
+ free(cur);
+ }
+ for (todo_t *next, *cur = TODOS; cur; cur = next) {
+ next = cur->next;
+ if (cur->name) free(cur->name);
+ if (cur->desc) free(cur->desc);
+ if (cur->cat) free(cur->cat);
+ free(cur);
+ }
/* Push dates out a bit to avoid reloading,
* enough to at least cover the current year */
ical_todos(start, end));
}
+
+/* Config parser */
+void cal_config(const char *group, const char *name, const char *key, const char *value)
+{
+ if (match(group, "dummy"))
+ dummy_config(group, name, key, value);
+ else if (match(group, "ical"))
+ ical_config(group, name, key, value);
+}