int i;
time_t now;
- struct tm *tm_now;
+ struct tm tm_now;
int this_year;
time_t tt;
- struct tm *tm;
+ struct tm tm;
const int span = 10;
now = time(NULL);
- tm_now = localtime(&now);
- this_year = tm_now->tm_year + 1900;
+ memcpy(&tm_now, localtime(&now), sizeof(struct tm));
+ this_year = tm_now.tm_year + 1900;
if (t == NULL) return;
tt = icaltime_as_timet(*t);
- tm = localtime(&tt);
+ memcpy(&tm, localtime(&tt), sizeof(struct tm));
wprintf("Month: ");
wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
for (i=0; i<=11; ++i) {
wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
- ((tm->tm_mon == i) ? "SELECTED" : ""),
+ ((tm.tm_mon == i) ? "SELECTED" : ""),
i+1,
months[i]
);
wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
for (i=1; i<=31; ++i) {
wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
- ((tm->tm_mday == i) ? "SELECTED" : ""),
+ ((tm.tm_mday == i) ? "SELECTED" : ""),
i, i
);
}
wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
for (i=0; i<=23; ++i) {
wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
- ((tm->tm_hour == i) ? "SELECTED" : ""),
+ ((tm.tm_hour == i) ? "SELECTED" : ""),
i, hourname[i]
);
}
wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
for (i=0; i<=59; ++i) {
wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
- ((tm->tm_min == i) ? "SELECTED" : ""),
+ ((tm.tm_min == i) ? "SELECTED" : ""),
i, i
);
}
void calendar_month_view(int year, int month, int day) {
struct tm starting_tm;
- struct tm *tm;
+ struct tm tm;
time_t thetime;
int i;
time_t previous_month;
starting_tm.tm_mday = day;
thetime = mktime(&starting_tm);
- tm = &starting_tm;
- while (tm->tm_mday != 1) {
+ memcpy(&tm, &starting_tm, sizeof(struct tm));
+ while (tm.tm_mday != 1) {
thetime = thetime - (time_t)86400; /* go back 24 hours */
- tm = localtime(&thetime);
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
}
/* Determine previous and next months ... for links */
next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
/* Now back up until we're on a Sunday */
- tm = localtime(&thetime);
- while (tm->tm_wday != 0) {
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
+ while (tm.tm_wday != 0) {
thetime = thetime - (time_t)86400; /* go back 24 hours */
- tm = localtime(&thetime);
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
}
/* Outer table (to get the background color) */
wprintf("<TD><CENTER><H3>");
- tm = localtime(&previous_month);
+ memcpy(&tm, localtime(&previous_month), sizeof(struct tm));
wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
- (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+ (int)(tm.tm_year)+1900, tm.tm_mon + 1);
wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
wprintf(" "
"</FONT>"
" ", months[month-1], year);
- tm = localtime(&next_month);
+ memcpy(&tm, localtime(&next_month), sizeof(struct tm));
wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
- (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+ (int)(tm.tm_year)+1900, tm.tm_mon + 1);
wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
wprintf("</H3></TD><TD align=right><font color=#FFFFFF size=-2>"
/* Now do 35 days */
for (i = 0; i < 35; ++i) {
- tm = localtime(&thetime);
- if (tm->tm_wday == 0) {
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
+
+ /* Before displaying Sunday, start a new row */
+ if ((i % 7) == 0) {
wprintf("<TR>");
}
wprintf("<TD BGCOLOR=%s WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
- ((tm->tm_mon != month-1) ? "DDDDDD" :
- ((tm->tm_wday==0 || tm->tm_wday==6) ? "EEEECC" :
+ ((tm.tm_mon != month-1) ? "DDDDDD" :
+ ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
"FFFFFF"))
);
- if ((i==0) || (tm->tm_mday == 1)) {
- wprintf("%s ", months[tm->tm_mon]);
+ if ((i==0) || (tm.tm_mday == 1)) {
+ wprintf("%s ", months[tm.tm_mon]);
}
wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
"%d</A></B><BR>",
- tm->tm_year + 1900,
- tm->tm_mon + 1,
- tm->tm_mday,
- tm->tm_mday);
+ tm.tm_year + 1900,
+ tm.tm_mon + 1,
+ tm.tm_mday,
+ tm.tm_mday);
/* put the data here, stupid */
calendar_month_view_display_events(thetime);
wprintf("</TD>");
- if (tm->tm_wday == 6) {
+ /* After displaying Saturday, end the row */
+ if ((i % 7) == 6) {
wprintf("</TR>\n");
}
void do_calendar_view(void) {
int i;
time_t now;
- struct tm *tm;
+ struct tm tm;
int year, month, day;
char calview[SIZ];
/* In case no date was specified, go with today */
now = time(NULL);
- tm = localtime(&now);
- year = tm->tm_year + 1900;
- month = tm->tm_mon + 1;
- day = tm->tm_mday;
+ memcpy(&tm, localtime(&now), sizeof(struct tm));
+ year = tm.tm_year + 1900;
+ month = tm.tm_mon + 1;
+ day = tm.tm_mday;
/* Now see if a date was specified */
if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));