+/* Event functions */
+static event_t *to_event(ical_inst *inst)
+{
+ icalproperty *prop = icalcomponent_get_first_property(inst->comp, ICAL_CATEGORIES_PROPERTY);
+
+ event_t *event = calloc(1, sizeof(event_t));
+ event->name = icalcomponent_get_summary(inst->comp);
+ event->desc = icalcomponent_get_description(inst->comp);
+ event->loc = icalcomponent_get_location(inst->comp);
+ event->cat = icalproperty_get_value_as_string(prop);
+ event->start = to_date(inst->start);
+ event->end = to_date(inst->end);
+ return event;
+}
+
+static event_t *to_events(icalarray *array)
+{
+ event_t list = {};
+ event_t *tail = &list;
+ for (int i = 0; i < array->num_elements; i++) {
+ ical_inst *inst = icalarray_element_at(array, i);
+ tail->next = to_event(inst);
+ tail = tail->next;
+ }
+ return list.next;
+}
+
+static void print_events(event_t *start)
+{
+ for (event_t *cur = start; cur; cur = cur->next)
+ printf("%04d-%02d-%02d %02d:%02d - %s\n",
+ cur->start.year, cur->start.month, cur->start.day,
+ cur->start.hour, cur->start.min,
+ cur->name ?: cur->desc ?: "[no summary]");
+}
+
+/* Todo functions */
+static todo_t *to_todo(ical_inst *inst)
+{
+ icalproperty *cat = icalcomponent_get_first_property(inst->comp, ICAL_CATEGORIES_PROPERTY);
+ icalproperty *perc = icalcomponent_get_first_property(inst->comp, ICAL_PERCENTCOMPLETE_PROPERTY);
+
+ todo_t *todo = calloc(1, sizeof(todo_t));
+ todo->name = icalcomponent_get_summary(inst->comp);
+ todo->desc = icalcomponent_get_description(inst->comp);
+ todo->cat = icalproperty_get_value_as_string(cat);
+ todo->status = icalcomponent_get_status(inst->comp) == ICAL_STATUS_COMPLETED ? 100 :
+ perc ? icalproperty_get_percentcomplete(perc) : 0;
+ todo->start = to_date(inst->start);
+ todo->due = to_date(icalcomponent_get_due(inst->comp));
+ return todo;
+}
+
+static todo_t *to_todos(icalarray *array)
+{
+ todo_t list = {};
+ todo_t *tail = &list;
+ for (int i = 0; i < array->num_elements; i++) {
+ ical_inst *inst = icalarray_element_at(array, i);
+ tail->next = to_todo(inst);
+ tail = tail->next;
+ }
+ return list.next;
+}
+
+static void print_todos(todo_t *start)
+{
+ for (todo_t *cur = start; cur; cur = cur->next)
+ printf("%04d-%02d-%02d %02d:%02d - %d%% - %s\n",
+ cur->due.year, cur->due.month, cur->due.day,
+ cur->due.hour, cur->due.min, cur->status,
+ cur->name ?: cur->desc ?: "[no summary]");
+}
+