Still need to tweak a few things here and there.
wprintf(_("Date:"));
wprintf("</B></TD><TD>"
"%s %d, %d</TD></TR>",
- months[t.month - 1],
+ monthname(t.month - 1),
t.day, t.year
);
}
wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
((tm.tm_mon == i) ? "SELECTED" : ""),
i+1,
- months[i]
+ monthname(i)
);
}
wprintf("</SELECT>\n");
escputs((char *)
icalproperty_get_comment(p));
/** \todo: allso ammitime format */
- strftime_l(&sbuf[0], sizeof(sbuf), timeformat, &event_tms,
- wc_locales[WC->selected_language]);
- strftime_l(&ebuf[0], sizeof(sbuf), timeformat, &event_tme,
- wc_locales[WC->selected_language]);
+ wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
+ wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
wprintf("</a></font></td>"
"<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
int i;
time_t previous_month;
time_t next_month;
+ time_t colheader_time;
+ struct tm colheader_tm;
+ char colheader_label[32];
/** Determine what day to start.
* First, back up to the 1st of the month...
(int)(tm.tm_year)+1900, tm.tm_mon + 1);
wprintf("<IMG ALIGN=MIDDLE src=\"static/prevdate_32x.gif\" BORDER=0></A>\n");
+ wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
wprintf(" "
"<FONT SIZE=+1 COLOR=\"#FFFFFF\">"
"%s %d"
"</FONT>"
- " ", months[month-1], year);
+ " ", colheader_label, year);
localtime_r(&next_month, &tm);
wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
/** Inner table (the real one) */
wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
"bgcolor=#204B78><TR>");
+ colheader_time = thetime;
for (i=0; i<7; ++i) {
+ colheader_time = thetime + (i * 86400) ;
+ localtime_r(&colheader_time, &colheader_tm);
+ wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
wprintf("<TD ALIGN=CENTER WIDTH=14%%>"
- "<FONT COLOR=\"#FFFFFF\">%s</FONT></TH>", wdays[i]);
+ "<FONT COLOR=\"#FFFFFF\">%s</FONT></TH>", colheader_label);
}
wprintf("</TR>\n");
"FFFFFF"))
);
if ((i==0) || (tm.tm_mday == 1)) {
- wprintf("%s ", months[tm.tm_mon]);
+ wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
+ wprintf("%s ", colheader_label);
}
wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
"%d</A></B><br />",
int i;
time_t previous_month;
time_t next_month;
+ char month_label[32];
/** Determine what day to start.
* First, back up to the 1st of the month...
(int)(tm.tm_year)+1900, tm.tm_mon + 1);
wprintf("<IMG ALIGN=MIDDLE src=\"static/prevdate_32x.gif\" BORDER=0></A>\n");
+ wc_strftime(month_label, sizeof month_label, "%B", &tm);
wprintf(" "
"<FONT SIZE=+1 COLOR=\"#FFFFFF\">"
"%s %d"
"</FONT>"
- " ", months[month-1], year);
+ " ", month_label, year);
localtime_r(&next_month, &tm);
wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
/** Now do 35 days */
for (i = 0; i < 35; ++i) {
char weeknumber[255];
+ char weekday_name[32];
char *daycolor;
localtime_r(&thetime, &tm);
/** Before displaying Sunday, start a new CELL */
if ((i % 7) == 0) {
- strftime_l(&weeknumber[0], sizeof(weeknumber), "%U", &tm, wc_locales[WC->selected_language]);
+ wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
wprintf("<TABLE border='0' BGCOLOR=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
" <tr><td>%s</td><td width='70%'>%s</td><td>%s</td><td>%s</td></tr>\n",
_("Week"),
"FFFFFF"));
/** Day Header */
- wprintf("<tr><td BGCOLOR='%s' colspan='1' align='left'> %s</td><td BGCOLOR='%s' colspan='3'><hr></td></tr>\n",
- daycolor,
- wdays[i%7],
- daycolor);
+ wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
+ wprintf("<tr><td BGCOLOR='%s' colspan='1' align='left'> %s"
+ "</td><td BGCOLOR='%s' colspan='3'><hr></td></tr>\n",
+ daycolor,
+ weekday_name,
+ daycolor);
/** put the data of one day here, stupid */
calendar_month_view_brief_events(thetime, daycolor);
wprintf("<FONT SIZE=+2>%s</FONT><br />"
"<FONT SIZE=+3>%d</FONT><br />"
"<FONT SIZE=+2>%d</FONT><br />",
- months[month-1], day, year);
+ monthname(month-1),
+ day, year);
wprintf("</TD>");
/** Right arrow */
* Determine who is the organizer of this event.
* We need to determine "me" or "not me."
*/
- organizer = icalcomponent_get_first_property(vevent,
- ICAL_ORGANIZER_PROPERTY);
+ organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
if (organizer != NULL) {
strcpy(organizer_string, icalproperty_get_organizer(organizer));
if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
strcpy(organizer_string, &organizer_string[7]);
striplt(organizer_string);
- lprintf(9, "ISME %s\n", organizer_string);
serv_printf("ISME %s", organizer_string);
serv_getln(buf, sizeof buf);
- lprintf(9, "%s\n", buf);
if (buf[0] == '2') {
organizer_is_me = 1;
}
#include "webserver.h"
typedef unsigned char byte; /**< a byte. */
-char *wdays[7];
-char *months[12];
#define FALSE 0 /**< no. */
#define TRUE 1 /**< yes. */
+/**
+ * \brief Wrapper around strftime() or strftime_l()
+ * depending upon how our build is configured.
+ *
+ * \param s String target buffer
+ * \param max Maximum size of string target buffer
+ * \param format strftime() format
+ * \param tm Input date/time
+ */
+size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm)
+{
+#ifdef ENABLE_NLS
+ return strftime_l(s, max, format, tm, wc_locales[WC->selected_language]);
+#else
+ return strftime(s, max, format, tm);
+#endif
+}
+
+
/**
* \brief Format a date/time stamp for output
* \param buf the output buffer
time_t today_timet;
int hour;
char calhourformat[16];
- static char *ascmonths[12] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } ;
-
- if (ascmonths[0] == NULL) {
- ascmonths[0] = _("Jan");
- ascmonths[1] = _("Feb");
- ascmonths[2] = _("Mar");
- ascmonths[3] = _("Apr");
- ascmonths[4] = _("May");
- ascmonths[5] = _("Jun");
- ascmonths[6] = _("Jul");
- ascmonths[7] = _("Aug");
- ascmonths[8] = _("Sep");
- ascmonths[9] = _("Oct");
- ascmonths[10] = _("Nov");
- ascmonths[11] = _("Dec");
- };
get_preference("calhourformat", calhourformat, sizeof calhourformat);
if ((tm.tm_year == today_tm.tm_year)
&&(tm.tm_mon == today_tm.tm_mon)
&&(tm.tm_mday == today_tm.tm_mday)) {
- if (!strcasecmp(calhourformat, "24")) {
- sprintf(buf, "%2d:%02d",
- tm.tm_hour, tm.tm_min
- );
- }
- else {
- sprintf(buf, "%2d:%02d%s",
- hour, tm.tm_min,
- ((tm.tm_hour >= 12) ? "pm" : "am")
- );
- }
+ wc_strftime(buf, 32, "%l:%M%p", &tm);
}
-
/** Otherwise, for messages up to 6 months old, show the
* month and day, and the time */
else if (today_timet - thetime < 15552000) {
- if (!strcasecmp(calhourformat, "24")) {
- sprintf(buf, "%s %d %2d:%02d",
- ascmonths[tm.tm_mon],
- tm.tm_mday,
- tm.tm_hour, tm.tm_min
- );
- }
- else {
- sprintf(buf, "%s %d %2d:%02d%s",
- ascmonths[tm.tm_mon],
- tm.tm_mday,
- hour, tm.tm_min,
- ((tm.tm_hour >= 12) ? "pm" : "am")
- );
- }
+ wc_strftime(buf, 32, "%b %d %l:%M%p", &tm);
}
-
/** older than 6 months, show only the date */
else {
- sprintf(buf, "%s %d %d",
- ascmonths[tm.tm_mon],
- tm.tm_mday,
- tm.tm_year + 1900
- );
+ wc_strftime(buf, 32, "%b %d %Y", &tm);
}
}
else {
- strftime_l(buf, 32, "%c", &tm, wc_locales[WC->selected_language]);
+ wc_strftime(buf, 32, "%c", &tm);
+ }
+}
+
+/**
+ * \brief Convenience function to return a month name
+ *
+ * \param m Numeric month
+ */
+char *monthname(int m)
+{
+ static char months[12][32];
+ static int initialized = 0;
+
+ time_t tt;
+ struct tm tm;
+ int i;
+
+ if (!initialized) {
+ for (i=0; i<12; ++i) {
+ tt = 1137997451 + (i * 2592000);
+ localtime_r(&tt, &tm);
+ wc_strftime(months[i], 32, "%B", &tm);
+ lprintf(9, "%s\n", months[i]);
+ }
}
+ initialized = 1;
+
+ return months[m];
+
}
* \param buf time to parse
* \return the time found in buf
*/
-time_t httpdate_to_timestamp(const char *buf)
+time_t httpdate_to_timestamp(char *buf)
{
time_t t = 0;
struct tm tt;
-/**
- * /brief Initialize the strings used to display months and weekdays.
- */
-void initialize_months_and_days(void) {
- wdays[0] = _("Sunday");
- wdays[1] = _("Monday");
- wdays[2] = _("Tuesday");
- wdays[3] = _("Wednesday");
- wdays[4] = _("Thursday");
- wdays[5] = _("Friday");
- wdays[6] = _("Saturday");
-
- months[0] = _("January");
- months[1] = _("February");
- months[2] = _("March");
- months[3] = _("April");
- months[4] = _("May");
- months[5] = _("June");
- months[6] = _("July");
- months[7] = _("August");
- months[8] = _("September");
- months[9] = _("October");
- months[10] = _("November");
- months[11] = _("December");
-}
-
-
-
/*@}*/
time(&now);
localtime_r(&now, &tm);
- strftime_l(buf, 32, "%A, %x", &tm, wc_locales[WC->selected_language]);
+ wc_strftime(buf, 32, "%A, %x", &tm);
wprintf("%s", buf);
}
void smart_goto(char *);
void worker_entry(void);
void session_loop(struct httprequest *);
+size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
void fmt_date(char *buf, time_t thetime, int brief);
void fmt_time(char *buf, time_t thetime);
+char *monthname(int m);
void httpdate(char *buf, time_t thetime);
-time_t httpdate_to_timestamp(const char *buf);
+time_t httpdate_to_timestamp(char *buf);
void end_webcit_session(void);
void page_popup(void);
void chat_recv(void);
void begin_burst(void);
void end_burst(void);
-extern char *ascmonths[]; /**< Short (three letter) month names */
-extern char *months[]; /**< Long (full) month names */
extern char *hourname[]; /**< Names of hours (12am, 1am, etc.) */
-extern char *wdays[]; /**< Days of the week */
-void initialize_months_and_days(void);
void http_datestring(char *buf, size_t n, time_t xtime);
initialize_viewdefs();
initialize_axdefs();
- initialize_months_and_days();
/**
* Set up a place to put thread-specific data.