diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-15 08:35:21 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-15 18:25:55 +0100 |
commit | eaf8f96e065ef30fb78ead5cf1e4007aefd25fbf (patch) | |
tree | 0d165e8a1ecdb0ec8261cb51a0f2a036a88618f2 /src/event.c | |
parent | 07954626c6925f22e4d59b6d68f0947d4e54b8b9 (diff) | |
download | calcurse-eaf8f96e065ef30fb78ead5cf1e4007aefd25fbf.zip |
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 <lfleischer@calcurse.org>
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 13 |
1 files changed, 9 insertions, 4 deletions
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); } |