diff options
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 75 |
1 files changed, 21 insertions, 54 deletions
diff --git a/src/event.c b/src/event.c index 203af44..dca6820 100644 --- a/src/event.c +++ b/src/event.c @@ -42,33 +42,28 @@ #include "calcurse.h" llist_t eventlist; -static struct event bkp_cut_event; -void event_free_bkp(void) -{ - if (bkp_cut_event.mesg) { - mem_free(bkp_cut_event.mesg); - bkp_cut_event.mesg = 0; - } - erase_note(&bkp_cut_event.note); -} - -static void event_free(struct event *ev) +void event_free(struct event *ev) { mem_free(ev->mesg); erase_note(&ev->note); mem_free(ev); } -static void event_dup(struct event *in, struct event *bkp) +struct event *event_dup(struct event *in) { - EXIT_IF(!in || !bkp, _("null pointer")); + EXIT_IF(!in, _("null pointer")); - bkp->id = in->id; - bkp->day = in->day; - bkp->mesg = mem_strdup(in->mesg); + struct event *ev = mem_malloc(sizeof(struct event)); + ev->id = in->id; + ev->day = in->day; + ev->mesg = mem_strdup(in->mesg); if (in->note) - bkp->note = mem_strdup(in->note); + ev->note = mem_strdup(in->note); + else + ev->note = NULL; + + return ev; } void event_llist_init(void) @@ -104,9 +99,9 @@ struct event *event_new(char *mesg, char *note, long day, int id) } /* Check if the event belongs to the selected day */ -unsigned event_inday(struct event *i, long start) +unsigned event_inday(struct event *i, long *start) { - return (i->day < start + DAYINSEC && i->day >= start); + return (i->day < *start + DAYINSEC && i->day >= *start); } /* Write to file the event in user-friendly format */ @@ -151,47 +146,19 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note) return event_new(buf, note, tstart, id); } -/* Retrieve an event from the list, given the day and item position. */ -struct event *event_get(long day, int pos) -{ - llist_item_t *i = LLIST_FIND_NTH(&eventlist, pos, day, event_inday); - - if (i) - return LLIST_TS_GET_DATA(i); - - EXIT(_("event not found")); - /* NOTREACHED */ -} - /* Delete an event from the list. */ -void event_delete_bynum(long start, unsigned num, enum eraseflg flag) +void event_delete(struct event *ev) { - llist_item_t *i = LLIST_FIND_NTH(&eventlist, num, start, event_inday); + llist_item_t *i = LLIST_FIND_FIRST(&eventlist, ev, NULL); if (!i) EXIT(_("no such appointment")); - struct event *ev = LLIST_TS_GET_DATA(i); - - switch (flag) { - case ERASE_FORCE_ONLY_NOTE: - erase_note(&ev->note); - break; - case ERASE_CUT: - event_free_bkp(); - event_dup(ev, &bkp_cut_event); - erase_note(&ev->note); - /* FALLTHROUGH */ - default: - LLIST_REMOVE(&eventlist, i); - mem_free(ev->mesg); - mem_free(ev); - break; - } + + LLIST_REMOVE(&eventlist, i); } -void event_paste_item(void) +void event_paste_item(struct event *ev, long date) { - event_new(bkp_cut_event.mesg, bkp_cut_event.note, - date2sec(*calendar_get_slctd_day(), 0, 0), bkp_cut_event.id); - event_free_bkp(); + ev->day = date; + LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day); } |