diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-24 22:46:26 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-30 21:10:53 +0200 |
commit | 13a41f8e0a722f4491ad6256718227e7161b5896 (patch) | |
tree | 476b3f0abd18dcb2ccdfe47b103af3047e9ce905 | |
parent | 709525cf8d545f039e99a033068c1242a3bc4a31 (diff) | |
download | calcurse-13a41f8e0a722f4491ad6256718227e7161b5896.tar.gz calcurse-13a41f8e0a722f4491ad6256718227e7161b5896.zip |
Fix sort order in app_arg()
We used to iterate over the list of regular appointments and the list of
recurrent appointments in separate loops, thus leading to recurrent
appointments being printed first and regular appointments being printed
afterwards, regardless of their start and end times. Merge these loops
to coerce precedence of the start time.
There's still a fair bit of hackery in here - we will fix that later.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r-- | src/args.c | 130 |
1 files changed, 78 insertions, 52 deletions
@@ -351,7 +351,7 @@ static int app_arg (int add_line, struct date *day, long date, int print_note, struct conf *conf, regex_t *regex) { - llist_item_t *i; + llist_item_t *i, *j; long today; unsigned print_date = 1; int app_found = 0; @@ -417,72 +417,98 @@ app_arg (int add_line, struct date *day, long date, int print_note, } /* Same process is performed but this time on the appointments. */ + LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK (&recur_alist_p); - LLIST_TS_FIND_FOREACH (&recur_alist_p, today, recur_apoint_inday, i) - { - struct recur_apoint *ra = LLIST_TS_GET_DATA (i); - struct apoint *apt; - if (regex && regexec (regex, ra->mesg, 0, 0, 0) != 0) - continue; + /* + * Iterate over regular appointments and recurrent ones simultaneously (fixes + * http://lists.calcurse.org/bugs/msg00002.html). + */ + i = LLIST_TS_FIND_FIRST (&alist_p, today, apoint_inday); + j = LLIST_TS_FIND_FIRST (&recur_alist_p, today, recur_apoint_inday); + while (i || j) + { + struct apoint *apt = LLIST_TS_GET_DATA (i); + struct recur_apoint *ra = LLIST_TS_GET_DATA (j); - app_found = 1; - if (add_line) + while (i && regex && regexec (regex, apt->mesg, 0, 0, 0) != 0) { - fputs ("\n", stdout); - add_line = 0; + i = LLIST_TS_FIND_NEXT (i, today, apoint_inday); + apt = LLIST_TS_GET_DATA (i); } - if (print_date) + + while (j && regex && regexec (regex, ra->mesg, 0, 0, 0) != 0) { - arg_print_date (today, conf); - print_date = 0; + j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday); + ra = LLIST_TS_GET_DATA (j); } - apt = apoint_recur_s2apoint_s (ra); - apoint_sec2str (apt, RECUR_APPT, today, apoint_start_time, - apoint_end_time); - mem_free (apt->mesg); - mem_free (apt); - fputs (" - ", stdout); - fputs (apoint_start_time, stdout); - fputs (" -> ", stdout); - fputs (apoint_end_time, stdout); - fputs ("\n\t", stdout); - fputs (ra->mesg, stdout); - fputs ("\n", stdout); - if (print_note && ra->note) - print_notefile (stdout, ra->note, 2); - } - LLIST_TS_UNLOCK (&recur_alist_p); - LLIST_TS_LOCK (&alist_p); - LLIST_TS_FIND_FOREACH (&alist_p, today, apoint_inday, i) - { - struct apoint *apt = LLIST_TS_GET_DATA (i); - if (regex && regexec (regex, apt->mesg, 0, 0, 0) != 0) - continue; + if (apt && ra) + { + if (apt->start <= recur_apoint_inday (ra, today)) + ra = NULL; + else + apt = NULL; + } - app_found = 1; - if (add_line) + if (apt) { + app_found = 1; + if (add_line) + { + fputs ("\n", stdout); + add_line = 0; + } + if (print_date) + { + arg_print_date (today, conf); + print_date = 0; + } + apoint_sec2str (apt, APPT, today, apoint_start_time, apoint_end_time); + fputs (" - ", stdout); + fputs (apoint_start_time, stdout); + fputs (" -> ", stdout); + fputs (apoint_end_time, stdout); + fputs ("\n\t", stdout); + fputs (apt->mesg, stdout); fputs ("\n", stdout); - add_line = 0; + if (print_note && apt->note) + print_notefile (stdout, apt->note, 2); + i = LLIST_TS_FIND_NEXT (i, today, apoint_inday); } - if (print_date) + else if (ra) { - arg_print_date (today, conf); - print_date = 0; + app_found = 1; + if (add_line) + { + fputs ("\n", stdout); + add_line = 0; + } + if (print_date) + { + arg_print_date (today, conf); + print_date = 0; + } + apt = apoint_recur_s2apoint_s (ra); + apoint_sec2str (apt, RECUR_APPT, today, apoint_start_time, + apoint_end_time); + mem_free (apt->mesg); + mem_free (apt); + fputs (" - ", stdout); + fputs (apoint_start_time, stdout); + fputs (" -> ", stdout); + fputs (apoint_end_time, stdout); + fputs ("\n\t", stdout); + fputs (ra->mesg, stdout); + fputs ("\n", stdout); + if (print_note && ra->note) + print_notefile (stdout, ra->note, 2); + apt = NULL; + j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday); } - apoint_sec2str (apt, APPT, today, apoint_start_time, apoint_end_time); - fputs (" - ", stdout); - fputs (apoint_start_time, stdout); - fputs (" -> ", stdout); - fputs (apoint_end_time, stdout); - fputs ("\n\t", stdout); - fputs (apt->mesg, stdout); - fputs ("\n", stdout); - if (print_note && apt->note) - print_notefile (stdout, apt->note, 2); } + + LLIST_TS_UNLOCK (&recur_alist_p); LLIST_TS_UNLOCK (&alist_p); return (app_found); |