diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/args.c | 11 | ||||
-rw-r--r-- | src/calcurse.h | 29 | ||||
-rw-r--r-- | src/day.c | 36 | ||||
-rw-r--r-- | src/ical.c | 30 | ||||
-rw-r--r-- | src/notify.c | 5 | ||||
-rw-r--r-- | src/recur.c | 8 | ||||
-rw-r--r-- | src/ui-calendar.c | 2 | ||||
-rw-r--r-- | src/ui-day.c | 11 | ||||
-rw-r--r-- | src/utils.c | 26 |
9 files changed, 69 insertions, 89 deletions
@@ -310,7 +310,7 @@ date_arg_from_to(long from, long to, int add_line, const char *fmt_apt, } } -static long parse_datearg(const char *str) +static time_t parse_datearg(const char *str) { struct date day; @@ -329,12 +329,12 @@ static long parse_datearg(const char *str) return LONG_MAX; } -static long parse_datetimearg(const char *str) +static time_t parse_datetimearg(const char *str) { char *date = mem_strdup(str); char *time; unsigned hour, min; - long ret; + time_t ret; time = strchr(date, ' '); if (time) { @@ -363,7 +363,7 @@ static long parse_datetimearg(const char *str) return ret; } -static int parse_daterange(const char *str, long *date_from, long *date_to) +static int parse_daterange(const char *str, time_t *date_from, time_t *date_to) { int ret = 0; char *s = xstrdup(str); @@ -438,7 +438,8 @@ int parse_args(int argc, char **argv) int grep = 0, query = 0, next = 0; int status = 0, gc = 0, import = 0, export = 0; /* Query ranges */ - long from = -1, range = -1, to = -1; + time_t from = -1, to = -1; + int range = -1; int limit = INT_MAX; /* Filters */ struct item_filter filter = { 0, NULL, -1, -1, -1, -1, 0, 0, 0 }; diff --git a/src/calcurse.h b/src/calcurse.h index ebb3eb8..a1b59cf 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -406,10 +406,10 @@ enum item_type { struct item_filter { int type_mask; regex_t *regex; - long start_from; - long start_to; - long end_from; - long end_to; + time_t start_from; + time_t start_to; + time_t end_from; + time_t end_to; int priority; int completed; int uncompleted; @@ -699,7 +699,7 @@ unsigned ui_calendar_week_begins_on_monday(void); void ui_calendar_store_current_date(struct date *); void ui_calendar_init_slctd_day(void); struct date *ui_calendar_get_slctd_day(void); -long ui_calendar_get_slctd_day_sec(void); +time_t ui_calendar_get_slctd_day_sec(void); void ui_calendar_monthly_view_cache_set_invalid(void); void ui_calendar_update_panel(void); void ui_calendar_goto_today(void); @@ -954,11 +954,9 @@ void recur_apoint_write(struct recur_apoint *, FILE *); void recur_event_write(struct recur_event *, FILE *); void recur_save_data(FILE *); unsigned recur_item_find_occurrence(long, long, llist_t *, int, - int, long, long, unsigned *); -unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, - unsigned *); -unsigned recur_event_find_occurrence(struct recur_event *, long, - unsigned *); + int, long, long, time_t *); +unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, time_t *); +unsigned recur_event_find_occurrence(struct recur_event *, long, time_t *); 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 *); @@ -1053,17 +1051,17 @@ int is_all_digit(const char *); long get_item_time(long); int get_item_hour(long); int get_item_min(long); -long date2sec(struct date, unsigned, unsigned); -long utcdate2sec(struct date, unsigned, unsigned); +time_t date2sec(struct date, unsigned, unsigned); +time_t utcdate2sec(struct date, unsigned, unsigned); char *date_sec2date_str(long, const char *); void date_sec2date_fmt(long, const char *, char *); long date_sec_change(long, int, int); long update_time_in_date(long, unsigned, unsigned); -long get_sec_date(struct date); +time_t get_sec_date(struct date); long min2sec(unsigned); void draw_scrollbar(WINDOW *, int, int, int, int, int, unsigned); void item_in_popup(const char *, const char *, const char *, const char *); -long get_today(void); +time_t get_today(void); long now(void); char *nowstr(void); void print_bool_option_incolor(WINDOW *, unsigned, int, int); @@ -1083,8 +1081,7 @@ int child_wait(int *, int *, int); void press_any_key(void); void print_apoint(const char *, long, struct apoint *); void print_event(const char *, long, struct event *); -void print_recur_apoint(const char *, long, unsigned, - struct recur_apoint *); +void print_recur_apoint(const char *, long, time_t, struct recur_apoint *); void print_recur_event(const char *, long, struct recur_event *); void print_todo(const char *, struct todo *); int vasprintf(char **, const char *, va_list); @@ -308,7 +308,7 @@ static int day_store_recur_apoints(long date) p.rapt = rapt; - unsigned real_start; + time_t real_start; if (recur_apoint_find_occurrence(rapt, date, &real_start)) { day_add_item(RECUR_APPT, real_start, p); a_nb++; @@ -358,7 +358,6 @@ day_store_items(long date, int include_captions) */ void day_process_storage(struct date *slctd_date, unsigned day_changed) { - long date; struct date day; if (slctd_date) @@ -366,14 +365,12 @@ void day_process_storage(struct date *slctd_date, unsigned day_changed) else ui_calendar_store_current_date(&day); - date = date2sec(day, 0, 0); - /* Inits */ if (apad.length != 0) delwin(apad.ptrwin); /* Store the events and appointments (recursive and normal items). */ - day_store_items(date, 1); + day_store_items(date2sec(day, 0, 0), 1); } /* @@ -508,25 +505,24 @@ void day_popup_item(struct day_item *day) */ int day_check_if_item(struct date day) { - const long date = date2sec(day, 0, 0); + const time_t t = date2sec(day, 0, 0); - if (LLIST_FIND_FIRST - (&recur_elist, (long *)&date, recur_event_inday)) + if (LLIST_FIND_FIRST(&recur_elist, (time_t *)&t, recur_event_inday)) return 1; LLIST_TS_LOCK(&recur_alist_p); - if (LLIST_TS_FIND_FIRST - (&recur_alist_p, (long *)&date, recur_apoint_inday)) { + if (LLIST_TS_FIND_FIRST(&recur_alist_p, (time_t *)&t, + recur_apoint_inday)) { LLIST_TS_UNLOCK(&recur_alist_p); return 1; } LLIST_TS_UNLOCK(&recur_alist_p); - if (LLIST_FIND_FIRST(&eventlist, (long *)&date, event_inday)) + if (LLIST_FIND_FIRST(&eventlist, (time_t *)&t, event_inday)) return 1; LLIST_TS_LOCK(&alist_p); - if (LLIST_TS_FIND_FIRST(&alist_p, (long *)&date, apoint_inday)) { + if (LLIST_TS_FIND_FIRST(&alist_p, (time_t *)&t, apoint_inday)) { LLIST_TS_UNLOCK(&alist_p); return 1; } @@ -558,24 +554,24 @@ static unsigned fill_slices(int *slices, int slicesno, int first, int last) */ unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices) { + const time_t t = date2sec(day, 0, 0); llist_item_t *i; int slicelen; - const long date = date2sec(day, 0, 0); slicelen = DAYINSEC / slicesno; #define SLICENUM(tsec) ((tsec) / slicelen % slicesno) LLIST_TS_LOCK(&recur_alist_p); - LLIST_TS_FIND_FOREACH(&recur_alist_p, (long *)&date, + LLIST_TS_FIND_FOREACH(&recur_alist_p, (time_t *)&t, 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); - if (rapt->start < date) + if (rapt->start < t) start = 0; - if (rapt->start + rapt->dur >= date + DAYINSEC) + if (rapt->start + rapt->dur >= t + DAYINSEC) end = DAYINSEC - 1; if (!fill_slices @@ -587,16 +583,16 @@ 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, (long *)&date, apoint_inday, i) { + LLIST_TS_FIND_FOREACH(&alist_p, (time_t *)&t, 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); - if (apt->start >= date + DAYINSEC) + if (apt->start >= t + DAYINSEC) break; - if (apt->start < date) + if (apt->start < t) start = 0; - if (apt->start + apt->dur >= date + DAYINSEC) + if (apt->start + apt->dur >= t + DAYINSEC) end = DAYINSEC - 1; if (!fill_slices @@ -481,14 +481,13 @@ ical_chk_header(FILE * fd, char *buf, char *lstore, unsigned *lineno, * * The timezone is not yet handled by calcurse. */ -static long ical_datetime2long(char *datestr, ical_vevent_e * type) +static time_t ical_datetime2time_t(char *datestr, ical_vevent_e * type) { - const int NOTFOUND = 0, FORMAT_DATE = 3, FORMAT_DATETIME = 6, - FORMAT_DATETIMEZ = 7; + const int FORMAT_DATE = 3, FORMAT_DATETIME = 6, FORMAT_DATETIMEZ = 7; struct date date; unsigned hour, min, sec; char c; - long datelong ; + time_t t = 0; int format; format = sscanf(datestr, "%04u%02u%02uT%02u%02u%02u%c", @@ -496,18 +495,16 @@ static long ical_datetime2long(char *datestr, ical_vevent_e * type) if (format == FORMAT_DATE) { if (type) *type = EVENT; - datelong = date2sec(date, 0, 0); + t = date2sec(date, 0, 0); } else if (format == FORMAT_DATETIME || format == FORMAT_DATETIMEZ) { if (type) *type = APPOINTMENT; if (format == FORMAT_DATETIMEZ && c == 'Z') - datelong = utcdate2sec(date, hour, min); + t = utcdate2sec(date, hour, min); else - datelong = date2sec(date, hour, min); - } else { - datelong = NOTFOUND; + t = date2sec(date, hour, min); } - return datelong; + return t; } static long ical_durtime2long(char *timestr) @@ -723,7 +720,7 @@ static ical_rpt_t *ical_read_rrule(FILE * log, char *rrulestr, * specified, counts as the first occurrence. */ if ((p = strstr(rrulestr, "UNTIL")) != NULL) { - rpt->until = ical_datetime2long(strchr(p, '=') + 1, NULL); + rpt->until = ical_datetime2time_t(strchr(p, '=') + 1, NULL); } else { unsigned cnt; char *countstr; @@ -766,7 +763,6 @@ ical_read_exdate(llist_t * exc, FILE * log, char *exstr, unsigned *noskipped, const int itemline) { char *p, *q; - long date; p = strchr(exstr, ':'); if (!p) { @@ -783,12 +779,10 @@ ical_read_exdate(llist_t * exc, FILE * log, char *exstr, strncpy(buf, p, buflen); buf[buflen] = '\0'; - date = ical_datetime2long(buf, NULL); - ical_add_exc(exc, date); + ical_add_exc(exc, ical_datetime2time_t(buf, NULL)); p = ++q; } - date = ical_datetime2long(p, NULL); - ical_add_exc(exc, date); + ical_add_exc(exc, ical_datetime2time_t(p, NULL)); } /* Return an allocated string containing the name of the newly created note. */ @@ -944,7 +938,7 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents, goto cleanup; } - vevent.start = ical_datetime2long(++p, &vevent_type); + vevent.start = ical_datetime2time_t(++p, &vevent_type); if (!vevent.start) { ical_log(log, ICAL_VEVENT, ITEMLINE, _("could not retrieve event start time.")); @@ -958,7 +952,7 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents, goto cleanup; } - vevent.end = ical_datetime2long(++p, &vevent_type); + vevent.end = ical_datetime2time_t(++p, &vevent_type); if (!vevent.end) { ical_log(log, ICAL_VEVENT, ITEMLINE, _("could not retrieve event end time.")); diff --git a/src/notify.c b/src/notify.c index 970306e..78c8484 100644 --- a/src/notify.c +++ b/src/notify.c @@ -499,9 +499,8 @@ void notify_check_added(char *mesg, long start, char state) /* Check if the newly repeated appointment is to be notified. */ void notify_check_repeated(struct recur_apoint *i) { - unsigned real_app_time; + time_t current_time, real_app_time; int update_notify = 0; - time_t current_time; current_time = time(NULL); pthread_mutex_lock(¬ify_app.mutex); @@ -541,7 +540,7 @@ int notify_same_item(long time) int notify_same_recur_item(struct recur_apoint *i) { int same = 0; - unsigned item_start = 0; + time_t item_start = 0; recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type, i->rpt->freq, i->rpt->until, diff --git a/src/recur.c b/src/recur.c index bda899d..667ecdf 100644 --- a/src/recur.c +++ b/src/recur.c @@ -610,7 +610,7 @@ unsigned recur_item_find_occurrence(long item_start, long item_dur, llist_t * item_exc, int rpt_type, int rpt_freq, long rpt_until, long day_start, - unsigned *occurrence) + time_t *occurrence) { struct date start_date; long diff, span; @@ -696,7 +696,7 @@ recur_item_find_occurrence(long item_start, long item_dur, unsigned recur_apoint_find_occurrence(struct recur_apoint *rapt, long day_start, - unsigned *occurrence) + time_t *occurrence) { return recur_item_find_occurrence(rapt->start, rapt->dur, &rapt->exc, rapt->rpt->type, @@ -707,7 +707,7 @@ recur_apoint_find_occurrence(struct recur_apoint *rapt, long day_start, unsigned recur_event_find_occurrence(struct recur_event *rev, long day_start, - unsigned *occurrence) + time_t *occurrence) { return recur_item_find_occurrence(rev->day, DAYINSEC, &rev->exc, rev->rpt->type, rev->rpt->freq, @@ -841,7 +841,7 @@ struct notify_app *recur_apoint_check_next(struct notify_app *app, long start, long day) { llist_item_t *i; - unsigned real_recur_start_time; + time_t real_recur_start_time; LLIST_TS_LOCK(&recur_alist_p); LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time, diff --git a/src/ui-calendar.c b/src/ui-calendar.c index 4539b86..2259c7f 100644 --- a/src/ui-calendar.c +++ b/src/ui-calendar.c @@ -214,7 +214,7 @@ struct date *ui_calendar_get_slctd_day(void) } /* Returned value represents the selected day in calendar (in seconds) */ -long ui_calendar_get_slctd_day_sec(void) +time_t ui_calendar_get_slctd_day_sec(void) { return date2sec(slctd_day, 0, 0); } diff --git a/src/ui-day.c b/src/ui-day.c index c71feb7..c777704 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -155,7 +155,7 @@ static void update_desc(char **desc) static void update_rept(struct rpt **rpt, const long start) { int newtype, newfreq; - long newuntil; + time_t newuntil; char *freqstr = NULL, *timstr, *outstr; const char *msg_rpt_prefix = _("Enter the new repetition type:"); const char *msg_rpt_daily = _("(d)aily"); @@ -480,7 +480,7 @@ void ui_day_item_add(void) const char *enter_str = _("Press [Enter] to continue"); char item_time[LDUR] = ""; char item_mesg[BUFSIZ] = ""; - long apoint_start; + time_t apoint_start; unsigned heures, minutes; unsigned apoint_duration; unsigned end_h, end_m; @@ -680,7 +680,7 @@ void ui_day_item_repeat(void) int item_nb; struct day_item *p; struct recur_apoint *ra; - long until, date; + time_t until, date; if (day_item_count(0) <= 0) goto cleanup; @@ -744,8 +744,7 @@ void ui_day_item_repeat(void) until_date.dd = day; until_date.mm = month; until_date.yyyy = year; - until = - date2sec(until_date, lt.tm_hour, lt.tm_min); + until = date2sec(until_date, lt.tm_hour, lt.tm_min); if (until >= p->start) break; status_mesg(mesg_older, wrong_type_2); @@ -859,7 +858,7 @@ void ui_day_sel_move(int delta) void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) { struct date slctd_date = *ui_calendar_get_slctd_day(); - long date = date2sec(slctd_date, 0, 0); + time_t date = date2sec(slctd_date, 0, 0); struct day_item *item = day_get_item(n); int width = lb_apt.sw.w; diff --git a/src/utils.c b/src/utils.c index ec5a1ea..613e4bc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -365,7 +365,7 @@ int get_item_min(long date) return lt.tm_min; } -long date2sec(struct date day, unsigned hour, unsigned min) +time_t date2sec(struct date day, unsigned hour, unsigned min) { time_t t = now(); struct tm start; @@ -386,8 +386,7 @@ long date2sec(struct date day, unsigned hour, unsigned min) return t; } -time_t -utcdate2sec(struct date day, unsigned hour, unsigned min) +time_t utcdate2sec(struct date day, unsigned hour, unsigned min) { char *tz; time_t t; @@ -488,11 +487,10 @@ long update_time_in_date(long date, unsigned hr, unsigned mn) * Returns the date in seconds from year 1900. * If no date is entered, current date is chosen. */ -long get_sec_date(struct date date) +time_t get_sec_date(struct date date) { struct tm ptrtime; time_t timer; - long long_date; char current_day[] = "dd "; char current_month[] = "mm "; char current_year[] = "yyyy "; @@ -501,16 +499,14 @@ long get_sec_date(struct date date) timer = time(NULL); localtime_r(&timer, &ptrtime); strftime(current_day, strlen(current_day), "%d", &ptrtime); - strftime(current_month, strlen(current_month), "%m", - &ptrtime); - strftime(current_year, strlen(current_year), "%Y", - &ptrtime); + strftime(current_month, strlen(current_month), "%m", &ptrtime); + strftime(current_year, strlen(current_year), "%Y", &ptrtime); date.mm = atoi(current_month); date.dd = atoi(current_day); date.yyyy = atoi(current_year); } - long_date = date2sec(date, 0, 0); - return long_date; + + return date2sec(date, 0, 0); } long min2sec(unsigned minutes) @@ -566,11 +562,10 @@ item_in_popup(const char *a_start, const char *a_end, const char *msg, } /* Returns the beginning of current day in seconds from 1900. */ -long get_today(void) +time_t get_today(void) { struct tm lt; time_t current_time; - long current_day; struct date day; current_time = time(NULL); @@ -578,9 +573,8 @@ long get_today(void) day.mm = lt.tm_mon + 1; day.dd = lt.tm_mday; day.yyyy = lt.tm_year + 1900; - current_day = date2sec(day, 0, 0); - return current_day; + return date2sec(day, 0, 0); } /* Returns the current time in seconds. */ @@ -1500,7 +1494,7 @@ void print_event(const char *format, long day, struct event *ev) /* Print a formatted recurrent appointment to stdout. */ void -print_recur_apoint(const char *format, long day, unsigned occurrence, +print_recur_apoint(const char *format, long day, time_t occurrence, struct recur_apoint *rapt) { struct apoint apt; |