Refactor *_dup()
* Actually duplicate an item instead of copying data only. * Properly clone an item without a note. * Mark *_dup() public. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
1c53c9d8c3
commit
a1394e9833
19
src/apoint.c
19
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)
|
||||
|
@ -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 *);
|
||||
|
17
src/event.c
17
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)
|
||||
|
58
src/recur.c
58
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));
|
||||
|
||||
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->id = in->id;
|
||||
rev->day = in->day;
|
||||
rev->mesg = mem_strdup(in->mesg);
|
||||
|
||||
exc_dup(&bkp->exc, &in->exc);
|
||||
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(&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));
|
||||
|
||||
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->start = in->start;
|
||||
rapt->dur = in->dur;
|
||||
rapt->state = in->state;
|
||||
rapt->mesg = mem_strdup(in->mesg);
|
||||
|
||||
exc_dup(&bkp->exc, &in->exc);
|
||||
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(&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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user