summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-06-26 11:22:08 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-06-30 14:34:35 +0200
commitb8b6830dfd75f6870b2171e7f31cb0cdb927532e (patch)
treecd3ad69b32150402de8b031f68705fb2f8e99600 /src
parent8a85aaafa5905297398605eb890b00d22416eeb5 (diff)
downloadcalcurse-b8b6830dfd75f6870b2171e7f31cb0cdb927532e.zip
Allow passing more complex data to list callbacks
Change the data type of the "data" parameter from "long" to "void *" in llist_find_*() signatures to allow for passing more complex objects. Change all llist_find_*() invocations and callbacks accordingly. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/apoint.c12
-rw-r--r--src/calcurse.h8
-rw-r--r--src/day.c20
-rw-r--r--src/event.c6
-rw-r--r--src/llist.c8
-rw-r--r--src/llist.h10
-rw-r--r--src/recur.c20
7 files changed, 42 insertions, 42 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 8d7852b..61acc49 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -186,9 +186,9 @@ void apoint_paste(unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
hilt++;
}
-unsigned apoint_inday(struct apoint *i, long start)
+unsigned apoint_inday(struct apoint *i, long *start)
{
- return (i->start <= start + DAYINSEC && i->start + i->dur > start);
+ return (i->start <= *start + DAYINSEC && i->start + i->dur > *start);
}
void apoint_sec2str(struct apoint *o, long day, char *start, char *end)
@@ -275,7 +275,7 @@ void apoint_delete_bynum(long start, unsigned num, enum eraseflg flag)
int need_check_notify = 0;
LLIST_TS_LOCK(&alist_p);
- i = LLIST_TS_FIND_NTH(&alist_p, num, start, apoint_inday);
+ i = LLIST_TS_FIND_NTH(&alist_p, num, &start, apoint_inday);
if (!i)
EXIT(_("no such appointment"));
@@ -356,9 +356,9 @@ void apoint_scroll_pad_up(int nb_events_inday)
apad.first_onscreen = item_first_line;
}
-static int apoint_starts_after(struct apoint *apt, long time)
+static int apoint_starts_after(struct apoint *apt, long *time)
{
- return apt->start > time;
+ return apt->start > *time;
}
/*
@@ -370,7 +370,7 @@ struct notify_app *apoint_check_next(struct notify_app *app, long start)
llist_item_t *i;
LLIST_TS_LOCK(&alist_p);
- i = LLIST_TS_FIND_FIRST(&alist_p, start, apoint_starts_after);
+ i = LLIST_TS_FIND_FIRST(&alist_p, &start, apoint_starts_after);
if (i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
diff --git a/src/calcurse.h b/src/calcurse.h
index 8afb7f4..1702ffe 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -601,7 +601,7 @@ int apoint_hilt(void);
struct apoint *apoint_new(char *, char *, long, long, char);
int apoint_cut(unsigned *, unsigned *);
void apoint_paste(unsigned *, unsigned *, int);
-unsigned apoint_inday(struct apoint *, long);
+unsigned apoint_inday(struct apoint *, long *);
void apoint_sec2str(struct apoint *, long, char *, char *);
void apoint_write(struct apoint *, FILE *);
struct apoint *apoint_scan(FILE *, struct tm, struct tm, char, char *);
@@ -692,7 +692,7 @@ void event_free_bkp(void);
void event_llist_init(void);
void event_llist_free(void);
struct event *event_new(char *, char *, long, int);
-unsigned event_inday(struct event *, long);
+unsigned event_inday(struct event *, long *);
void event_write(struct event *, FILE *);
struct event *event_scan(FILE *, struct tm, int, char *);
void event_delete_bynum(long, unsigned, enum eraseflg);
@@ -869,8 +869,8 @@ unsigned recur_item_find_occurrence(long, long, llist_t *, int,
unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, unsigned *);
unsigned recur_event_find_occurrence(struct recur_event *, long, unsigned *);
unsigned recur_item_inday(long, long, llist_t *, int, int, long, long);
-unsigned recur_apoint_inday(struct recur_apoint *, long);
-unsigned recur_event_inday(struct recur_event *, long);
+unsigned recur_apoint_inday(struct recur_apoint *, long *);
+unsigned recur_event_inday(struct recur_event *, long *);
void recur_event_erase(long, unsigned, unsigned, enum eraseflg);
void recur_apoint_erase(long, unsigned, unsigned, enum eraseflg);
void recur_exc_scan(llist_t *, FILE *);
diff --git a/src/day.c b/src/day.c
index fc4a475..a0b119f 100644
--- a/src/day.c
+++ b/src/day.c
@@ -164,7 +164,7 @@ static int day_store_events(long date, regex_t *regex)
union aptev_ptr p;
int e_nb = 0;
- LLIST_FIND_FOREACH_CONT(&eventlist, date, event_inday, i) {
+ LLIST_FIND_FOREACH_CONT(&eventlist, &date, event_inday, i) {
struct event *ev = LLIST_TS_GET_DATA(i);
if (regex && regexec(regex, ev->mesg, 0, 0, 0) != 0)
@@ -191,7 +191,7 @@ static int day_store_recur_events(long date, regex_t *regex)
union aptev_ptr p;
int e_nb = 0;
- LLIST_FIND_FOREACH(&recur_elist, date, recur_event_inday, i) {
+ LLIST_FIND_FOREACH(&recur_elist, &date, recur_event_inday, i) {
struct recur_event *rev = LLIST_TS_GET_DATA(i);
if (regex && regexec(regex, rev->mesg, 0, 0, 0) != 0)
@@ -219,7 +219,7 @@ static int day_store_apoints(long date, regex_t *regex)
int a_nb = 0;
LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FIND_FOREACH(&alist_p, date, apoint_inday, i) {
+ LLIST_TS_FIND_FOREACH(&alist_p, &date, apoint_inday, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
if (regex && regexec(regex, apt->mesg, 0, 0, 0) != 0)
@@ -252,7 +252,7 @@ static int day_store_recur_apoints(long date, regex_t *regex)
int a_nb = 0;
LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FIND_FOREACH(&recur_alist_p, date, recur_apoint_inday, i) {
+ LLIST_TS_FIND_FOREACH(&recur_alist_p, &date, recur_apoint_inday, i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
if (regex && regexec(regex, rapt->mesg, 0, 0, 0) != 0)
@@ -511,21 +511,21 @@ int day_check_if_item(struct date day)
{
const long date = date2sec(day, 0, 0);
- if (LLIST_FIND_FIRST(&recur_elist, date, recur_event_inday))
+ if (LLIST_FIND_FIRST(&recur_elist, (long *)&date, recur_event_inday))
return 1;
LLIST_TS_LOCK(&recur_alist_p);
- if (LLIST_TS_FIND_FIRST(&recur_alist_p, date, recur_apoint_inday)) {
+ if (LLIST_TS_FIND_FIRST(&recur_alist_p, (long *)&date, recur_apoint_inday)) {
LLIST_TS_UNLOCK(&recur_alist_p);
return 1;
}
LLIST_TS_UNLOCK(&recur_alist_p);
- if (LLIST_FIND_FIRST(&eventlist, date, event_inday))
+ if (LLIST_FIND_FIRST(&eventlist, (long *)&date, event_inday))
return 1;
LLIST_TS_LOCK(&alist_p);
- if (LLIST_TS_FIND_FIRST(&alist_p, date, apoint_inday)) {
+ if (LLIST_TS_FIND_FIRST(&alist_p, (long *)&date, apoint_inday)) {
LLIST_TS_UNLOCK(&alist_p);
return 1;
}
@@ -566,7 +566,7 @@ unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
#define SLICENUM(tsec) ((tsec) / slicelen % slicesno)
LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FIND_FOREACH(&recur_alist_p, date, recur_apoint_inday, i) {
+ LLIST_TS_FIND_FOREACH(&recur_alist_p, (long *)&date, recur_apoint_inday, i) {
struct apoint *rapt = LLIST_TS_GET_DATA(i);
long start = get_item_time(rapt->start);
long end = get_item_time(rapt->start + rapt->dur);
@@ -579,7 +579,7 @@ unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
LLIST_TS_UNLOCK(&recur_alist_p);
LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FIND_FOREACH(&alist_p, date, apoint_inday, i) {
+ LLIST_TS_FIND_FOREACH(&alist_p, (long *)&date, apoint_inday, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
long start = get_item_time(apt->start);
long end = get_item_time(apt->start + apt->dur);
diff --git a/src/event.c b/src/event.c
index 6371b27..4af9f23 100644
--- a/src/event.c
+++ b/src/event.c
@@ -104,9 +104,9 @@ struct event *event_new(char *mesg, char *note, long day, int id)
}
/* Check if the event belongs to the selected day */
-unsigned event_inday(struct event *i, long start)
+unsigned event_inday(struct event *i, long *start)
{
- return (i->day < start + DAYINSEC && i->day >= start);
+ return (i->day < *start + DAYINSEC && i->day >= *start);
}
/* Write to file the event in user-friendly format */
@@ -157,7 +157,7 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note)
/* Delete an event from the list. */
void event_delete_bynum(long start, unsigned num, enum eraseflg flag)
{
- llist_item_t *i = LLIST_FIND_NTH(&eventlist, num, start, event_inday);
+ llist_item_t *i = LLIST_FIND_NTH(&eventlist, num, &start, event_inday);
if (!i)
EXIT(_("no such appointment"));
diff --git a/src/llist.c b/src/llist.c
index 847b795..addce42 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -112,7 +112,7 @@ llist_item_t *llist_next(llist_item_t * i)
* Return the successor of a list item if it is matched by some filter
* callback. Return NULL otherwise.
*/
-llist_item_t *llist_next_filter(llist_item_t * i, long data,
+llist_item_t *llist_next_filter(llist_item_t * i, void *data,
llist_fn_match_t fn_match)
{
if (i && i->next && fn_match(i->next->data, data))
@@ -205,7 +205,7 @@ void llist_remove(llist_t * l, llist_item_t * i)
/*
* Find the first item matched by some filter callback.
*/
-llist_item_t *llist_find_first(llist_t * l, long data,
+llist_item_t *llist_find_first(llist_t * l, void *data,
llist_fn_match_t fn_match)
{
llist_item_t *i;
@@ -221,7 +221,7 @@ llist_item_t *llist_find_first(llist_t * l, long data,
/*
* Find the next item matched by some filter callback.
*/
-llist_item_t *llist_find_next(llist_item_t * i, long data,
+llist_item_t *llist_find_next(llist_item_t * i, void *data,
llist_fn_match_t fn_match)
{
if (i) {
@@ -238,7 +238,7 @@ llist_item_t *llist_find_next(llist_item_t * i, long data,
/*
* Find the nth item matched by some filter callback.
*/
-llist_item_t *llist_find_nth(llist_t * l, int n, long data,
+llist_item_t *llist_find_nth(llist_t * l, int n, void *data,
llist_fn_match_t fn_match)
{
llist_item_t *i;
diff --git a/src/llist.h b/src/llist.h
index c795f37..a786358 100644
--- a/src/llist.h
+++ b/src/llist.h
@@ -48,7 +48,7 @@ struct llist {
};
typedef int (*llist_fn_cmp_t) (void *, void *);
-typedef int (*llist_fn_match_t) (void *, long);
+typedef int (*llist_fn_match_t) (void *, void *);
typedef void (*llist_fn_free_t) (void *);
/* Initialization and deallocation. */
@@ -65,10 +65,10 @@ void llist_free_inner(llist_t *, llist_fn_free_t);
llist_item_t *llist_first(llist_t *);
llist_item_t *llist_nth(llist_t *, int);
llist_item_t *llist_next(llist_item_t *);
-llist_item_t *llist_next_filter(llist_item_t *, long, llist_fn_match_t);
-llist_item_t *llist_find_first(llist_t *, long, llist_fn_match_t);
-llist_item_t *llist_find_next(llist_item_t *, long, llist_fn_match_t);
-llist_item_t *llist_find_nth(llist_t *, int, long, llist_fn_match_t);
+llist_item_t *llist_next_filter(llist_item_t *, void *, llist_fn_match_t);
+llist_item_t *llist_find_first(llist_t *, void *, llist_fn_match_t);
+llist_item_t *llist_find_next(llist_item_t *, void *, llist_fn_match_t);
+llist_item_t *llist_find_nth(llist_t *, int, void *, llist_fn_match_t);
#define LLIST_FIRST(l) llist_first(l)
#define LLIST_NTH(l, n) llist_nth(l, n)
diff --git a/src/recur.c b/src/recur.c
index 46cc375..212a98d 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -550,9 +550,9 @@ static long 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)
+static int exc_inday(struct excp *exc, long *day_start)
{
- return (exc->st >= day_start && exc->st < day_start + DAYINSEC);
+ return (exc->st >= *day_start && exc->st < *day_start + DAYINSEC);
}
/*
@@ -626,7 +626,7 @@ recur_item_find_occurrence(long item_start, long item_dur, llist_t * item_exc,
lt_item_day.tm_isdst = lt_day.tm_isdst;
t = mktime(&lt_item_day);
- if (LLIST_FIND_FIRST(item_exc, t, exc_inday))
+ if (LLIST_FIND_FIRST(item_exc, &t, exc_inday))
return 0;
if (rpt_until != 0 && t > rpt_until)
@@ -678,16 +678,16 @@ recur_item_inday(long item_start, long item_dur, llist_t * item_exc,
rpt_freq, rpt_until, day_start, NULL);
}
-unsigned recur_apoint_inday(struct recur_apoint *rapt, long day_start)
+unsigned recur_apoint_inday(struct recur_apoint *rapt, long *day_start)
{
return recur_item_inday(rapt->start, rapt->dur, &rapt->exc, rapt->rpt->type,
- rapt->rpt->freq, rapt->rpt->until, day_start);
+ rapt->rpt->freq, rapt->rpt->until, *day_start);
}
-unsigned recur_event_inday(struct recur_event *rev, long day_start)
+unsigned recur_event_inday(struct recur_event *rev, long *day_start)
{
return recur_item_inday(rev->day, DAYINSEC, &rev->exc, rev->rpt->type,
- rev->rpt->freq, rev->rpt->until, day_start);
+ rev->rpt->freq, rev->rpt->until, *day_start);
}
/*
@@ -700,7 +700,7 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
{
llist_item_t *i;
- i = LLIST_FIND_NTH(&recur_elist, num, start, recur_event_inday);
+ i = LLIST_FIND_NTH(&recur_elist, num, &start, recur_event_inday);
if (!i)
EXIT(_("event not found"));
@@ -742,7 +742,7 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
llist_item_t *i;
int need_check_notify = 0;
- i = LLIST_TS_FIND_NTH(&recur_alist_p, num, start, recur_apoint_inday);
+ i = LLIST_TS_FIND_NTH(&recur_alist_p, num, &start, recur_apoint_inday);
if (!i)
EXIT(_("appointment not found"));
@@ -825,7 +825,7 @@ struct notify_app *recur_apoint_check_next(struct notify_app *app, long start,
unsigned real_recur_start_time;
LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FIND_FOREACH(&recur_alist_p, app->time, recur_apoint_starts_before,
+ LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time, recur_apoint_starts_before,
i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);