More conversion of date/time strings to strftime-based functions.
authorArt Cancro <ajc@citadel.org>
Sun, 12 Feb 2006 06:34:37 +0000 (06:34 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 12 Feb 2006 06:34:37 +0000 (06:34 +0000)
Still need to tweak a few things here and there.

webcit/calendar.c
webcit/calendar_tools.c
webcit/calendar_view.c
webcit/event.c
webcit/fmt_date.c
webcit/summary.c
webcit/webcit.h
webcit/webserver.c

index 37621ef6525384fab3400115b814de985e1c414f..09735ea79b0148441c1baf10c83cef89add1b92e 100644 (file)
@@ -167,7 +167,7 @@ void cal_process_object(icalcomponent *cal,
                                wprintf(_("Date:"));
                                wprintf("</B></TD><TD>"
                                        "%s %d, %d</TD></TR>",
-                                       months[t.month - 1],
+                                       monthname(t.month - 1),
                                        t.day, t.year
                                );
                        }
index 72ee508a6ce3f7e5b71928937f9525981f166129..58e62146f4515055f2e0c60b71107f048be19d06 100644 (file)
@@ -73,7 +73,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
                wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
                        ((tm.tm_mon == i) ? "SELECTED" : ""),
                        i+1,
-                       months[i]
+                       monthname(i)
                );
        }
        wprintf("</SELECT>\n");
index d071ca4a29c8bb77adb5bd0bbb224feee976809b..a82e731b90c113f2843ec47faa2dcef273fea7ee 100644 (file)
@@ -196,10 +196,8 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
                                        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>",
@@ -231,6 +229,9 @@ void calendar_month_view(int year, int month, int day) {
        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...
@@ -272,11 +273,12 @@ void calendar_month_view(int year, int month, int day) {
                (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("&nbsp;&nbsp;"
                "<FONT SIZE=+1 COLOR=\"#FFFFFF\">"
                "%s %d"
                "</FONT>"
-               "&nbsp;&nbsp;", months[month-1], year);
+               "&nbsp;&nbsp;", colheader_label, year);
 
        localtime_r(&next_month, &tm);
        wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
@@ -288,9 +290,13 @@ void calendar_month_view(int year, int month, int day) {
        /** 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");
 
@@ -309,7 +315,8 @@ void calendar_month_view(int year, int month, int day) {
                        "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 />",
@@ -349,6 +356,7 @@ void calendar_brief_month_view(int year, int month, int day) {
        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...
@@ -390,11 +398,12 @@ void calendar_brief_month_view(int year, int month, int day) {
                (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("&nbsp;&nbsp;"
                "<FONT SIZE=+1 COLOR=\"#FFFFFF\">"
                "%s %d"
                "</FONT>"
-               "&nbsp;&nbsp;", months[month-1], year);
+               "&nbsp;&nbsp;", month_label, year);
 
        localtime_r(&next_month, &tm);
        wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
@@ -412,13 +421,14 @@ void calendar_brief_month_view(int year, int month, int day) {
        /** 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"), 
@@ -435,10 +445,12 @@ void calendar_brief_month_view(int year, int month, int day) {
                                   "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);
@@ -675,7 +687,8 @@ void calendar_day_view(int year, int month, int day) {
        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 */
index 565ae727cde2506de9832dee661dbff934e22556..94fac68dbc9d4188cfea0eb40d42ff7728083431 100644 (file)
@@ -270,17 +270,14 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
         * 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;
                        }
index cdc4f18030cce10ff191afeb6284ead05d7e457c..b5681e8ee9072bd09eb0c095719657efec186fa6 100644 (file)
 #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
@@ -29,22 +46,6 @@ void fmt_date(char *buf, time_t thetime, int brief)
        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);
 
@@ -66,51 +67,49 @@ void fmt_date(char *buf, time_t thetime, int brief)
                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];
+               
 }
 
 
@@ -159,7 +158,7 @@ void fmt_time(char *buf, time_t thetime)
  * \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;
@@ -246,33 +245,5 @@ time_t httpdate_to_timestamp(const char *buf)
 
 
 
-/**
- * /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");
-}
-
-
-
 
 /*@}*/
index 0c309364fc7d741c133d42d577f43f92b273a3b8..b7b9084b59467d1fe717aad59bcfa7ffd3744ce1 100644 (file)
@@ -19,7 +19,7 @@ void output_date(void) {
        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);
 }
 
index 0684163d2f7e920b55bf0de96ebee11e78dec555..5d89ebebc78b6f67d92da9749caede0eb2c67b96 100644 (file)
@@ -550,10 +550,12 @@ void display_menubar(int);
 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);
@@ -720,12 +722,8 @@ void utf8ify_rfc822_string(char *buf);
 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);
 
 
index 4824d5a95c3aeb94b50c78fbf80b15e4a3039dfb..40b52a6f6234b67d36c4f4802276e7cf3e06330f 100644 (file)
@@ -577,7 +577,6 @@ int main(int argc, char **argv)
 
        initialize_viewdefs();
        initialize_axdefs();
-       initialize_months_and_days();
 
        /**
         * Set up a place to put thread-specific data.