summaryrefslogtreecommitdiff
path: root/src/calendar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/calendar.c')
-rw-r--r--src/calendar.c70
1 files changed, 45 insertions, 25 deletions
diff --git a/src/calendar.c b/src/calendar.c
index 61e758b..3d7698e 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -144,15 +144,15 @@ void calendar_stop_date_thread(void)
void calendar_set_current_date(void)
{
time_t timer;
- struct tm *tm;
+ struct tm tm;
timer = time(NULL);
- tm = localtime(&timer);
+ localtime_r(&timer, &tm);
pthread_mutex_lock(&date_thread_mutex);
- today.dd = tm->tm_mday;
- today.mm = tm->tm_mon + 1;
- today.yyyy = tm->tm_year + 1900;
+ today.dd = tm.tm_mday;
+ today.mm = tm.tm_mon + 1;
+ today.yyyy = tm.tm_year + 1900;
pthread_mutex_unlock(&date_thread_mutex);
}
@@ -306,6 +306,7 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
c_day_1 = (int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L);
/* Write the current month and year on top of the calendar */
+ WINS_CALENDAR_LOCK;
custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw(cwin->p, ofs_y,
(SBAR_WIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
@@ -319,6 +320,7 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
mvwaddstr(cwin->p, ofs_y, ofs_x + 4 * j, _(daynames[1 + j - sunday_first]));
}
custom_remove_attr(cwin->p, ATTR_HIGHEST);
+ WINS_CALENDAR_UNLOCK;
day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7;
@@ -348,11 +350,12 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
ofs_x = OFFX - day_1_sav - 4 * c_day;
}
- /* This is today, so print it in yellow. */
+ WINS_CALENDAR_LOCK;
if (c_day == current_day->dd
&& current_day->mm == slctd_day.mm
&& current_day->yyyy == slctd_day.yyyy
&& current_day->dd != slctd_day.dd) {
+ /* This is today, so print it in yellow. */
custom_apply_attr(cwin->p, ATTR_LOWEST);
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
@@ -368,10 +371,12 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin->p, ATTR_LOW);
- } else
+ } else {
/* otherwise, print normal days in black */
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
+ }
+ WINS_CALENDAR_UNLOCK;
}
monthly_view_cache_valid = 1;
@@ -477,9 +482,11 @@ draw_weekly_view(struct window *cwin, struct date *current_day,
/* Print the week number. */
weeknum = ISO8601weeknum(&t);
+ WINS_CALENDAR_LOCK;
custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw(cwin->p, 2, cwin->w - 9, "(# %02d)", weeknum);
custom_remove_attr(cwin->p, ATTR_HIGHEST);
+ WINS_CALENDAR_UNLOCK;
/* Now draw calendar view. */
for (j = 0; j < WEEKINDAYS; j++) {
@@ -511,22 +518,28 @@ draw_weekly_view(struct window *cwin, struct date *current_day,
else
attr = 0;
+ WINS_CALENDAR_LOCK;
if (attr)
custom_apply_attr(cwin->p, attr);
mvwprintw(cwin->p, OFFY + 1, OFFX + 1 + 4 * j, "%02d", t.tm_mday);
if (attr)
custom_remove_attr(cwin->p, attr);
+ WINS_CALENDAR_UNLOCK;
/* Draw slices indicating appointment times. */
memset(slices, 0, DAYSLICESNO * sizeof *slices);
if (day_chk_busy_slices(date, DAYSLICESNO, slices)) {
for (i = 0; i < DAYSLICESNO; i++) {
- if (j != WEEKINDAYS - 1 && i != DAYSLICESNO - 1)
+ if (j != WEEKINDAYS - 1 && i != DAYSLICESNO - 1) {
+ WINS_CALENDAR_LOCK;
mvwhline(cwin->p, OFFY + 2 + i, OFFX + 3 + 4 * j, ACS_S9, 2);
+ WINS_CALENDAR_UNLOCK;
+ }
if (slices[i]) {
int highlight;
highlight = (t.tm_mday == slctd_day.dd) ? 1 : 0;
+ WINS_CALENDAR_LOCK;
if (highlight)
custom_apply_attr(cwin->p, attr);
wattron(cwin->p, A_REVERSE);
@@ -535,6 +548,7 @@ draw_weekly_view(struct window *cwin, struct date *current_day,
wattroff(cwin->p, A_REVERSE);
if (highlight)
custom_remove_attr(cwin->p, attr);
+ WINS_CALENDAR_UNLOCK;
}
}
}
@@ -544,11 +558,13 @@ draw_weekly_view(struct window *cwin, struct date *current_day,
}
/* Draw marks to indicate midday on the sides of the calendar. */
+ WINS_CALENDAR_LOCK;
custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwhline(cwin->p, OFFY + 1 + DAYSLICESNO / 2, OFFX, ACS_S9, 1);
mvwhline(cwin->p, OFFY + 1 + DAYSLICESNO / 2,
OFFX + WCALWIDTH - 3, ACS_S9, 1);
custom_remove_attr(cwin->p, ATTR_HIGHEST);
+ WINS_CALENDAR_UNLOCK;
#undef DAYSLICESNO
}
@@ -560,8 +576,12 @@ void calendar_update_panel(struct window *cwin)
unsigned sunday_first;
calendar_store_current_date(&current_day);
+
+ WINS_CALENDAR_LOCK;
erase_window_part(cwin->p, 1, 3, cwin->w - 2, cwin->h - 2);
mvwhline(cwin->p, 2, 1, ACS_HLINE, cwin->w - 2);
+ WINS_CALENDAR_UNLOCK;
+
sunday_first = calendar_week_begins_on_monday()? 0 : 1;
draw_calendar[calendar_view] (cwin, &current_day, sunday_first);
@@ -707,16 +727,16 @@ void calendar_move(enum move move, int count)
long calendar_start_of_year(void)
{
time_t timer;
- struct tm *tm;
+ struct tm tm;
timer = time(NULL);
- tm = localtime(&timer);
- tm->tm_mon = 0;
- tm->tm_mday = 1;
- tm->tm_hour = 0;
- tm->tm_min = 0;
- tm->tm_sec = 0;
- timer = mktime(tm);
+ localtime_r(&timer, &tm);
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ timer = mktime(&tm);
return (long)timer;
}
@@ -724,17 +744,17 @@ long calendar_start_of_year(void)
long calendar_end_of_year(void)
{
time_t timer;
- struct tm *tm;
+ struct tm tm;
timer = time(NULL);
- tm = localtime(&timer);
- tm->tm_mon = 0;
- tm->tm_mday = 1;
- tm->tm_hour = 0;
- tm->tm_min = 0;
- tm->tm_sec = 0;
- tm->tm_year++;
- timer = mktime(tm);
+ localtime_r(&timer, &tm);
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ tm.tm_year++;
+ timer = mktime(&tm);
return (long)(timer - 1);
}