diff options
-rwxr-xr-x | ChangeLog | 5 | ||||
-rwxr-xr-x | src/apoint.c | 36 | ||||
-rwxr-xr-x | src/apoint.h | 6 | ||||
-rwxr-xr-x | src/day.c | 446 | ||||
-rwxr-xr-x | src/day.h | 5 | ||||
-rwxr-xr-x | src/event.c | 36 | ||||
-rwxr-xr-x | src/event.h | 7 | ||||
-rwxr-xr-x | src/io.c | 7 | ||||
-rwxr-xr-x | src/recur.c | 37 | ||||
-rwxr-xr-x | src/recur.h | 11 | ||||
-rwxr-xr-x | src/todo.c | 6 | ||||
-rwxr-xr-x | src/utils.c | 22 | ||||
-rwxr-xr-x | src/utils.h | 11 |
13 files changed, 353 insertions, 282 deletions
@@ -1,3 +1,8 @@ +20 Jan 2008: + day_edit_item() rewritten so that there is no need to first delete + the item and then recreate it + event_get() and apoint_get() added + 17 Jan 2008: exit_calcurse() improved: screen is now cleared completely when calcurse exits diff --git a/src/apoint.c b/src/apoint.c index 03573e6..380599a 100755 --- a/src/apoint.c +++ b/src/apoint.c @@ -1,4 +1,4 @@ -/* $calcurse: apoint.c,v 1.20 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: apoint.c,v 1.21 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -35,7 +35,6 @@ #include "apoint.h" #include "day.h" #include "custom.h" -#include "utils.h" #include "notify.h" #include "recur.h" #include "calendar.h" @@ -87,7 +86,7 @@ apoint_new(char *mesg, char *note, long start, long dur, char state) o = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t)); o->mesg = (char *) malloc(strlen(mesg) + 1); strncpy(o->mesg, mesg, strlen(mesg) + 1); - o->note = note; + o->note = (note != NULL) ? strdup(note) : NULL; o->state = state; o->start = start; o->dur = dur; @@ -240,7 +239,7 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints) if (go_for_deletion) { if (nb_items != 0) { deleted_item_type = - day_erase_item(date, hilt, 0); + day_erase_item(date, hilt, ERASE_DONT_FORCE); if (deleted_item_type == EVNT || deleted_item_type == RECUR_EVNT) { (*nb_events)--; @@ -363,8 +362,28 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note) return (apoint_new(buf, note, tstart, tend - tstart, state)); } +/* Retrieve an appointment from the list, given the day and item position. */ +apoint_llist_node_t * +apoint_get(long day, int pos) +{ + apoint_llist_node_t *o; + int n; + + n = 0; + for (o = alist_p->root; o; o = o->next) { + if (apoint_inday(o, day)) { + if (n == pos) + return o; + n++; + } + } + /* NOTREACHED */ + fputs(_("FATAL ERROR in apoint_get: no such item\n"), stderr); + exit(EXIT_FAILURE); +} + void -apoint_delete_bynum(long start, unsigned num, int only_note) +apoint_delete_bynum(long start, unsigned num, erase_flag_e flag) { unsigned n; int need_check_notify = 0; @@ -376,16 +395,15 @@ apoint_delete_bynum(long start, unsigned num, int only_note) for (i = alist_p->root; i != 0; i = i->next) { if (apoint_inday(i, start)) { if (n == num) { - if (only_note) - erase_note(&i->note); + if (flag == ERASE_FORCE_ONLY_NOTE) + erase_note(&i->note, flag); else { if (notify_bar()) need_check_notify = notify_same_item(i->start); *iptr = i->next; free(i->mesg); - if (i->note != NULL) - erase_note(&i->note); + erase_note(&i->note, flag); free(i); pthread_mutex_unlock(&(alist_p->mutex)); if (need_check_notify) diff --git a/src/apoint.h b/src/apoint.h index 3f5d704..9c1e7ef 100755 --- a/src/apoint.h +++ b/src/apoint.h @@ -1,4 +1,4 @@ -/* $calcurse: apoint.h,v 1.11 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: apoint.h,v 1.12 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,6 +27,7 @@ #ifndef CALCURSE_APOINT_H #define CALCURSE_APOINT_H +#include "utils.h" #include "notify.h" #include "recur.h" #include "vars.h" @@ -67,7 +68,8 @@ void apoint_sec2str(apoint_llist_node_t *, int, long, char *, char *); void apoint_write(apoint_llist_node_t *, FILE *); apoint_llist_node_t *apoint_scan(FILE *, struct tm, struct tm, char, char *); -void apoint_delete_bynum(long, unsigned, int); +apoint_llist_node_t *apoint_get(long, int); +void apoint_delete_bynum(long, unsigned, erase_flag_e); void apoint_scroll_pad_down(int, int); void apoint_scroll_pad_up(int); struct notify_app_s *apoint_check_next(struct notify_app_s *, long); @@ -1,4 +1,4 @@ -/* $calcurse: day.c,v 1.33 2008/01/17 19:35:42 culot Exp $ */ +/* $calcurse: day.c,v 1.34 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -31,7 +31,6 @@ #include <time.h> #include "i18n.h" -#include "utils.h" #include "apoint.h" #include "event.h" #include "custom.h" @@ -492,37 +491,6 @@ day_check_if_item(date_t day) return 0; } -/* Update an existing item. */ -static void -update_item(long date, int item_num, struct day_item_s *p, struct rpt_s *rpt) -{ - recur_apoint_llist_node_t *ra_new; - - day_erase_item(date, item_num, 1); - - switch (p->type) { - case RECUR_EVNT: - recur_event_new(p->mesg, p->note, p->start, p->evnt_id, - rpt->type, rpt->freq, rpt->until, NULL); - break; - case EVNT: - event_new(p->mesg, p->note, p->start, p->evnt_id); - break; - case RECUR_APPT: - ra_new = recur_apoint_new(p->mesg, p->note, p->start, - p->appt_dur, p->state, rpt->type, rpt->freq, rpt->until, - NULL); - if (notify_bar()) - notify_check_repeated(ra_new); - break; - case APPT: - apoint_new(p->mesg, p->note, p->start, p->appt_dur, p->state); - if (notify_bar()) - notify_check_added(p->mesg, p->start, p->state); - break; - } -} - /* Request the user to enter a new time. */ static char * day_edit_time(long time) @@ -541,15 +509,164 @@ day_edit_time(long time) status_mesg(fmt_msg, enter_str); wgetch(win[STA].p); } else - return timestr; + return (timestr); } } +static void +update_start_time(long *start, long *dur) +{ + long newtime; + unsigned hr, mn; + int valid_date; + char *timestr; + char *msg_wrong_time = + _("Invalid time: start time must be before end time!"); + char *msg_enter = _("Press [Enter] to continue"); + + do { + timestr = day_edit_time(*start); + sscanf(timestr, "%u:%u", &hr, &mn); + free(timestr); + newtime = update_time_in_date(*start, hr, mn); + if (newtime < *start + *dur) { + *dur -= (newtime - *start); + *start = newtime; + valid_date = 1; + } else { + status_mesg(msg_wrong_time, msg_enter); + wgetch(win[STA].p); + valid_date = 0; + } + } while (valid_date == 0); +} + +static void +update_duration(long *start, long *dur) +{ + long newtime; + unsigned hr, mn; + char *timestr; + + timestr = day_edit_time(*start + *dur); + sscanf(timestr, "%u:%u", &hr, &mn); + free(timestr); + newtime = update_time_in_date(*start, hr, mn); + *dur = (newtime > *start) ? newtime - *start : + DAYINSEC + newtime - *start; +} + +static void +update_desc(char **desc) +{ + status_mesg(_("Enter the new item description:"), ""); + updatestring(win[STA].p, desc, 0, 1); +} + +static void +update_rept(struct rpt_s **rpt, const long start) +{ + const int SINGLECHAR = 2; + int ch, cancel, newfreq, date_entered, valid_date; + long newuntil; + char *typstr, *freqstr, *timstr; + char *msg_rpt_type = + _("Enter the new repetition type: (D)aily, (W)eekly, " + "(M)onthly, (Y)early"); + char *msg_rpt_ans = _("[D/W/M/Y] "); + char *msg_wrong_freq = _("The frequence you entered is not valid."); + char *msg_wrong_time = + _("Invalid time: start time must be before end time!"); + char *msg_wrong_date = _("The entered date is not valid."); + char *msg_fmts = _("Possible formats are [mm/dd/yyyy] or '0' " + "for an endless repetetition"); + char *msg_enter = _("Press [Enter] to continue"); + + do { + status_mesg(msg_rpt_type, msg_rpt_ans); + typstr = (char *)malloc(sizeof(char) * SINGLECHAR); + snprintf(typstr, SINGLECHAR, "%c", recur_def2char((*rpt)->type)); + cancel = updatestring(win[STA].p, &typstr, 0, 1); + if (cancel) { + free(typstr); + return; + } else { + ch = toupper(*typstr); + free(typstr); + } + } while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y')); + + do { + status_mesg(_("Enter the new repetition frequence:"), ""); + freqstr = (char *)malloc(BUFSIZ); + snprintf(freqstr, BUFSIZ, "%d", (*rpt)->freq); + cancel = updatestring(win[STA].p, &freqstr, 0, 1); + if (cancel) { + free(freqstr); + return; + } else { + newfreq = atoi(freqstr); + free(freqstr); + if (newfreq == 0) { + status_mesg(msg_wrong_freq, msg_enter); + wgetch(win[STA].p); + } + } + } while (newfreq == 0); + + do { + status_mesg(_("Enter the new ending date: [mm/dd/yyyy] or '0'"), + ""); + timstr = date_sec2date_str((*rpt)->until); + cancel = updatestring(win[STA].p, &timstr, 0, 1); + if (cancel) { + free(timstr); + return; + } + if (strcmp(timstr, "0") == 0) { + newuntil = 0; + date_entered = 1; + } else { + struct tm *lt; + time_t t; + date_t new_date; + int newmonth, newday, newyear; + + valid_date = check_date(timstr); + if (valid_date) { + sscanf(timstr, "%d / %d / %d", + &newmonth, &newday, &newyear); + t = start; + lt = localtime(&t); + new_date.dd = newday; + new_date.mm = newmonth; + new_date.yyyy = newyear; + newuntil = date2sec(new_date, lt->tm_hour, + lt->tm_min); + if (newuntil < start) { + status_mesg(msg_wrong_time, msg_enter); + wgetch(win[STA].p); + date_entered = 0; + } else + date_entered = 1; + } else { + status_mesg(msg_wrong_date, msg_fmts); + wgetch(win[STA].p); + date_entered = 0; + } + } + } while (date_entered == 0); + + free(timstr); + (*rpt)->type = recur_char2def(ch); + (*rpt)->freq = newfreq; + (*rpt)->until = newuntil; +} + /* Edit an already existing item. */ void day_edit_item(void) { -#define SINGLECHAR 2 #define STRT '1' #define END '2' #define DESC '3' @@ -557,188 +674,86 @@ day_edit_item(void) struct day_item_s *p; struct recur_event_s *re; - struct rpt_s *rpt = 0L; - struct tm *lt; - time_t t; - date_t new_date; + struct event_s *e; recur_apoint_llist_node_t *ra; - long date, newtime = 0; - int cancel, ch = 0, valid_date = 0, newfreq = 0, date_entered = 0; - int newmonth, newday, newyear; - int item_num; - unsigned hr, mn; - char *timestr, *typestr, *freqstr; - char *msg_norecur = - _("Edit: (1)Start time, (2)End time or (3)Description?"); - char *choice_norecur = "[1/2/3] "; - char *msg_recur = - _("Edit: (1)Start time, (2)End time, (3)Description or (4)Repetition?"); - char *msg_event_recur = - _("Edit: (1)Description or (2)Repetition?"); - char *choice_recur = "[1/2/3/4] "; - char *choice_event_recur = "[1/2] "; - char *mesg_wrong_date = _("The entered date is not valid."); - char *mesg_possible_fmts = - _("Possible formats are [mm/dd/yyyy] or '0' for an endless repetetition"); - char *error_msg = - _("Invalid time: start time must be before end time!"); - char *enter_str = _("Press [Enter] to continue"); - char *mesg_desc = _("Enter the new item description:"); - char *mesg_type_1 = - _("Enter the new repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early"); - char *mesg_type_2 = _("[D/W/M/Y] "); - char *mesg_freq_1 = _("Enter the new repetition frequence:"); - char *mesg_wrong_freq = _("The frequence you entered is not valid."); - char *mesg_until_1 = - _("Enter the new ending date: [mm/dd/yyyy] or '0'"); + apoint_llist_node_t *a; + long date; + int item_num, ch; item_num = apoint_hilt(); p = day_get_item(item_num); date = calendar_get_slctd_day_sec(); + ch = 0; switch (p->type) { case RECUR_EVNT: re = recur_get_event(date, day_item_nb(date, item_num, RECUR_EVNT)); - rpt = re->rpt; - status_mesg(msg_event_recur, choice_event_recur); - while (ch != STRT && ch != END && ch != ESCAPE) + status_mesg(_("Edit: (1)Description or (2)Repetition?"), + "[1/2] "); + while (ch != '1' && ch != '2' && ch != ESCAPE) ch = wgetch(win[STA].p); - if (ch == ESCAPE) + switch (ch) { + case '1': + update_desc(&re->mesg); + break; + case '2': + update_rept(&re->rpt, re->day); + break; + default: return; - else - ch += 2; + } break; case EVNT: - ch = DESC; + e = event_get(date, day_item_nb(date, item_num, EVNT)); + update_desc(&e->mesg); break; case RECUR_APPT: ra = recur_get_apoint(date, day_item_nb(date, item_num, RECUR_APPT)); - rpt = ra->rpt; - status_mesg(msg_recur, choice_recur); + status_mesg(_("Edit: (1)Start time, (2)End time, " + "(3)Description or (4)Repetition?"), "[1/2/3/4] "); while (ch != STRT && ch != END && ch != DESC && - ch != REPT && ch != ESCAPE) + ch != REPT && ch != ESCAPE) ch = wgetch(win[STA].p); - if (ch == ESCAPE) + switch (ch) { + case STRT: + update_start_time(&ra->start, &ra->dur); + break; + case END: + update_duration(&ra->start, &ra->dur); + break; + case DESC: + update_desc(&ra->mesg); + break; + case REPT: + update_rept(&ra->rpt, ra->start); + break; + case ESCAPE: return; + } break; case APPT: - status_mesg(msg_norecur, choice_norecur); - while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE) + a = apoint_get(date, day_item_nb(date, item_num, APPT)); + status_mesg(_("Edit: (1)Start time, (2)End time " + "or (3)Description?"), "[1/2/3] "); + while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE) ch = wgetch(win[STA].p); - if (ch == ESCAPE) + switch (ch) { + case STRT: + update_start_time(&a->start, &a->dur); + break; + case END: + update_duration(&a->start, &a->dur); + break; + case DESC: + update_desc(&a->mesg); + break; + case ESCAPE: return; - break; - } - - switch (ch) { - case STRT: - while (!valid_date) { - timestr = day_edit_time(p->start); - sscanf(timestr, "%u:%u", &hr, &mn); - free(timestr); - newtime = update_time_in_date(p->start, hr, mn); - if (newtime < p->start + p->appt_dur) { - p->appt_dur -= (newtime - p->start); - p->start = newtime; - valid_date = 1; - } else { - status_mesg(error_msg, enter_str); - wgetch(win[STA].p); - } } break; - case END: - while (!valid_date) { - timestr = day_edit_time( - p->start + p->appt_dur); - sscanf(timestr, "%u:%u", &hr, &mn); - free(timestr); - newtime = update_time_in_date(p->start, hr, mn); - p->appt_dur = (newtime > p->start) ? - newtime - p->start : - DAYINSEC + newtime - p->start; - valid_date = 1; - } - break; - case DESC: - status_mesg(mesg_desc, ""); - updatestring(win[STA].p, &p->mesg, 0, 1); - break; - case REPT: - while ( (ch != 'D') && (ch != 'W') && (ch != 'M') - && (ch != 'Y') ) { - status_mesg(mesg_type_1, mesg_type_2); - typestr = (char *)malloc(sizeof(char) * SINGLECHAR); - snprintf(typestr, SINGLECHAR, "%c", - recur_def2char(rpt->type)); - cancel = updatestring(win[STA].p, &typestr, 0, 1); - ch = toupper(*typestr); - free(typestr); - if (cancel) - return; - } - while (newfreq == 0) { - status_mesg(mesg_freq_1, ""); - freqstr = (char *) malloc(BUFSIZ); - snprintf(freqstr, BUFSIZ, "%d", rpt->freq); - cancel = updatestring(win[STA].p, &freqstr, 0, 1); - newfreq = atoi(freqstr); - free(freqstr); - if (cancel) - return; - else { - if (newfreq == 0) { - status_mesg(mesg_wrong_freq, enter_str); - wgetch(win[STA].p); - } - } - } - while (!date_entered) { - status_mesg(mesg_until_1, ""); - timestr = date_sec2date_str(rpt->until); - cancel = updatestring(win[STA].p, ×tr, 0, 1); - if (cancel) { - free(timestr); - return; - } - if (strlen(timestr) == 1 && - strncmp(timestr, "0", 1) == 0 ) { - rpt->until = 0; - date_entered = 1; - } else { - valid_date = check_date(timestr); - if (valid_date) { - sscanf(timestr, "%d / %d / %d", - &newmonth, &newday, &newyear); - t = p->start; lt = localtime(&t); - new_date.dd = newday; - new_date.mm = newmonth; - new_date.yyyy = newyear; - rpt->until = date2sec(new_date, - lt->tm_hour, lt->tm_min); - if (rpt->until < p->start) { - status_mesg(error_msg, - enter_str); - wgetch(win[STA].p); - date_entered = 0; - } else - date_entered = 1; - } else { - status_mesg(mesg_wrong_date, - mesg_possible_fmts); - wgetch(win[STA].p); - date_entered = 0; - } - } - } - free(timestr); - rpt->freq = newfreq; - rpt->type = recur_char2def(ch); - break; } - update_item(date, item_num, p, rpt); } /* @@ -748,7 +763,7 @@ day_edit_item(void) * type of the item to be deleted. */ int -day_erase_item(long date, int item_number, int force_erase) +day_erase_item(long date, int item_number, erase_flag_e flag) { struct day_item_s *p; char *erase_warning = @@ -759,35 +774,31 @@ day_erase_item(long date, int item_number, int force_erase) "Delete (i)tem or just its (n)ote ?"); char *note_choice = _("[i/n] "); char *erase_choice = _("[a/o] "); - int ch = 0, only_note, has_note, ans = 0; + int ch = 0, ans; unsigned delete_whole; p = day_get_item(item_number); - if (force_erase) { - ch = 'a'; - only_note = 0; - } else { - has_note = (p->note != NULL ) ? 1 : 0; - if (has_note == 0) + if (flag == ERASE_DONT_FORCE) { + ans = 0; + if (p->note == NULL) ans = 'i'; while (ans != 'i' && ans != 'n') { status_mesg(note_warning, note_choice); ans = wgetch(win[STA].p); } if (ans == 'i') - only_note = 0; + flag = ERASE_FORCE; else - only_note = 1; + flag = ERASE_FORCE_ONLY_NOTE; } - if (p->type == EVNT) { event_delete_bynum(date, day_item_nb(date, item_number, EVNT), - only_note); + flag); } else if (p->type == APPT) { apoint_delete_bynum(date, day_item_nb(date, item_number, APPT), - only_note); + flag); } else { - if (only_note) + if (flag == ERASE_FORCE_ONLY_NOTE) ch = 'a'; while ( (ch != 'a') && (ch != 'o') && (ch != ESCAPE)) { status_mesg(erase_warning, erase_choice); @@ -803,10 +814,10 @@ day_erase_item(long date, int item_number, int force_erase) if (p->type == RECUR_EVNT) { recur_event_erase(date, day_item_nb(date, item_number, RECUR_EVNT), - delete_whole, only_note); + delete_whole, flag); } else { recur_apoint_erase(date, p->appt_pos, delete_whole, - only_note); + flag); } } return (p->type); @@ -851,8 +862,9 @@ day_edit_note(char *editor) { struct day_item_s *p; recur_apoint_llist_node_t *ra; + apoint_llist_node_t *a; struct recur_event_s *re; - struct rpt_s *rpt; + struct event_s *e; char fullname[BUFSIZ]; char *filename; long date; @@ -861,11 +873,10 @@ day_edit_note(char *editor) item_num = apoint_hilt(); p = day_get_item(item_num); if (p->note == NULL) { - if ((filename = new_tempfile(path_notes, NOTESIZ)) - != NULL) - p->note = filename; - else + if ((filename = new_tempfile(path_notes, NOTESIZ)) == NULL) return; + else + p->note = filename; } snprintf(fullname, BUFSIZ, "%s%s", path_notes, p->note); wins_launch_external(fullname, editor); @@ -875,17 +886,22 @@ day_edit_note(char *editor) case RECUR_EVNT: re = recur_get_event(date, day_item_nb(date, item_num, RECUR_EVNT)); - rpt = re->rpt; + re->note = p->note; + break; + case EVNT: + e = event_get(date, day_item_nb(date, item_num, EVNT)); + e->note = p->note; break; case RECUR_APPT: ra = recur_get_apoint(date, day_item_nb(date, item_num, RECUR_APPT)); - rpt = ra->rpt; + ra->note = p->note; + break; + case APPT: + a = apoint_get(date, day_item_nb(date, item_num, APPT)); + a->note = p->note; break; - default: - rpt = NULL; } - update_item(date, item_num, p, rpt); } /* View a note previously attached to an appointment or event */ @@ -1,4 +1,4 @@ -/* $calcurse: day.h,v 1.16 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: day.h,v 1.17 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,6 +27,7 @@ #ifndef CALCURSE_DAY_H #define CALCURSE_DAY_H +#include "utils.h" #include "calendar.h" #define MAX_TYPES 4 @@ -66,7 +67,7 @@ void day_write_pad(long, int, int, int); void day_popup_item(void); int day_check_if_item(date_t); void day_edit_item(void); -int day_erase_item(long, int, int); +int day_erase_item(long, int, erase_flag_e); struct day_item_s *day_get_item(int); int day_item_nb(long, int, int); void day_edit_note(char *); diff --git a/src/event.c b/src/event.c index 919d71a..47da756 100755 --- a/src/event.c +++ b/src/event.c @@ -1,4 +1,4 @@ -/* $calcurse: event.c,v 1.5 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: event.c,v 1.6 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -31,7 +31,6 @@ #include "vars.h" #include "i18n.h" -#include "utils.h" #include "event.h" struct event_s *eventlist; @@ -46,7 +45,7 @@ event_new(char *mesg, char *note, long day, int id) strncpy(o->mesg, mesg, strlen(mesg) + 1); o->day = day; o->id = id; - o->note = note; + o->note = (note != NULL) ? strdup(note) : NULL; i = &eventlist; for (;;) { if (*i == 0 || (*i)->day > day) { @@ -117,9 +116,29 @@ event_scan(FILE * f, struct tm start, int id, char *note) return (event_new(buf, note, tstart, id)); } -/* Delete an event from the list */ +/* Retrieve an event from the list, given the day and item position. */ +struct event_s * +event_get(long day, int pos) +{ + struct event_s *o; + int n; + + n = 0; + for (o = eventlist; o; o = o->next) { + if (event_inday(o, day)) { + if (n == pos) + return o; + n++; + } + } + /* NOTREACHED */ + fputs(_("FATAL ERROR in event_get: no such item\n"), stderr); + exit(EXIT_FAILURE); +} + +/* Delete an event from the list. */ void -event_delete_bynum(long start, unsigned num, int only_note) +event_delete_bynum(long start, unsigned num, erase_flag_e flag) { unsigned n; struct event_s *i, **iptr; @@ -129,13 +148,12 @@ event_delete_bynum(long start, unsigned num, int only_note) for (i = eventlist; i != 0; i = i->next) { if (event_inday(i, start)) { if (n == num) { - if (only_note) - erase_note(&i->note); + if (flag == ERASE_FORCE_ONLY_NOTE) + erase_note(&i->note, flag); else { *iptr = i->next; free(i->mesg); - if (i->note != NULL) - erase_note(&i->note); + erase_note(&i->note, flag); free(i); } return; diff --git a/src/event.h b/src/event.h index 2fa8908..1de4306 100755 --- a/src/event.h +++ b/src/event.h @@ -1,4 +1,4 @@ -/* $calcurse: event.h,v 1.4 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: event.h,v 1.5 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -27,6 +27,8 @@ #ifndef CALCURSE_EVENT_H #define CALCURSE_EVENT_H +#include "utils.h" + #define HRMIN_SIZE 6 #define MESG_MAXSIZE 256 @@ -44,6 +46,7 @@ struct event_s *event_new(char *, char *, long, int); unsigned event_inday(struct event_s *, long); void event_write(struct event_s *, FILE *); struct event_s *event_scan(FILE *, struct tm, int, char *); -void event_delete_bynum(long, unsigned, int); +struct event_s *event_get(long, int); +void event_delete_bynum(long, unsigned, erase_flag_e); #endif /* CALCURSE_EVENT_H */ @@ -1,4 +1,4 @@ -/* $calcurse: io.c,v 1.26 2008/01/17 19:35:42 culot Exp $ */ +/* $calcurse: io.c,v 1.27 2008/01/20 10:45:38 culot Exp $ */ /* * Calcurse - text-based organizer @@ -654,7 +654,7 @@ io_load_app(void) if (c == '>') { fgets(note, NOTESIZ + 1, data_file); note[NOTESIZ] = '\0'; - notep = strdup(note); + notep = note; getc(data_file); } else { notep = NULL; @@ -680,7 +680,8 @@ io_load_app(void) recur_apoint_scan(data_file, start, end, type, freq, until, notep, exc, state); } else { - apoint_scan(data_file, start, end, state, notep); + apoint_scan(data_file, start, end, state, + notep); } } else if (is_event) { if (is_recursive) { diff --git a/src/recur.c b/src/recur.c index 6683310..740f10b 100755 --- a/src/recur.c +++ b/src/recur.c @@ -1,4 +1,4 @@ -/* $calcurse: recur.c,v 1.32 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: recur.c,v 1.33 2008/01/20 10:45:39 culot Exp $ */ /* * Calcurse - text-based organizer @@ -51,7 +51,7 @@ recur_apoint_llist_init(void) } /* Insert a new recursive appointment in the general linked list */ -recur_apoint_llist_node_t * +static recur_apoint_llist_node_t * recur_apoint_new(char *mesg, char *note, long start, long dur, char state, int type, int freq, long until, struct days_s *except) { @@ -62,7 +62,7 @@ recur_apoint_new(char *mesg, char *note, long start, long dur, char state, o->mesg = (char *) malloc(strlen(mesg) + 1); o->exc = (struct days_s *) malloc(sizeof(struct days_s)); strncpy(o->mesg, mesg, strlen(mesg) + 1); - o->note = note; + o->note = (note != NULL) ? strdup(note) : NULL; o->start = start; o->state = state; o->dur = dur; @@ -87,7 +87,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_s * +static struct recur_event_s * recur_event_new(char *mesg, char *note, long day, int id, int type, int freq, long until, struct days_s *except) { @@ -95,7 +95,7 @@ recur_event_new(char *mesg, char *note, long day, int id, int type, int freq, o = (struct recur_event_s *) malloc(sizeof(struct recur_event_s)); o->rpt = (struct rpt_s *) malloc(sizeof(struct rpt_s)); o->mesg = (char *) malloc(strlen(mesg) + 1); - o->note = note; + o->note = (note != NULL) ? strdup(note) : NULL; o->exc = (struct days_s *) malloc(sizeof(struct days_s)); strncpy(o->mesg, mesg, strlen(mesg) + 1); o->day = day; @@ -278,7 +278,8 @@ struct tm until, char *note, struct days_s *exc) } tstart = mktime(&start); if ( (tstart == -1) || (tuntil == -1) ) { - fputs(_("FATAL ERROR in recur_event_scan: date error in the event\n"), stderr); + fputs(_("FATAL ERROR in recur_event_scan: " + "date error in the event\n"), stderr); exit(EXIT_FAILURE); } @@ -473,7 +474,8 @@ recur_item_inday(long item_start, struct days_s *item_exc, int rpt_type, * or delete only one occurence of the recurrent event. */ void -recur_event_erase(long start, unsigned num, unsigned delete_whole, int only_note) +recur_event_erase(long start, unsigned num, unsigned delete_whole, + erase_flag_e flag) { unsigned n = 0; struct recur_event_s *i, **iptr; @@ -485,15 +487,14 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole, int only_note i->rpt->freq, i->rpt->until, start)) { if (n == num) { if (delete_whole) { - if (only_note) - erase_note(&i->note); + if (flag == ERASE_FORCE_ONLY_NOTE) + erase_note(&i->note, flag); else { *iptr = i->next; free(i->mesg); free(i->rpt); free(i->exc); - if (i->note != NULL) - erase_note(&i->note); + erase_note(&i->note, flag); free(i); } return; @@ -529,7 +530,7 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole, int only_note */ void recur_apoint_erase(long start, unsigned num, unsigned delete_whole, - int only_note) + erase_flag_e flag) { unsigned n = 0; recur_apoint_llist_node_t *i, **iptr; @@ -542,19 +543,19 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole, if (recur_item_inday(i->start, i->exc, i->rpt->type, i->rpt->freq, i->rpt->until, start)) { if (n == num) { - if (notify_bar() && only_note != 0) + if (notify_bar() && + flag != ERASE_FORCE_ONLY_NOTE) need_check_notify = notify_same_recur_item(i); if (delete_whole) { - if (only_note) - erase_note(&i->note); + if (flag == ERASE_FORCE_ONLY_NOTE) + erase_note(&i->note, flag); else { *iptr = i->next; free(i->mesg); free(i->rpt); free(i->exc); - if (i->note != NULL) - erase_note(&i->note); + erase_note(&i->note, flag); free(i); pthread_mutex_unlock( &(recur_alist_p->mutex)); @@ -704,7 +705,6 @@ recur_repeat_item(void) } date = calendar_get_slctd_day_sec(); - day_erase_item(date, item_nb, 0); if (p->type == EVNT) { re = recur_event_new(p->mesg, p->note, p->start, p->evnt_id, type, freq, until, NULL); @@ -718,6 +718,7 @@ recur_repeat_item(void) stderr); exit(EXIT_FAILURE); } + day_erase_item(date, item_nb, ERASE_FORCE_KEEP_NOTE); } /* diff --git a/src/recur.h b/src/recur.h index 01b8840..e039656 100755 --- a/src/recur.h +++ b/src/recur.h @@ -1,4 +1,4 @@ -/* $calcurse: recur.h,v 1.16 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: recur.h,v 1.17 2008/01/20 10:45:39 culot Exp $ */ /* * Calcurse - text-based organizer @@ -76,10 +76,6 @@ extern recur_apoint_llist_t *recur_alist_p; extern struct recur_event_s *recur_elist; int recur_apoint_llist_init(void); -recur_apoint_llist_node_t *recur_apoint_new(char *, char *, long, long, - char, int, int, long, struct days_s *); -struct recur_event_s *recur_event_new(char *, char *, long, int, int, - int, long, struct days_s *); char recur_def2char(recur_types_t); int recur_char2def(char); recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm, @@ -90,9 +86,10 @@ struct recur_event_s *recur_event_scan(FILE *, struct tm, int, char, void recur_save_data(FILE *); unsigned recur_item_inday(long, struct days_s *, int, int, long, long); -void recur_event_erase(long, unsigned, unsigned, int); +void recur_event_erase(long, unsigned, unsigned, + erase_flag_e); void recur_apoint_erase(long, unsigned, unsigned, - int); + erase_flag_e); void recur_repeat_item(void); struct days_s *recur_exc_scan(FILE *); struct notify_app_s *recur_apoint_check_next(struct notify_app_s *, @@ -1,4 +1,4 @@ -/* $calcurse: todo.c,v 1.18 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: todo.c,v 1.19 2008/01/20 10:45:39 culot Exp $ */ /* * Calcurse - text-based organizer @@ -188,7 +188,7 @@ todo_delete_note_bynum(unsigned num) ierror( _("FATAL ERROR in todo_delete_note_bynum: " "no note attached\n"), IERROR_FATAL); - erase_note(&i->note); + erase_note(&i->note, ERASE_FORCE_ONLY_NOTE); return; } iptr = &i->next; @@ -214,7 +214,7 @@ todo_delete_bynum(unsigned num) *iptr = i->next; free(i->mesg); if (i->note != NULL) - erase_note(&i->note); + erase_note(&i->note, ERASE_FORCE); free(i); return; } diff --git a/src/utils.c b/src/utils.c index 0e9cc4d..bad5d88 100755 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,4 @@ -/* $calcurse: utils.c,v 1.40 2008/01/17 19:35:42 culot Exp $ */ +/* $calcurse: utils.c,v 1.41 2008/01/20 10:45:39 culot Exp $ */ /* * Calcurse - text-based organizer @@ -44,9 +44,9 @@ static unsigned status_page; void exit_calcurse(int status) { - endwin(); clear(); refresh(); + endwin(); calendar_stop_date_thread(); exit(status); } @@ -569,7 +569,8 @@ date_sec2ical_datetime(long sec, char *ical_datetime) * Return a long containing the date which is updated taking into account * the new time and date entered by the user. */ -long update_time_in_date(long date, unsigned hr, unsigned mn) +long +update_time_in_date(long date, unsigned hr, unsigned mn) { struct tm *lt; time_t t, new_date; @@ -904,17 +905,18 @@ new_tempfile(const char *prefix, int trailing_len) /* Erase a note previously attached to a todo, event or appointment. */ void -erase_note(char **note) +erase_note(char **note, erase_flag_e flag) { char fullname[BUFSIZ]; + char *errmsg = _("FATAL ERROR in erase_note: could not remove note\n"); if (*note == NULL) - ierror(_("FATAL ERROR in erase_note: null pointer!\n"), - IERROR_FATAL); - snprintf(fullname, BUFSIZ, "%s%s", path_notes, *note); - if (unlink(fullname) != 0) - ierror(_("FATAL ERROR in erase_note: could not remove note\n"), - IERROR_FATAL); + return; + if (flag != ERASE_FORCE_KEEP_NOTE) { + snprintf(fullname, BUFSIZ, "%s%s", path_notes, *note); + if (unlink(fullname) != 0) + ierror(errmsg, IERROR_FATAL); + } free(*note); *note = NULL; } diff --git a/src/utils.h b/src/utils.h index 69b2d09..a52deb8 100755 --- a/src/utils.h +++ b/src/utils.h @@ -1,4 +1,4 @@ -/* $calcurse: utils.h,v 1.25 2008/01/13 12:40:45 culot Exp $ */ +/* $calcurse: utils.h,v 1.26 2008/01/20 10:45:39 culot Exp $ */ /* * Calcurse - text-based organizer @@ -61,6 +61,13 @@ typedef enum { IERROR_WARN } ierror_sev_e; +typedef enum { + ERASE_DONT_FORCE, + ERASE_FORCE, + ERASE_FORCE_KEEP_NOTE, + ERASE_FORCE_ONLY_NOTE +} erase_flag_e; + void exit_calcurse(int); void ierror(const char *, ierror_sev_e); void aerror(const char *, int, const char *); @@ -93,6 +100,6 @@ char *mycpy(const char *); long mystrtol(const char *); void print_option_incolor(WINDOW *, bool, int, int); char *new_tempfile(const char *, int); -void erase_note(char **); +void erase_note(char **, erase_flag_e); #endif /* CALCURSE_UTILS_H */ |