Use generic lists for events.
Use the new generic list implementation instead of those insane "next" pointers in events. Includes some cleanups. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
1de34587ab
commit
6f883c0f3f
15
src/args.c
15
src/args.c
@ -352,7 +352,6 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
{
|
{
|
||||||
llist_item_t *i;
|
llist_item_t *i;
|
||||||
struct recur_event *re;
|
struct recur_event *re;
|
||||||
struct event *j;
|
|
||||||
struct recur_apoint *ra;
|
struct recur_apoint *ra;
|
||||||
long today;
|
long today;
|
||||||
unsigned print_date = 1;
|
unsigned print_date = 1;
|
||||||
@ -397,11 +396,10 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = eventlist; j != NULL; j = j->next)
|
LLIST_FIND_FOREACH (&eventlist, today, event_inday, i)
|
||||||
{
|
{
|
||||||
if (event_inday (j, today))
|
struct apoint *ev = LLIST_TS_GET_DATA (i);
|
||||||
{
|
if (regex && regexec (regex, ev->mesg, 0, 0, 0) != 0)
|
||||||
if (regex && regexec (regex, j->mesg, 0, 0, 0) != 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
app_found = 1;
|
app_found = 1;
|
||||||
@ -416,11 +414,10 @@ app_arg (int add_line, struct date *day, long date, int print_note,
|
|||||||
print_date = 0;
|
print_date = 0;
|
||||||
}
|
}
|
||||||
fputs (" * ", stdout);
|
fputs (" * ", stdout);
|
||||||
fputs (j->mesg, stdout);
|
fputs (ev->mesg, stdout);
|
||||||
fputs ("\n", stdout);
|
fputs ("\n", stdout);
|
||||||
if (print_note && j->note)
|
if (print_note && ev->note)
|
||||||
print_notefile (stdout, j->note, 2);
|
print_notefile (stdout, ev->note, 2);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Same process is performed but this time on the appointments. */
|
/* Same process is performed but this time on the appointments. */
|
||||||
|
@ -75,6 +75,9 @@ main (int argc, char **argv)
|
|||||||
apoint_llist_init ();
|
apoint_llist_init ();
|
||||||
recur_apoint_llist_init ();
|
recur_apoint_llist_init ();
|
||||||
|
|
||||||
|
/* Initialize non-thread-safe data structures. */
|
||||||
|
event_llist_init ();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Begin by parsing and handling command line arguments.
|
* Begin by parsing and handling command line arguments.
|
||||||
* The data path is also initialized here.
|
* The data path is also initialized here.
|
||||||
|
@ -270,7 +270,6 @@ struct apoint
|
|||||||
|
|
||||||
/* Event definition. */
|
/* Event definition. */
|
||||||
struct event {
|
struct event {
|
||||||
struct event *next;
|
|
||||||
int id; /* event identifier */
|
int id; /* event identifier */
|
||||||
long day; /* seconds since 1 jan 1970 */
|
long day; /* seconds since 1 jan 1970 */
|
||||||
char *mesg;
|
char *mesg;
|
||||||
@ -558,7 +557,6 @@ enum save_display {
|
|||||||
/* apoint.c */
|
/* apoint.c */
|
||||||
extern llist_ts_t alist_p;
|
extern llist_ts_t alist_p;
|
||||||
void apoint_free_bkp (enum eraseflg);
|
void apoint_free_bkp (enum eraseflg);
|
||||||
void apoint_free (struct apoint *);
|
|
||||||
void apoint_llist_init (void);
|
void apoint_llist_init (void);
|
||||||
void apoint_llist_free (void);
|
void apoint_llist_free (void);
|
||||||
void apoint_hilt_set (int);
|
void apoint_hilt_set (int);
|
||||||
@ -647,8 +645,9 @@ void dmon_start (int);
|
|||||||
void dmon_stop (void);
|
void dmon_stop (void);
|
||||||
|
|
||||||
/* event.c */
|
/* event.c */
|
||||||
extern struct event *eventlist;
|
extern llist_t eventlist;
|
||||||
void event_free_bkp (enum eraseflg);
|
void event_free_bkp (enum eraseflg);
|
||||||
|
void event_llist_init (void);
|
||||||
void event_llist_free (void);
|
void event_llist_free (void);
|
||||||
struct event *event_new (char *, char *, long, int);
|
struct event *event_new (char *, char *, long, int);
|
||||||
unsigned event_inday (struct event *, long);
|
unsigned event_inday (struct event *, long);
|
||||||
|
14
src/day.c
14
src/day.c
@ -150,16 +150,14 @@ day_add_apoint (int type, char *mesg, char *note, long start, long dur,
|
|||||||
static int
|
static int
|
||||||
day_store_events (long date)
|
day_store_events (long date)
|
||||||
{
|
{
|
||||||
struct event *j;
|
llist_item_t *i;
|
||||||
int e_nb = 0;
|
int e_nb = 0;
|
||||||
|
|
||||||
for (j = eventlist; j != NULL; j = j->next)
|
LLIST_FIND_FOREACH (&eventlist, date, event_inday, i)
|
||||||
{
|
|
||||||
if (event_inday (j, date))
|
|
||||||
{
|
{
|
||||||
|
struct event *ev = LLIST_TS_GET_DATA (i);
|
||||||
|
(void)day_add_event (EVNT, ev->mesg, ev->note, ev->day, ev->id);
|
||||||
e_nb++;
|
e_nb++;
|
||||||
(void)day_add_event (EVNT, j->mesg, j->note, j->day, j->id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return e_nb;
|
return e_nb;
|
||||||
@ -475,7 +473,6 @@ day_check_if_item (struct date day)
|
|||||||
{
|
{
|
||||||
struct recur_event *re;
|
struct recur_event *re;
|
||||||
struct recur_apoint *ra;
|
struct recur_apoint *ra;
|
||||||
struct event *e;
|
|
||||||
const long date = date2sec (day, 0, 0);
|
const long date = date2sec (day, 0, 0);
|
||||||
|
|
||||||
for (re = recur_elist; re != NULL; re = re->next)
|
for (re = recur_elist; re != NULL; re = re->next)
|
||||||
@ -493,8 +490,7 @@ day_check_if_item (struct date day)
|
|||||||
}
|
}
|
||||||
pthread_mutex_unlock (&(recur_alist_p->mutex));
|
pthread_mutex_unlock (&(recur_alist_p->mutex));
|
||||||
|
|
||||||
for (e = eventlist; e != NULL; e = e->next)
|
if (LLIST_FIND_FIRST (&eventlist, date, event_inday))
|
||||||
if (event_inday (e, date))
|
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
LLIST_TS_LOCK (&alist_p);
|
LLIST_TS_LOCK (&alist_p);
|
||||||
|
@ -172,6 +172,7 @@ dmon_start (int parent_exit_status)
|
|||||||
path_apts, strerror (errno));
|
path_apts, strerror (errno));
|
||||||
apoint_llist_init ();
|
apoint_llist_init ();
|
||||||
recur_apoint_llist_init ();
|
recur_apoint_llist_init ();
|
||||||
|
event_llist_init ();
|
||||||
io_load_app ();
|
io_load_app ();
|
||||||
data_loaded = 1;
|
data_loaded = 1;
|
||||||
|
|
||||||
|
116
src/event.c
116
src/event.c
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
#include "calcurse.h"
|
#include "calcurse.h"
|
||||||
|
|
||||||
struct event *eventlist;
|
llist_t eventlist;
|
||||||
static struct event bkp_cut_event;
|
static struct event bkp_cut_event;
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -55,6 +55,14 @@ event_free_bkp (enum eraseflg flag)
|
|||||||
erase_note (&bkp_cut_event.note, flag);
|
erase_note (&bkp_cut_event.note, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
event_free (struct event *ev)
|
||||||
|
{
|
||||||
|
mem_free (ev->mesg);
|
||||||
|
erase_note (&ev->note, ERASE_FORCE_KEEP_NOTE);
|
||||||
|
mem_free (ev);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
event_dup (struct event *in, struct event *bkp)
|
event_dup (struct event *in, struct event *bkp)
|
||||||
{
|
{
|
||||||
@ -67,44 +75,40 @@ event_dup (struct event *in, struct event *bkp)
|
|||||||
bkp->note = mem_strdup (in->note);
|
bkp->note = mem_strdup (in->note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
event_llist_init (void)
|
||||||
|
{
|
||||||
|
LLIST_INIT (&eventlist);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
event_llist_free (void)
|
event_llist_free (void)
|
||||||
{
|
{
|
||||||
struct event *o, **i;
|
LLIST_FREE_INNER (&eventlist, event_free);
|
||||||
|
LLIST_FREE (&eventlist);
|
||||||
|
}
|
||||||
|
|
||||||
i = &eventlist;
|
static int
|
||||||
while (*i)
|
event_cmp_day (struct event *a, struct event *b)
|
||||||
{
|
{
|
||||||
o = *i;
|
return (a->day < b->day ? -1 : (a->day == b->day ? 0 : 1));
|
||||||
*i = o->next;
|
|
||||||
mem_free (o->mesg);
|
|
||||||
erase_note (&o->note, ERASE_FORCE_KEEP_NOTE);
|
|
||||||
mem_free (o);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new event */
|
/* Create a new event */
|
||||||
struct event *
|
struct event *
|
||||||
event_new (char *mesg, char *note, long day, int id)
|
event_new (char *mesg, char *note, long day, int id)
|
||||||
{
|
{
|
||||||
struct event *o, **i;
|
struct event *ev;
|
||||||
o = mem_malloc (sizeof (struct event));
|
|
||||||
o->mesg = mem_strdup (mesg);
|
ev = mem_malloc (sizeof (struct event));
|
||||||
o->day = day;
|
ev->mesg = mem_strdup (mesg);
|
||||||
o->id = id;
|
ev->day = day;
|
||||||
o->note = (note != NULL) ? mem_strdup (note) : NULL;
|
ev->id = id;
|
||||||
i = &eventlist;
|
ev->note = (note != NULL) ? mem_strdup (note) : NULL;
|
||||||
for (;;)
|
|
||||||
{
|
LLIST_ADD_SORTED (&eventlist, ev, event_cmp_day);
|
||||||
if (*i == NULL || (*i)->day > day)
|
|
||||||
{
|
return ev;
|
||||||
o->next = *i;
|
|
||||||
*i = o;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i = &(*i)->next;
|
|
||||||
}
|
|
||||||
return (o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the event belongs to the selected day */
|
/* Check if the event belongs to the selected day */
|
||||||
@ -168,21 +172,12 @@ event_scan (FILE *f, struct tm start, int id, char *note)
|
|||||||
struct event *
|
struct event *
|
||||||
event_get (long day, int pos)
|
event_get (long day, int pos)
|
||||||
{
|
{
|
||||||
struct event *o;
|
llist_item_t *i = LLIST_FIND_NTH (&eventlist, pos, day, event_inday);
|
||||||
int n;
|
|
||||||
|
if (i)
|
||||||
|
return LLIST_TS_GET_DATA (i);
|
||||||
|
|
||||||
n = 0;
|
|
||||||
for (o = eventlist; o; o = o->next)
|
|
||||||
{
|
|
||||||
if (event_inday (o, day))
|
|
||||||
{
|
|
||||||
if (n == pos)
|
|
||||||
return o;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EXIT (_("event not found"));
|
EXIT (_("event not found"));
|
||||||
return 0;
|
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,43 +185,30 @@ event_get (long day, int pos)
|
|||||||
void
|
void
|
||||||
event_delete_bynum (long start, unsigned num, enum eraseflg flag)
|
event_delete_bynum (long start, unsigned num, enum eraseflg flag)
|
||||||
{
|
{
|
||||||
unsigned n;
|
llist_item_t *i = LLIST_FIND_NTH (&eventlist, num, start, event_inday);
|
||||||
struct event *i, **iptr;
|
|
||||||
|
if (!i)
|
||||||
|
EXIT (_("no such appointment"));
|
||||||
|
struct event *ev = LLIST_TS_GET_DATA (i);
|
||||||
|
|
||||||
n = 0;
|
|
||||||
iptr = &eventlist;
|
|
||||||
for (i = eventlist; i != NULL; i = i->next)
|
|
||||||
{
|
|
||||||
if (event_inday (i, start))
|
|
||||||
{
|
|
||||||
if (n == num)
|
|
||||||
{
|
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case ERASE_FORCE_ONLY_NOTE:
|
case ERASE_FORCE_ONLY_NOTE:
|
||||||
erase_note (&i->note, flag);
|
erase_note (&ev->note, flag);
|
||||||
break;
|
break;
|
||||||
case ERASE_CUT:
|
case ERASE_CUT:
|
||||||
event_free_bkp (ERASE_FORCE);
|
event_free_bkp (ERASE_FORCE);
|
||||||
event_dup (i, &bkp_cut_event);
|
event_dup (ev, &bkp_cut_event);
|
||||||
erase_note (&i->note, ERASE_FORCE_KEEP_NOTE);
|
erase_note (&ev->note, ERASE_FORCE_KEEP_NOTE);
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
default:
|
default:
|
||||||
*iptr = i->next;
|
LLIST_REMOVE (&eventlist, i);
|
||||||
mem_free (i->mesg);
|
mem_free (ev->mesg);
|
||||||
if (flag != ERASE_FORCE_KEEP_NOTE && flag != ERASE_CUT)
|
if (flag != ERASE_FORCE_KEEP_NOTE && flag != ERASE_CUT)
|
||||||
erase_note (&i->note, flag);
|
erase_note (&ev->note, flag);
|
||||||
mem_free (i);
|
mem_free (ev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
iptr = &i->next;
|
|
||||||
}
|
|
||||||
EXIT (_("event not found"));
|
|
||||||
/* NOTREACHED */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
26
src/io.c
26
src/io.c
@ -461,15 +461,16 @@ pcal_export_recur_events (FILE *stream)
|
|||||||
static void
|
static void
|
||||||
ical_export_events (FILE *stream)
|
ical_export_events (FILE *stream)
|
||||||
{
|
{
|
||||||
struct event *i;
|
llist_item_t *i;
|
||||||
char ical_date[BUFSIZ];
|
char ical_date[BUFSIZ];
|
||||||
|
|
||||||
for (i = eventlist; i != NULL; i = i->next)
|
LLIST_FOREACH (&eventlist, i)
|
||||||
{
|
{
|
||||||
date_sec2date_fmt (i->day, ICALDATEFMT, ical_date);
|
struct event *ev = LLIST_TS_GET_DATA (i);
|
||||||
|
date_sec2date_fmt (ev->day, ICALDATEFMT, ical_date);
|
||||||
(void)fprintf (stream, "BEGIN:VEVENT\n");
|
(void)fprintf (stream, "BEGIN:VEVENT\n");
|
||||||
(void)fprintf (stream, "DTSTART:%s\n", ical_date);
|
(void)fprintf (stream, "DTSTART:%s\n", ical_date);
|
||||||
(void)fprintf (stream, "SUMMARY:%s\n", i->mesg);
|
(void)fprintf (stream, "SUMMARY:%s\n", ev->mesg);
|
||||||
(void)fprintf (stream, "END:VEVENT\n");
|
(void)fprintf (stream, "END:VEVENT\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,11 +478,14 @@ ical_export_events (FILE *stream)
|
|||||||
static void
|
static void
|
||||||
pcal_export_events (FILE *stream)
|
pcal_export_events (FILE *stream)
|
||||||
{
|
{
|
||||||
struct event *i;
|
llist_item_t *i;
|
||||||
|
|
||||||
(void)fprintf (stream, "\n# ======\n# Events\n# ======\n");
|
(void)fprintf (stream, "\n# ======\n# Events\n# ======\n");
|
||||||
for (i = eventlist; i != NULL; i = i->next)
|
LLIST_FOREACH (&eventlist, i)
|
||||||
pcal_dump_event (stream, i->day, 0, i->mesg);
|
{
|
||||||
|
struct event *ev = LLIST_TS_GET_DATA (i);
|
||||||
|
pcal_dump_event (stream, ev->day, 0, ev->mesg);
|
||||||
|
}
|
||||||
(void)fprintf (stream, "\n");
|
(void)fprintf (stream, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -964,7 +968,6 @@ unsigned
|
|||||||
io_save_apts (void)
|
io_save_apts (void)
|
||||||
{
|
{
|
||||||
llist_item_t *i;
|
llist_item_t *i;
|
||||||
struct event *e;
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if ((fp = fopen (path_apts, "w")) == NULL)
|
if ((fp = fopen (path_apts, "w")) == NULL)
|
||||||
@ -982,8 +985,11 @@ io_save_apts (void)
|
|||||||
if (ui_mode == UI_CURSES)
|
if (ui_mode == UI_CURSES)
|
||||||
LLIST_TS_UNLOCK (&alist_p);
|
LLIST_TS_UNLOCK (&alist_p);
|
||||||
|
|
||||||
for (e = eventlist; e != NULL; e = e->next)
|
LLIST_FOREACH (&eventlist, i)
|
||||||
event_write (e, fp);
|
{
|
||||||
|
struct event *ev = LLIST_TS_GET_DATA (i);
|
||||||
|
event_write (ev, fp);
|
||||||
|
}
|
||||||
file_close (fp, __FILE_POS__);
|
file_close (fp, __FILE_POS__);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user