Refactor edit of exception days
The patch contains no functional changes, but is a necessary precondition for extensions of update_rept() (in ui-day.c) with further recurrence rules. The reason is that recurrence parameters must be treated as a whole: if an edit session is cancelled at any point, no value should change, and all parameters should remain as they were. Hence, the new values must only be set after all of them have been determined. This was not the case for the list of exception days, but as long as it was treated last, it did not matter. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
bf3dba2ae2
commit
23eb51456a
@ -1033,7 +1033,9 @@ void pcal_export_data(FILE *);
|
|||||||
/* recur.c */
|
/* recur.c */
|
||||||
extern llist_ts_t recur_alist_p;
|
extern llist_ts_t recur_alist_p;
|
||||||
extern llist_t recur_elist;
|
extern llist_t recur_elist;
|
||||||
int recur_update_exc(llist_t *, char *);
|
void recur_free_exc_list(llist_t *);
|
||||||
|
void recur_exc_dup(llist_t *, llist_t *);
|
||||||
|
int recur_str2exc(llist_t *, char *);
|
||||||
char *recur_exc2str(llist_t *);
|
char *recur_exc2str(llist_t *);
|
||||||
struct recur_event *recur_event_dup(struct recur_event *);
|
struct recur_event *recur_event_dup(struct recur_event *);
|
||||||
struct recur_apoint *recur_apoint_dup(struct recur_apoint *);
|
struct recur_apoint *recur_apoint_dup(struct recur_apoint *);
|
||||||
|
30
src/recur.c
30
src/recur.c
@ -51,7 +51,7 @@ static void free_exc(struct excp *exc)
|
|||||||
mem_free(exc);
|
mem_free(exc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_exc_list(llist_t * exc)
|
void recur_free_exc_list(llist_t * exc)
|
||||||
{
|
{
|
||||||
LLIST_FREE_INNER(exc, free_exc);
|
LLIST_FREE_INNER(exc, free_exc);
|
||||||
LLIST_FREE(exc);
|
LLIST_FREE(exc);
|
||||||
@ -70,7 +70,7 @@ static void recur_add_exc(llist_t * exc, time_t day)
|
|||||||
LLIST_ADD_SORTED(exc, o, exc_cmp_day);
|
LLIST_ADD_SORTED(exc, o, exc_cmp_day);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exc_dup(llist_t * in, llist_t * exc)
|
void recur_exc_dup(llist_t * in, llist_t * exc)
|
||||||
{
|
{
|
||||||
llist_item_t *i;
|
llist_item_t *i;
|
||||||
|
|
||||||
@ -103,10 +103,10 @@ char *recur_exc2str(llist_t *exc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the list of exceptions from a string of days. Any positive number of
|
* Update a list of exceptions from a string of days. Any positive number of
|
||||||
* spaces are allowed before, between and after the days.
|
* spaces are allowed before, between and after the days.
|
||||||
*/
|
*/
|
||||||
int recur_update_exc(llist_t *exc, char *days)
|
int recur_str2exc(llist_t *exc, char *days)
|
||||||
{
|
{
|
||||||
int updated = 0;
|
int updated = 0;
|
||||||
char *d;
|
char *d;
|
||||||
@ -130,11 +130,11 @@ int recur_update_exc(llist_t *exc, char *days)
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free_exc_list(exc);
|
recur_free_exc_list(exc);
|
||||||
exc_dup(exc, &nexc);
|
recur_exc_dup(exc, &nexc);
|
||||||
updated = 1;
|
updated = 1;
|
||||||
cleanup:
|
cleanup:
|
||||||
free_exc_list(&nexc);
|
recur_free_exc_list(&nexc);
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ struct recur_event *recur_event_dup(struct recur_event *in)
|
|||||||
rev->rpt->freq = in->rpt->freq;
|
rev->rpt->freq = in->rpt->freq;
|
||||||
rev->rpt->until = in->rpt->until;
|
rev->rpt->until = in->rpt->until;
|
||||||
|
|
||||||
exc_dup(&rev->exc, &in->exc);
|
recur_exc_dup(&rev->exc, &in->exc);
|
||||||
|
|
||||||
if (in->note)
|
if (in->note)
|
||||||
rev->note = mem_strdup(in->note);
|
rev->note = mem_strdup(in->note);
|
||||||
@ -180,7 +180,7 @@ struct recur_apoint *recur_apoint_dup(struct recur_apoint *in)
|
|||||||
rapt->rpt->freq = in->rpt->freq;
|
rapt->rpt->freq = in->rpt->freq;
|
||||||
rapt->rpt->until = in->rpt->until;
|
rapt->rpt->until = in->rpt->until;
|
||||||
|
|
||||||
exc_dup(&rapt->exc, &in->exc);
|
recur_exc_dup(&rapt->exc, &in->exc);
|
||||||
|
|
||||||
if (in->note)
|
if (in->note)
|
||||||
rapt->note = mem_strdup(in->note);
|
rapt->note = mem_strdup(in->note);
|
||||||
@ -207,7 +207,7 @@ void recur_apoint_free(struct recur_apoint *rapt)
|
|||||||
mem_free(rapt->note);
|
mem_free(rapt->note);
|
||||||
if (rapt->rpt)
|
if (rapt->rpt)
|
||||||
mem_free(rapt->rpt);
|
mem_free(rapt->rpt);
|
||||||
free_exc_list(&rapt->exc);
|
recur_free_exc_list(&rapt->exc);
|
||||||
mem_free(rapt);
|
mem_free(rapt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ void recur_event_free(struct recur_event *rev)
|
|||||||
mem_free(rev->note);
|
mem_free(rev->note);
|
||||||
if (rev->rpt)
|
if (rev->rpt)
|
||||||
mem_free(rev->rpt);
|
mem_free(rev->rpt);
|
||||||
free_exc_list(&rev->exc);
|
recur_free_exc_list(&rev->exc);
|
||||||
mem_free(rev);
|
mem_free(rev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,8 +277,8 @@ struct recur_apoint *recur_apoint_new(char *mesg, char *note, time_t start,
|
|||||||
* Note. The exception dates are in the list rapt->exc.
|
* Note. The exception dates are in the list rapt->exc.
|
||||||
* The (empty) list rapt->rpt->exc is not used.
|
* The (empty) list rapt->rpt->exc is not used.
|
||||||
*/
|
*/
|
||||||
exc_dup(&rapt->exc, &rpt->exc);
|
recur_exc_dup(&rapt->exc, &rpt->exc);
|
||||||
free_exc_list(&rpt->exc);
|
recur_free_exc_list(&rpt->exc);
|
||||||
LLIST_INIT(&rapt->rpt->exc);
|
LLIST_INIT(&rapt->rpt->exc);
|
||||||
|
|
||||||
LLIST_TS_LOCK(&recur_alist_p);
|
LLIST_TS_LOCK(&recur_alist_p);
|
||||||
@ -301,8 +301,8 @@ struct recur_event *recur_event_new(char *mesg, char *note, time_t day,
|
|||||||
rev->rpt = mem_malloc(sizeof(struct rpt));
|
rev->rpt = mem_malloc(sizeof(struct rpt));
|
||||||
*rev->rpt = *rpt;
|
*rev->rpt = *rpt;
|
||||||
/* Similarly as for recurrent appointment. */
|
/* Similarly as for recurrent appointment. */
|
||||||
exc_dup(&rev->exc, &rpt->exc);
|
recur_exc_dup(&rev->exc, &rpt->exc);
|
||||||
free_exc_list(&rpt->exc);
|
recur_free_exc_list(&rpt->exc);
|
||||||
LLIST_INIT(&rev->rpt->exc);
|
LLIST_INIT(&rev->rpt->exc);
|
||||||
|
|
||||||
LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp);
|
LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp);
|
||||||
|
24
src/ui-day.c
24
src/ui-day.c
@ -273,8 +273,8 @@ static void update_desc(char **desc)
|
|||||||
updatestring(win[STA].p, desc, 0, 1);
|
updatestring(win[STA].p, desc, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Edit the list of exception days for a recurrent item. */
|
/* Edit a list of exception days for a recurrent item. */
|
||||||
static int update_exc(llist_t *exc)
|
static int edit_exc(llist_t *exc)
|
||||||
{
|
{
|
||||||
int updated = 0;
|
int updated = 0;
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ static int update_exc(llist_t *exc)
|
|||||||
while (1) {
|
while (1) {
|
||||||
ret = updatestring(win[STA].p, &days, 0, 1);
|
ret = updatestring(win[STA].p, &days, 0, 1);
|
||||||
if (ret == GETSTRING_VALID || ret == GETSTRING_RET) {
|
if (ret == GETSTRING_VALID || ret == GETSTRING_RET) {
|
||||||
if (recur_update_exc(exc, days)) {
|
if (recur_str2exc(exc, days)) {
|
||||||
updated = 1;
|
updated = 1;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -313,7 +313,7 @@ static void update_rept(struct rpt **rpt, const time_t start, llist_t *exc)
|
|||||||
char *timstr = NULL;
|
char *timstr = NULL;
|
||||||
char *outstr = NULL;
|
char *outstr = NULL;
|
||||||
|
|
||||||
/* Update repetition type. */
|
/* Edit repetition type. */
|
||||||
int newtype;
|
int newtype;
|
||||||
const char *msg_rpt_prefix = _("Enter the new repetition type:");
|
const char *msg_rpt_prefix = _("Enter the new repetition type:");
|
||||||
const char *msg_rpt_daily = _("(d)aily");
|
const char *msg_rpt_daily = _("(d)aily");
|
||||||
@ -362,7 +362,7 @@ static void update_rept(struct rpt **rpt, const time_t start, llist_t *exc)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update frequency. */
|
/* Edit frequency. */
|
||||||
int newfreq;
|
int newfreq;
|
||||||
const char *msg_wrong_freq = _("Invalid frequency.");
|
const char *msg_wrong_freq = _("Invalid frequency.");
|
||||||
const char *msg_enter = _("Press [Enter] to continue");
|
const char *msg_enter = _("Press [Enter] to continue");
|
||||||
@ -382,7 +382,7 @@ static void update_rept(struct rpt **rpt, const time_t start, llist_t *exc)
|
|||||||
}
|
}
|
||||||
while (newfreq == 0);
|
while (newfreq == 0);
|
||||||
|
|
||||||
/* Update end date. */
|
/* Edit end date. */
|
||||||
time_t newuntil;
|
time_t newuntil;
|
||||||
const char *msg_until_1 =
|
const char *msg_until_1 =
|
||||||
_("Enter end date or duration ('?' for input formats):");
|
_("Enter end date or duration ('?' for input formats):");
|
||||||
@ -449,13 +449,21 @@ static void update_rept(struct rpt **rpt, const time_t start, llist_t *exc)
|
|||||||
keys_wgetch(win[KEY].p);
|
keys_wgetch(win[KEY].p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update exception list. */
|
/* Edit exception list. */
|
||||||
if (!update_exc(exc))
|
llist_t newexc;
|
||||||
|
recur_exc_dup(&newexc, exc);
|
||||||
|
if (!edit_exc(&newexc)) {
|
||||||
|
recur_free_exc_list(&newexc);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update all recurrence parameters. */
|
||||||
(*rpt)->type = recur_char2def(newtype);
|
(*rpt)->type = recur_char2def(newtype);
|
||||||
(*rpt)->freq = newfreq;
|
(*rpt)->freq = newfreq;
|
||||||
(*rpt)->until = newuntil;
|
(*rpt)->until = newuntil;
|
||||||
|
recur_free_exc_list(exc);
|
||||||
|
recur_exc_dup(exc, &newexc);
|
||||||
|
recur_free_exc_list(&newexc);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
mem_free(msg_rpt_current);
|
mem_free(msg_rpt_current);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user