diff options
-rw-r--r-- | src/apoint.c | 19 | ||||
-rw-r--r-- | src/calcurse.h | 4 | ||||
-rw-r--r-- | src/event.c | 17 | ||||
-rw-r--r-- | src/recur.c | 58 |
4 files changed, 62 insertions, 36 deletions
diff --git a/src/apoint.c b/src/apoint.c index 57223bc..694c318 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -51,16 +51,21 @@ void apoint_free(struct apoint *apt) mem_free(apt); } -static void apoint_dup(struct apoint *in, struct apoint *bkp) +struct apoint *apoint_dup(struct apoint *in) { - EXIT_IF(!in || !bkp, _("null pointer")); + EXIT_IF(!in, _("null pointer")); - bkp->start = in->start; - bkp->dur = in->dur; - bkp->state = in->state; - bkp->mesg = mem_strdup(in->mesg); + struct apoint *apt = mem_malloc(sizeof(struct apoint)); + apt->start = in->start; + apt->dur = in->dur; + apt->state = in->state; + apt->mesg = mem_strdup(in->mesg); if (in->note) - bkp->note = mem_strdup(in->note); + apt->note = mem_strdup(in->note); + else + apt->note = NULL; + + return apt; } void apoint_llist_init(void) diff --git a/src/calcurse.h b/src/calcurse.h index 714852e..afbf1b0 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -593,6 +593,7 @@ enum save_display { /* apoint.c */ extern llist_ts_t alist_p; void apoint_free_bkp(void); +struct apoint *apoint_dup(struct apoint *); void apoint_free(struct apoint *); void apoint_llist_init(void); void apoint_llist_free(void); @@ -689,6 +690,7 @@ void dmon_stop(void); /* event.c */ extern llist_t eventlist; void event_free_bkp(void); +struct event *event_dup(struct event *); void event_free(struct event *); void event_llist_init(void); void event_llist_free(void); @@ -849,6 +851,8 @@ void pcal_export_data(FILE *); /* recur.c */ extern llist_ts_t recur_alist_p; extern llist_t recur_elist; +struct recur_event *recur_event_dup(struct recur_event *); +struct recur_apoint *recur_apoint_dup(struct recur_apoint *); void recur_event_free_bkp(void); void recur_apoint_free_bkp(void); void recur_event_free(struct recur_event *); diff --git a/src/event.c b/src/event.c index aed504a..de0ce02 100644 --- a/src/event.c +++ b/src/event.c @@ -50,15 +50,20 @@ void event_free(struct event *ev) 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) diff --git a/src/recur.c b/src/recur.c index 23cadee..0a17414 100644 --- a/src/recur.c +++ b/src/recur.c @@ -83,43 +83,55 @@ static void exc_dup(llist_t * in, llist_t * exc) } } -static void recur_event_dup(struct recur_event *in, struct recur_event *bkp) +struct recur_event *recur_event_dup(struct recur_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 recur_event *rev = mem_malloc(sizeof(struct recur_event)); + + rev->id = in->id; + rev->day = in->day; + rev->mesg = mem_strdup(in->mesg); - bkp->rpt = mem_malloc(sizeof(struct rpt)); - bkp->rpt->type = in->rpt->type; - bkp->rpt->freq = in->rpt->freq; - bkp->rpt->until = in->rpt->until; + rev->rpt = mem_malloc(sizeof(struct rpt)); + rev->rpt->type = in->rpt->type; + rev->rpt->freq = in->rpt->freq; + rev->rpt->until = in->rpt->until; - exc_dup(&bkp->exc, &in->exc); + exc_dup(&rev->exc, &in->exc); if (in->note) - bkp->note = mem_strdup(in->note); + rev->note = mem_strdup(in->note); + else + rev->note = NULL; + + return rev; } -static void recur_apoint_dup(struct recur_apoint *in, struct recur_apoint *bkp) +struct recur_apoint *recur_apoint_dup(struct recur_apoint *in) { - EXIT_IF(!in || !bkp, _("null pointer")); + EXIT_IF(!in, _("null pointer")); - bkp->start = in->start; - bkp->dur = in->dur; - bkp->state = in->state; - bkp->mesg = mem_strdup(in->mesg); + struct recur_apoint *rapt = mem_malloc(sizeof(struct recur_apoint)); + + rapt->start = in->start; + rapt->dur = in->dur; + rapt->state = in->state; + rapt->mesg = mem_strdup(in->mesg); - bkp->rpt = mem_malloc(sizeof(struct rpt)); - bkp->rpt->type = in->rpt->type; - bkp->rpt->freq = in->rpt->freq; - bkp->rpt->until = in->rpt->until; + rapt->rpt = mem_malloc(sizeof(struct rpt)); + rapt->rpt->type = in->rpt->type; + rapt->rpt->freq = in->rpt->freq; + rapt->rpt->until = in->rpt->until; - exc_dup(&bkp->exc, &in->exc); + exc_dup(&rapt->exc, &in->exc); if (in->note) - bkp->note = mem_strdup(in->note); + rapt->note = mem_strdup(in->note); + else + rapt->note = NULL; + + return rapt; } void recur_apoint_llist_init(void) |