diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2019-06-04 09:34:45 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2020-04-28 07:32:44 -0400 |
commit | ce81c0fa6362f0092f40eab1cddf0a6339c473c5 (patch) | |
tree | 4eac07b3b8ce8c24bc2952034b5410ccb5a48838 /src/ical.c | |
parent | 3f7bd331c875dd889c4d69537b5408396b0e8f16 (diff) | |
download | calcurse-ce81c0fa6362f0092f40eab1cddf0a6339c473c5.tar.gz calcurse-ce81c0fa6362f0092f40eab1cddf0a6339c473c5.zip |
Refactor function calls: recurrence parameters as a single argument
The recurrence parameters are type, frequency, until date and exception
list (in RFC 5545 parlance FREQ, INTERVAL, UNTIL and EXDATE's). When
these are passed in a function call, the argument list becomes long and
not very readable. When support for extended recurrence rules is
implemented, the number of recurrence parameters increases, and function
signatures must be amended.
Solution: The "struct rpt" is extended with the exception list; any
future recurrence parameters are added here. A pointer to this structure
replaces the recurrence parameters in function calls.
Note: Each recurrent event and appoinment instance has (a pointer to) a
"struct rpt" and in addition an exception list. The latter is retained
to avoid the derived changes, and the exception list in the structure is
initialized to an empty list when the recurrent instance is created.
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/ical.c')
-rw-r--r-- | src/ical.c | 46 |
1 files changed, 26 insertions, 20 deletions
@@ -78,8 +78,8 @@ static void ical_export_apoints(FILE *, int); static void ical_export_todo(FILE *, int); static void ical_export_footer(FILE *); -static const char *ical_recur_type[RECUR_TYPES] = - { "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" }; +static const char *ical_recur_type[NBRECUR] = + { "DAILY", "WEEKLY", "MONTHLY", "YEARLY" }; /* Escape characters in field before printing */ static void ical_format_line(FILE * stream, char * field, char * msg) @@ -375,17 +375,21 @@ static void ical_store_todo(int priority, int completed, char *mesg, static void ical_store_event(char *mesg, char *note, long day, long end, - ical_rpt_t * rpt, llist_t * exc, const char *fmt_ev, + ical_rpt_t *irpt, llist_t *exc, const char *fmt_ev, const char *fmt_rev) { const int EVENTID = 1; struct event *ev; struct recur_event *rev; - if (rpt) { - rev = recur_event_new(mesg, note, day, EVENTID, rpt->type, - rpt->freq, rpt->until, exc); - mem_free(rpt); + if (irpt) { + struct rpt rpt; + rpt.type = irpt->type; + rpt.freq = irpt->freq; + rpt.until = irpt->until; + rpt.exc = *exc; + rev = recur_event_new(mesg, note, day, EVENTID, &rpt); + mem_free(irpt); if (fmt_rev) print_recur_event(fmt_rev, day, rev); goto cleanup; @@ -406,14 +410,12 @@ ical_store_event(char *mesg, char *note, long day, long end, * event starts, so we need to do some conversion here. */ end = day + ((end - day - 1) / DAYINSEC) * DAYINSEC; - rpt = mem_malloc(sizeof(ical_rpt_t)); - rpt->type = RECUR_DAILY; - rpt->freq = 1; - rpt->count = 0; - rpt->until = end; - rev = recur_event_new(mesg, note, day, EVENTID, rpt->type, - rpt->freq, rpt->until, exc); - mem_free(rpt); + struct rpt rpt; + rpt.type = RECUR_DAILY; + rpt.freq = 1; + rpt.until = end; + rpt.exc = *exc; + rev = recur_event_new(mesg, note, day, EVENTID, &rpt); if (fmt_rev) print_recur_event(fmt_rev, day, rev); @@ -424,7 +426,7 @@ cleanup: static void ical_store_apoint(char *mesg, char *note, long start, long dur, - ical_rpt_t * rpt, llist_t * exc, int has_alarm, + ical_rpt_t * irpt, llist_t * exc, int has_alarm, const char *fmt_apt, const char *fmt_rapt) { char state = 0L; @@ -433,10 +435,14 @@ ical_store_apoint(char *mesg, char *note, long start, long dur, if (has_alarm) state |= APOINT_NOTIFY; - if (rpt) { - rapt = recur_apoint_new(mesg, note, start, dur, state, - rpt->type, rpt->freq, rpt->until, exc); - mem_free(rpt); + if (irpt) { + struct rpt rpt; + rpt.type = irpt->type; + rpt.freq = irpt->freq; + rpt.until = irpt->until; + rpt.exc = *exc; + rapt = recur_apoint_new(mesg, note, start, dur, state, &rpt); + mem_free(irpt); if (fmt_rapt) print_recur_apoint(fmt_rapt, start, rapt->start, rapt); } else { |