aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-04-17 17:34:54 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-04-22 02:47:36 +0200
commitfb5f9d0155d63451bd16d7d50204da90ff604949 (patch)
treed076a0c380864bcab416b121fbfb103fa4e12b9c /src
parent0ad23c7a8f795f4fffa4ff0b3fd07d42422390cf (diff)
downloadcalcurse-fb5f9d0155d63451bd16d7d50204da90ff604949.tar.gz
calcurse-fb5f9d0155d63451bd16d7d50204da90ff604949.zip
Use generic lists for recurring item exceptions.
Rename "days" structure to "excp" which seems to be a better name here. Use generic linked lists of excp structures instead of using the "days" structure which again contains a linked list implementation. Do some cleanups and invocation fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h20
-rw-r--r--src/io.c103
-rw-r--r--src/notify.c4
-rw-r--r--src/recur.c189
4 files changed, 142 insertions, 174 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index a31c4f2..c32272e 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -301,8 +301,7 @@ struct day_item {
char *note; /* note attached to item */
};
-struct days {
- struct days *next;
+struct excp {
long st; /* beggining of the considered day, in seconds */
};
@@ -325,7 +324,7 @@ struct rpt {
/* Recurrent appointment definition. */
struct recur_apoint {
struct rpt *rpt; /* information about repetition */
- struct days *exc; /* days when the item should not be repeated */
+ llist_t exc; /* days when the item should not be repeated */
long start; /* beggining of the appointment */
long dur; /* duration of the appointment */
char state; /* 8 bits to store item state */
@@ -336,7 +335,7 @@ struct recur_apoint {
/* Reccurent event definition. */
struct recur_event {
struct rpt *rpt; /* information about repetition */
- struct days *exc; /* days when the item should not be repeated */
+ llist_t exc; /* days when the item should not be repeated */
int id; /* event type */
long day; /* day at which event occurs */
char *mesg; /* event description */
@@ -768,20 +767,19 @@ void recur_apoint_llist_init (void);
void recur_apoint_llist_free (void);
void recur_event_llist_free (void);
struct recur_apoint *recur_apoint_new (char *, char *, long, long, char,
- int, int, long, struct days **);
+ int, int, long, llist_t *);
struct recur_event *recur_event_new (char *, char *, long, int, int, int,
- long, struct days **);
+ long, llist_t *);
char recur_def2char (enum recur_type);
int recur_char2def (char);
struct recur_apoint *recur_apoint_scan (FILE *, struct tm, struct tm,
char, int, struct tm, char *,
- struct days **, char);
+ llist_t *, char);
struct recur_event *recur_event_scan (FILE *, struct tm, int, char,
int, struct tm, char *,
- struct days **);
+ llist_t *);
void recur_save_data (FILE *);
-unsigned recur_item_inday (long, struct days *, int, int,
- long, long);
+unsigned recur_item_inday (long, llist_t *, int, int, long, long);
unsigned recur_apoint_inday(struct recur_apoint *, long);
unsigned recur_event_inday(struct recur_event *, long);
void recur_event_erase (long, unsigned, unsigned,
@@ -789,7 +787,7 @@ void recur_event_erase (long, unsigned, unsigned,
void recur_apoint_erase (long, unsigned, unsigned,
enum eraseflg);
void recur_repeat_item (struct conf *);
-struct days *recur_exc_scan (FILE *);
+void recur_exc_scan (llist_t *, FILE *);
struct notify_app *recur_apoint_check_next (struct notify_app *, long, long);
struct recur_apoint *recur_get_apoint (long, int);
struct recur_event *recur_get_event (long, int);
diff --git a/src/io.c b/src/io.c
index 9e1dcf6..bad6cf4 100644
--- a/src/io.c
+++ b/src/io.c
@@ -248,7 +248,7 @@ get_export_stream (enum export_type type)
* (mainly used to export data).
*/
static void
-foreach_date_dump (const long date_end, struct rpt *rpt, struct days *exc,
+foreach_date_dump (const long date_end, struct rpt *rpt, llist_t *exc,
long item_first_date, long item_dur, char *item_mesg,
cb_dump_t cb_dump, FILE *stream)
{
@@ -342,8 +342,7 @@ pcal_export_footer (FILE *stream)
static void
ical_export_recur_events (FILE *stream)
{
- llist_item_t *i;
- struct days *day;
+ llist_item_t *i, *j;
char ical_date[BUFSIZ];
LLIST_FOREACH (&recur_elist, i)
@@ -363,16 +362,19 @@ ical_export_recur_events (FILE *stream)
else
(void)fprintf (stream, "\n");
- if (rev->exc != NULL)
+ if (LLIST_FIRST (&rev->exc))
{
- date_sec2date_fmt (rev->exc->st, ICALDATEFMT, ical_date);
- (void)fprintf (stream, "EXDATE:%s", ical_date);
- for (day = rev->exc->next; day; day = day->next)
+ (void)fprintf (stream, "EXDATE:");
+ LLIST_FOREACH (&rev->exc, j)
{
- date_sec2date_fmt (day->st, ICALDATEFMT, ical_date);
- (void)fprintf (stream, ",%s", ical_date);
+ struct excp *exc = LLIST_GET_DATA (j);
+ date_sec2date_fmt (exc->st, ICALDATEFMT, ical_date);
+ (void)fprintf (stream, "%s", ical_date);
+ if (LLIST_NEXT (j))
+ (void)fprintf (stream, ",");
+ else
+ (void)fprintf (stream, "\n");
}
- (void)fprintf (stream, "\n");
}
(void)fprintf (stream, "SUMMARY:%s\n", rev->mesg);
@@ -454,7 +456,7 @@ pcal_export_recur_events (FILE *stream)
const long YEAR_END = calendar_end_of_year ();
if (rev->day < YEAR_END && rev->day > YEAR_START)
- foreach_date_dump (YEAR_END, rev->rpt, rev->exc, rev->day, 0,
+ foreach_date_dump (YEAR_END, rev->rpt, &rev->exc, rev->day, 0,
rev->mesg, (cb_dump_t) pcal_dump_event, stream);
}
}
@@ -496,8 +498,7 @@ pcal_export_events (FILE *stream)
static void
ical_export_recur_apoints (FILE *stream)
{
- llist_item_t *i;
- struct days *day;
+ llist_item_t *i, *j;
char ical_datetime[BUFSIZ];
char ical_date[BUFSIZ];
@@ -522,16 +523,19 @@ ical_export_recur_apoints (FILE *stream)
else
(void)fprintf (stream, "\n");
- if (rapt->exc != NULL)
+ if (LLIST_FIRST (&rapt->exc))
{
- date_sec2date_fmt (rapt->exc->st, ICALDATEFMT, ical_date);
- (void)fprintf (stream, "EXDATE:%s", ical_date);
- for (day = rapt->exc->next; day; day = day->next)
+ (void)fprintf (stream, "EXDATE:");
+ LLIST_FOREACH (&rapt->exc, j)
{
- date_sec2date_fmt (day->st, ICALDATEFMT, ical_date);
- (void)fprintf (stream, ",%s", ical_date);
+ struct excp *exc = LLIST_GET_DATA (j);
+ date_sec2date_fmt (exc->st, ICALDATEFMT, ical_date);
+ (void)fprintf (stream, "%s", ical_date);
+ if (LLIST_NEXT (j))
+ (void)fprintf (stream, ",");
+ else
+ (void)fprintf (stream, "\n");
}
- (void)fprintf (stream, "\n");
}
(void)fprintf (stream, "SUMMARY:%s\n", rapt->mesg);
@@ -596,7 +600,7 @@ pcal_export_recur_apoints (FILE *stream)
const long YEAR_END = calendar_end_of_year ();
if (rapt->start < YEAR_END && rapt->start > YEAR_START)
- foreach_date_dump (YEAR_END, rapt->rpt, rapt->exc, rapt->start,
+ foreach_date_dump (YEAR_END, rapt->rpt, &rapt->exc, rapt->start,
rapt->dur, rapt->mesg,
(cb_dump_t)pcal_dump_apoint, stream);
}
@@ -1104,7 +1108,7 @@ io_load_app (void)
FILE *data_file;
int c, is_appointment, is_event, is_recursive;
struct tm start, end, until, *lt;
- struct days *exc;
+ llist_t exc;
time_t t;
int id = 0;
int freq;
@@ -1118,7 +1122,7 @@ io_load_app (void)
data_file = fopen (path_apts, "r");
for (;;)
{
- exc = 0;
+ LLIST_INIT (&exc);
is_appointment = is_event = is_recursive = 0;
c = getc (data_file);
if (c == EOF)
@@ -1192,7 +1196,7 @@ io_load_app (void)
if (c == '!')
{
(void)ungetc (c, data_file);
- exc = recur_exc_scan (data_file);
+ recur_exc_scan (&exc, data_file);
c = getc (data_file);
}
else
@@ -1204,7 +1208,7 @@ io_load_app (void)
else if (c == '!')
{ // endless item with exceptions
(void)ungetc (c, data_file);
- exc = recur_exc_scan (data_file);
+ recur_exc_scan (&exc, data_file);
c = getc (data_file);
until.tm_year = 0;
}
@@ -1754,14 +1758,14 @@ ical_store_todo (int priority, char *mesg, char *note)
static void
ical_store_event (char *mesg, char *note, long day, long end, ical_rpt_t *rpt,
- struct days *exc)
+ llist_t *exc)
{
const int EVENTID = 1;
if (rpt)
{
recur_event_new (mesg, note, day, EVENTID, rpt->type, rpt->freq,
- rpt->until, &exc);
+ rpt->until, exc);
mem_free (rpt);
}
else if (end && end != day)
@@ -1773,7 +1777,7 @@ ical_store_event (char *mesg, char *note, long day, long end, ical_rpt_t *rpt,
rpt->count = 0;
rpt->until = end;
recur_event_new (mesg, note, day, EVENTID, rpt->type, rpt->freq,
- rpt->until, &exc);
+ rpt->until, exc);
mem_free (rpt);
}
else
@@ -1786,7 +1790,7 @@ ical_store_event (char *mesg, char *note, long day, long end, ical_rpt_t *rpt,
static void
ical_store_apoint (char *mesg, char *note, long start, long dur,
- ical_rpt_t *rpt, struct days *exc, int has_alarm)
+ ical_rpt_t *rpt, llist_t *exc, int has_alarm)
{
char state = 0L;
@@ -1795,7 +1799,7 @@ ical_store_apoint (char *mesg, char *note, long start, long dur,
if (rpt)
{
recur_apoint_new (mesg, note, start, dur, state, rpt->type, rpt->freq,
- rpt->until, &exc);
+ rpt->until, exc);
mem_free (rpt);
}
else
@@ -2299,18 +2303,14 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
}
static void
-ical_add_exc (struct days **exc_head, long date)
+ical_add_exc (llist_t *exc_head, long date)
{
- if (date == 0)
- return;
- else
+ if (date != 0)
{
- struct days *exc;
-
- exc = mem_malloc (sizeof (struct days));
+ struct excp *exc = mem_malloc (sizeof (struct excp));
exc->st = date;
- exc->next = *exc_head;
- *exc_head = exc;
+
+ LLIST_ADD (exc_head, exc);
}
}
@@ -2318,15 +2318,14 @@ ical_add_exc (struct days **exc_head, long date)
* This property defines the list of date/time exceptions for a
* recurring calendar component.
*/
-static struct days *
-ical_read_exdate (FILE *log, char *exstr, unsigned *noskipped,
+void
+ical_read_exdate (llist_t *exc, FILE *log, char *exstr, unsigned *noskipped,
const int itemline)
{
- struct days *exc;
char *p, *q;
long date;
- exc = NULL;
+ LLIST_INIT (exc);
if ((p = strchr (exstr, ':')) != NULL)
{
p++;
@@ -2338,11 +2337,11 @@ ical_read_exdate (FILE *log, char *exstr, unsigned *noskipped,
(void)strncpy (buf, p, buflen);
buf[buflen] = '\0';
date = ical_datetime2long (buf, NULL);
- ical_add_exc (&exc, date);
+ ical_add_exc (exc, date);
p = ++q;
}
date = ical_datetime2long (p, NULL);
- ical_add_exc (&exc, date);
+ ical_add_exc (exc, date);
}
else
{
@@ -2350,7 +2349,6 @@ ical_read_exdate (FILE *log, char *exstr, unsigned *noskipped,
_("recurrence exception dates malformed."));
(*noskipped)++;
}
- return exc;
}
/* Return an allocated string containing the name of the newly created note. */
@@ -2440,7 +2438,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
ical_vevent_e vevent_type;
char *p, buf[BUFSIZ], buf_upper[BUFSIZ];
struct {
- struct days *exc;
+ llist_t exc;
ical_rpt_t *rpt;
char *mesg, *note;
long start, end, dur;
@@ -2496,7 +2494,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
vevent.end = 0L;
ical_store_event (vevent.mesg, vevent.note,
vevent.start, vevent.end,
- vevent.rpt, vevent.exc);
+ vevent.rpt, &vevent.exc);
(*noevents)++;
return;
}
@@ -2512,7 +2510,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
}
}
ical_store_apoint (vevent.mesg, vevent.note, vevent.start,
- vevent.dur, vevent.rpt, vevent.exc,
+ vevent.dur, vevent.rpt, &vevent.exc,
vevent.has_alarm);
(*noapoints)++;
break;
@@ -2524,7 +2522,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
goto cleanup;
}
ical_store_event (vevent.mesg, vevent.note, vevent.start,
- vevent.end, vevent.rpt, vevent.exc);
+ vevent.end, vevent.rpt, &vevent.exc);
(*noevents)++;
break;
case UNDEFINED:
@@ -2581,7 +2579,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
}
else if (strncmp (buf_upper, exdate.str, exdate.len) == 0)
{
- vevent.exc = ical_read_exdate (log, buf, noskipped, ITEMLINE);
+ ical_read_exdate (&vevent.exc, log, buf, noskipped, ITEMLINE);
}
else if (strncmp (buf_upper, summary.str, summary.len) == 0)
{
@@ -2611,8 +2609,7 @@ cleanup:
mem_free (vevent.mesg);
if (vevent.rpt)
mem_free (vevent.rpt);
- if (vevent.exc)
- mem_free (vevent.exc);
+ LLIST_FREE (&vevent.exc);
(*noskipped)++;
}
diff --git a/src/notify.c b/src/notify.c
index 4ae4dd5..3e5d3c7 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -506,7 +506,7 @@ notify_check_repeated (struct recur_apoint *i)
current_time = time (NULL);
pthread_mutex_lock (&notify_app.mutex);
- if ((real_app_time = recur_item_inday (i->start, i->exc, i->rpt->type,
+ if ((real_app_time = recur_item_inday (i->start, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until,
get_today ()) > current_time))
{
@@ -551,7 +551,7 @@ notify_same_recur_item (struct recur_apoint *i)
int same = 0;
long item_start = 0;
- item_start = recur_item_inday (i->start, i->exc, i->rpt->type,
+ item_start = recur_item_inday (i->start, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today ());
pthread_mutex_lock (&notify_app.mutex);
if (notify_app.got_app && item_start == notify_app.time)
diff --git a/src/recur.c b/src/recur.c
index f037abf..d19cda4 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -47,48 +47,49 @@ llist_t recur_elist;
static struct recur_event bkp_cut_recur_event;
static struct recur_apoint bkp_cut_recur_apoint;
+static void
+free_exc (struct excp *exc)
+{
+ mem_free (exc);
+}
static void
-free_exc (struct days *exc)
+free_exc_list (llist_t *exc)
{
- struct days *o, **i;
+ LLIST_FREE_INNER (exc, free_exc);
+ LLIST_FREE (exc);
+}
- i = &exc;
- while (*i)
- {
- o = *i;
- *i = o->next;
- mem_free (o);
- }
+static int
+exc_cmp_day (struct excp *a, struct excp *b)
+{
+ return (a->st < b->st ? -1 : (a->st == b->st ? 0 : 1));
}
static void
-recur_add_exc (struct days **exc, long day)
+recur_add_exc (llist_t *exc, long day)
{
- struct days **i, *o;
-
- o = mem_malloc (sizeof (struct days));
+ struct excp *o = mem_malloc (sizeof (struct excp));
o->st = day;
- i = exc;
- for (;;)
- {
- if (*i == NULL || (*i)->st > day)
- {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
- }
+
+ LLIST_ADD_SORTED (exc, o, exc_cmp_day);
}
static void
-exc_dup (struct days **in, struct days *exc)
+exc_dup (llist_t *in, llist_t *exc)
{
- struct days *p;
+ llist_item_t *i;
+
+ LLIST_INIT (in);
- for (p = exc; p; p = p->next)
- recur_add_exc (in, p->st);
+ if (exc)
+ {
+ LLIST_FOREACH (exc, i)
+ {
+ struct excp *p = LLIST_GET_DATA (i);
+ recur_add_exc (in, p->st);
+ }
+ }
}
void
@@ -104,11 +105,7 @@ recur_event_free_bkp (enum eraseflg flag)
mem_free (bkp_cut_recur_event.rpt);
bkp_cut_recur_event.rpt = 0;
}
- if (bkp_cut_recur_event.exc)
- {
- free_exc (bkp_cut_recur_event.exc);
- bkp_cut_recur_event.exc = 0;
- }
+ free_exc_list (&bkp_cut_recur_event.exc);
erase_note (&bkp_cut_recur_event.note, flag);
}
@@ -125,11 +122,7 @@ recur_apoint_free_bkp (enum eraseflg flag)
mem_free (bkp_cut_recur_apoint.rpt);
bkp_cut_recur_apoint.rpt = 0;
}
- if (bkp_cut_recur_apoint.exc)
- {
- free_exc (bkp_cut_recur_apoint.exc);
- bkp_cut_recur_apoint.exc = 0;
- }
+ free_exc_list (&bkp_cut_recur_apoint.exc);
erase_note (&bkp_cut_recur_apoint.note, flag);
}
@@ -147,8 +140,7 @@ recur_event_dup (struct recur_event *in, struct recur_event *bkp)
bkp->rpt->freq = in->rpt->freq;
bkp->rpt->until = in->rpt->until;
- if (in->exc)
- exc_dup (&bkp->exc, in->exc);
+ exc_dup (&bkp->exc, &in->exc);
if (in->note)
bkp->note = mem_strdup (in->note);
@@ -169,8 +161,7 @@ recur_apoint_dup (struct recur_apoint *in, struct recur_apoint *bkp)
bkp->rpt->freq = in->rpt->freq;
bkp->rpt->until = in->rpt->until;
- if (in->exc)
- exc_dup (&bkp->exc, in->exc);
+ exc_dup (&bkp->exc, &in->exc);
if (in->note)
bkp->note = mem_strdup (in->note);
@@ -190,11 +181,7 @@ recur_apoint_free (struct recur_apoint *rapt)
mem_free (rapt->note);
if (rapt->rpt)
mem_free (rapt->rpt);
- if (rapt->exc)
- {
- free_exc (rapt->exc);
- rapt->exc = 0;
- }
+ free_exc_list (&rapt->exc);
mem_free (rapt);
}
@@ -206,11 +193,7 @@ recur_event_free (struct recur_event *rev)
mem_free (rev->note);
if (rev->rpt)
mem_free (rev->rpt);
- if (rev->exc)
- {
- free_exc (rev->exc);
- rev->exc = 0;
- }
+ free_exc_list (&rev->exc);
mem_free (rev);
}
@@ -243,7 +226,7 @@ recur_event_cmp_day (struct recur_event *a, struct recur_event *b)
/* Insert a new recursive appointment in the general linked list */
struct recur_apoint *
recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
- int type, int freq, long until, struct days **except)
+ int type, int freq, long until, llist_t *except)
{
struct recur_apoint *rapt = mem_malloc (sizeof (struct recur_apoint));
@@ -256,13 +239,13 @@ recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
rapt->rpt->type = type;
rapt->rpt->freq = freq;
rapt->rpt->until = until;
- rapt->exc = 0;
- if (except && *except)
+ if (except)
{
- exc_dup (&rapt->exc, *except);
- free_exc (*except);
- *except = 0;
+ exc_dup (&rapt->exc, except);
+ free_exc_list (except);
}
+ else
+ LLIST_INIT (&rapt->exc);
LLIST_TS_LOCK (&recur_alist_p);
LLIST_TS_ADD_SORTED (&recur_alist_p, rapt, recur_apoint_cmp_start);
@@ -274,7 +257,7 @@ recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
/* Insert a new recursive event in the general linked list */
struct recur_event *
recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
- long until, struct days **except)
+ long until, llist_t *except)
{
struct recur_event *rev = mem_malloc (sizeof (struct recur_event));
@@ -286,13 +269,13 @@ recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
rev->rpt->type = type;
rev->rpt->freq = freq;
rev->rpt->until = until;
- rev->exc = 0;
- if (except && *except)
+ if (except)
{
- exc_dup (&rev->exc, *except);
- free_exc (*except);
- *except = 0;
+ exc_dup (&rev->exc, except);
+ free_exc_list (except);
}
+ else
+ LLIST_INIT (&rev->exc);
LLIST_ADD_SORTED (&recur_elist, rev, recur_event_cmp_day);
@@ -362,28 +345,29 @@ recur_char2def (char type)
/* Write days for which recurrent items should not be repeated. */
static void
-recur_write_exc (struct days *exc, FILE *f)
+recur_write_exc (llist_t *lexc, FILE *f)
{
+ llist_item_t *i;
struct tm *lt;
time_t t;
int st_mon, st_day, st_year;
- while (exc)
+ LLIST_FOREACH (lexc, i)
{
+ struct excp *exc = LLIST_GET_DATA (i);
t = exc->st;
lt = localtime (&t);
st_mon = lt->tm_mon + 1;
st_day = lt->tm_mday;
st_year = lt->tm_year + 1900;
(void)fprintf (f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
- exc = exc->next;
}
}
/* Load the recursive appointment description */
struct recur_apoint *
recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
- int freq, struct tm until, char *note, struct days **exc,
+ int freq, struct tm until, char *note, llist_t *exc,
char state)
{
char buf[BUFSIZ], *nl;
@@ -429,7 +413,7 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
/* Load the recursive events from file */
struct recur_event *
recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
- struct tm until, char *note, struct days **exc)
+ struct tm until, char *note, llist_t *exc)
{
char buf[BUFSIZ], *nl;
time_t tstart, tuntil;
@@ -496,8 +480,7 @@ recur_apoint_write (struct recur_apoint *o, FILE *f)
o->rpt->freq, recur_def2char (o->rpt->type),
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
}
- if (o->exc != NULL)
- recur_write_exc (o->exc, f);
+ recur_write_exc (&o->exc, f);
(void)fprintf (f, "} ");
if (o->note != NULL)
(void)fprintf (f, ">%s ", o->note);
@@ -540,8 +523,7 @@ recur_event_write (struct recur_event *o, FILE *f)
o->rpt->freq, recur_def2char (o->rpt->type),
end_mon, end_day, end_year);
}
- if (o->exc != NULL)
- recur_write_exc (o->exc, f);
+ recur_write_exc (&o->exc, f);
(void)fprintf (f, "} ");
if (o->note != NULL)
(void)fprintf (f, ">%s ", o->note);
@@ -633,6 +615,12 @@ diff_years (struct tm lt_start, struct tm lt_end)
return lt_end.tm_year - lt_start.tm_year;
}
+static int
+exc_inday (struct excp *exc, long day_start)
+{
+ return (exc->st >= day_start && exc->st < day_start + DAYINSEC);
+}
+
/*
* Check if the recurrent item belongs to the selected day,
* and if yes, return the real start time.
@@ -643,22 +631,20 @@ diff_years (struct tm lt_start, struct tm lt_end)
* calculation of recurrent dates after a turn of years.
*/
unsigned
-recur_item_inday (long item_start, struct days *item_exc, int rpt_type,
+recur_item_inday (long item_start, llist_t *item_exc, int rpt_type,
int rpt_freq, long rpt_until, long day_start)
{
struct date start_date;
long day_end, diff;
struct tm lt_item, lt_day;
- struct days *exc;
time_t t;
day_end = day_start + DAYINSEC;
t = day_start;
lt_day = *localtime (&t);
- for (exc = item_exc; exc != NULL; exc = exc->next)
- if (exc->st < day_end && exc->st >= day_start)
- return (0);
+ if (LLIST_FIND_FIRST (item_exc, day_start, exc_inday))
+ return 0;
if (rpt_until == 0) /* we have an endless recurrent item */
rpt_until = day_end;
@@ -722,14 +708,14 @@ recur_item_inday (long item_start, struct days *item_exc, int rpt_type,
unsigned
recur_apoint_inday(struct recur_apoint *rapt, long day_start)
{
- return recur_item_inday (rapt->start, rapt->exc, rapt->rpt->type,
+ return recur_item_inday (rapt->start, &rapt->exc, rapt->rpt->type,
rapt->rpt->freq, rapt->rpt->until, day_start);
}
unsigned
recur_event_inday(struct recur_event *rev, long day_start)
{
- return recur_item_inday (rev->day, rev->exc, rev->rpt->type, rev->rpt->freq,
+ return recur_item_inday (rev->day, &rev->exc, rev->rpt->type, rev->rpt->freq,
rev->rpt->until, day_start);
}
@@ -769,11 +755,7 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
mem_free (rev->rpt);
rev->rpt = 0;
}
- if (rev->exc)
- {
- free_exc (rev->exc);
- rev->exc = 0;
- }
+ free_exc_list (&rev->exc);
if (flag != ERASE_FORCE_KEEP_NOTE && flag != ERASE_CUT)
erase_note (&rev->note, flag);
mem_free (rev);
@@ -824,11 +806,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
mem_free (rapt->rpt);
rapt->rpt = 0;
}
- if (rapt->exc)
- {
- free_exc (rapt->exc);
- rapt->exc = 0;
- }
+ free_exc_list (&rapt->exc);
if (flag != ERASE_FORCE_KEEP_NOTE && flag != ERASE_CUT)
erase_note (&rapt->note, flag);
mem_free (rapt);
@@ -999,14 +977,13 @@ recur_repeat_item (struct conf *conf)
* Read days for which recurrent items must not be repeated
* (such days are called exceptions).
*/
-struct days *
-recur_exc_scan (FILE *data_file)
+void
+recur_exc_scan (llist_t *lexc, FILE *data_file)
{
int c = 0;
struct tm day;
- struct days *exc_head, *exc;
- exc_head = 0;
+ LLIST_INIT (lexc);
while ((c = getc (data_file)) == '!')
{
(void)ungetc (c, data_file);
@@ -1020,12 +997,10 @@ recur_exc_scan (FILE *data_file)
day.tm_isdst = -1;
day.tm_year -= 1900;
day.tm_mon--;
- exc = mem_malloc (sizeof (struct days));
+ struct excp *exc = mem_malloc (sizeof (struct excp));
exc->st = mktime (&day);
- exc->next = exc_head;
- exc_head = exc;
+ LLIST_ADD (lexc, exc);
}
- return exc_head;
}
static int
@@ -1119,6 +1094,7 @@ void
recur_event_paste_item (void)
{
long new_start, time_shift;
+ llist_item_t *i;
new_start = date2sec (*calendar_get_slctd_day (), 12, 0);
time_shift = new_start - bkp_cut_recur_event.day;
@@ -1126,12 +1102,10 @@ recur_event_paste_item (void)
bkp_cut_recur_event.day += time_shift;
if (bkp_cut_recur_event.rpt->until != 0)
bkp_cut_recur_event.rpt->until += time_shift;
- if (bkp_cut_recur_event.exc)
+ LLIST_FOREACH (&bkp_cut_recur_event.exc, i)
{
- struct days *exc;
-
- for (exc = bkp_cut_recur_event.exc; exc != NULL; exc = exc->next)
- exc->st += time_shift;
+ struct excp *exc = LLIST_GET_DATA (i);
+ exc->st += time_shift;
}
(void)recur_event_new (bkp_cut_recur_event.mesg, bkp_cut_recur_event.note,
@@ -1147,6 +1121,7 @@ void
recur_apoint_paste_item (void)
{
long new_start, time_shift;
+ llist_item_t *i;
new_start = date2sec (*calendar_get_slctd_day (),
get_item_hour (bkp_cut_recur_apoint.start),
@@ -1156,12 +1131,10 @@ recur_apoint_paste_item (void)
bkp_cut_recur_apoint.start += time_shift;
if (bkp_cut_recur_apoint.rpt->until != 0)
bkp_cut_recur_apoint.rpt->until += time_shift;
- if (bkp_cut_recur_apoint.exc)
+ LLIST_FOREACH (&bkp_cut_recur_event.exc, i)
{
- struct days *exc;
-
- for (exc = bkp_cut_recur_apoint.exc; exc != NULL; exc = exc->next)
- exc->st += time_shift;
+ struct excp *exc = LLIST_GET_DATA (i);
+ exc->st += time_shift;
}
(void)recur_apoint_new (bkp_cut_recur_apoint.mesg, bkp_cut_recur_apoint.note,