From eaf8f96e065ef30fb78ead5cf1e4007aefd25fbf Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 15 Feb 2016 08:35:21 +0100 Subject: Improve ordering of appointments/events * Order by start time first. * Order items with the same start time by priority. * Order items with the same start and priority by description. Signed-off-by: Lukas Fleischer --- src/event.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/event.c') diff --git a/src/event.c b/src/event.c index d2526dc..ad26f19 100644 --- a/src/event.c +++ b/src/event.c @@ -78,9 +78,14 @@ void event_llist_free(void) LLIST_FREE(&eventlist); } -static int event_cmp_day(struct event *a, struct event *b) +static int event_cmp(struct event *a, struct event *b) { - return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1); + if (a->day < b->day) + return -1; + if (a->day > b->day) + return 1; + + return strcmp(a->mesg, b->mesg); } /* Create a new event */ @@ -94,7 +99,7 @@ struct event *event_new(char *mesg, char *note, long day, int id) ev->id = id; ev->note = (note != NULL) ? mem_strdup(note) : NULL; - LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day); + LLIST_ADD_SORTED(&eventlist, ev, event_cmp); return ev; } @@ -217,5 +222,5 @@ void event_delete(struct event *ev) void event_paste_item(struct event *ev, long date) { ev->day = date; - LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day); + LLIST_ADD_SORTED(&eventlist, ev, event_cmp); } -- cgit v1.2.3