Began moving date outputs to strftime_l()
authorArt Cancro <ajc@citadel.org>
Sun, 12 Feb 2006 05:10:31 +0000 (05:10 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 12 Feb 2006 05:10:31 +0000 (05:10 +0000)
webcit/calendar_view.c
webcit/configure.in
webcit/fmt_date.c
webcit/gettext.c
webcit/gettext.h [deleted file]
webcit/summary.c
webcit/webcit.h

index f5756114f12fac85eec8edd64f698e647d9a29e0..d071ca4a29c8bb77adb5bd0bbb224feee976809b 100644 (file)
@@ -180,7 +180,7 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
                                        difftime=(event_tte-event_tts)/60;
                                        hours=(int)(difftime / 60);
                                        minutes=difftime % 60;
-                                       wprintf("<tr><td bgcolor='%s'>%i:%i</td><td bgcolor='%s'>"
+                                       wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
                                                        "<font size=-1>"
                                                        "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
                                                        daycolor,
@@ -196,8 +196,10 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
                                        escputs((char *)
                                                        icalproperty_get_comment(p));
                                        /** \todo: allso ammitime format */
-                                       strftime(&sbuf[0],sizeof(sbuf),timeformat,&event_tms);
-                                       strftime(&ebuf[0],sizeof(sbuf),timeformat,&event_tme);
+                                       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]);
 
                                        wprintf("</a></font></td>"
                                                        "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
@@ -416,7 +418,7 @@ void calendar_brief_month_view(int year, int month, int day) {
 
                /** Before displaying Sunday, start a new CELL */
                if ((i % 7) == 0) {
-                       strftime(&weeknumber[0],sizeof(weeknumber),"%U",&tm);
+                       strftime_l(&weeknumber[0], sizeof(weeknumber), "%U", &tm, wc_locales[WC->selected_language]);
                        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"), 
index 625b547b7dad485429dc470b12b478e9b6255959..6a863d8eeacdb17b83db3087a2e5d5bf1758940e 100644 (file)
@@ -306,16 +306,22 @@ AC_ARG_ENABLE(nls,
        ok_nls=no, ok_nls=yes)
 
 if test "$ok_nls" != "no"; then
-       AC_MSG_RESULT(Checking to see if your system supports multithreaded NLS...)
+       AC_MSG_RESULT(Checking for per-thread NLS support...)
        AC_TRY_RUN([
-               #define _GNU_SOURCE
-               #include <locale.h>
-               #include <libintl.h>
-               main() {
-                       char *foo;
-                       uselocale(LC_GLOBAL_LOCALE);
-                       foo = gettext("bar");
-                       exit(0);
+                #define _GNU_SOURCE
+                #include <libintl.h>
+                #include <locale.h>
+                #include <time.h>
+                main() {
+                        char *foo = NULL;
+                        char baz[32];
+                       struct tm *tm;
+                        uselocale(LC_GLOBAL_LOCALE);
+                        foo = gettext("bar");
+                       if (0) {
+                               strftime_l(baz, sizeof baz, "%c", tm, LC_GLOBAL_LOCALE);
+                       }
+                        exit(0);
                }
        ],
                ok_uselocale=yes,
index 0475f91cf3b0c3a91c410078d5ed72874e769b19..cdc4f18030cce10ff191afeb6284ead05d7e457c 100644 (file)
@@ -109,22 +109,7 @@ void fmt_date(char *buf, time_t thetime, int brief)
                }
        }
        else {
-               if (!strcasecmp(calhourformat, "24")) {
-                       sprintf(buf, "%s %d %d %2d:%02d",
-                               ascmonths[tm.tm_mon],
-                               tm.tm_mday,
-                               tm.tm_year + 1900,
-                               tm.tm_hour, tm.tm_min
-                       );
-               }
-               else {
-                       sprintf(buf, "%s %d %d %2d:%02d%s",
-                               ascmonths[tm.tm_mon],
-                               tm.tm_mday,
-                               tm.tm_year + 1900,
-                               hour, tm.tm_min, ((tm.tm_hour >= 12) ? "pm" : "am")
-                       );
-               }
+               strftime_l(buf, 32, "%c", &tm, wc_locales[WC->selected_language]);
        }
 }
 
index 3596c5d7c5103d5bdc868f74800d49aa831632ad..c83c41ee07f5fc81b9b5ec563686cdb6e7968acf 100644 (file)
@@ -252,10 +252,20 @@ void initialize_locales(void) {
 
        for (i = 0; i < NUM_LANGS; ++i) {
                sprintf(buf, "%s.UTF8", AvailLang[i]);
-               wc_locales[i] = newlocale(LC_MESSAGES_MASK /* |LC_TIME_MASK FIXME */ ,
+               wc_locales[i] = newlocale(
+                       (LC_MESSAGES_MASK|LC_TIME_MASK),
                        buf,
                        Empty_Locale
                );
+               if (wc_locales[i] == NULL) {
+                       lprintf(1, "Error configuring locale for %s: %s\n",
+                               buf,
+                               strerror(errno)
+                       );
+               }
+               else {
+                       lprintf(3, "Configured available locale: %s\n", buf);
+               }
        }
 }
 
diff --git a/webcit/gettext.h b/webcit/gettext.h
deleted file mode 100644 (file)
index 4e3cbd2..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-/* Convenience header for conditional use of GNU <libintl.h>.
-   Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Library General Public License as published
-   by the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-   USA.  */
-
-#ifndef _LIBGETTEXT_H
-#define _LIBGETTEXT_H 1
-
-/* NLS can be disabled through the configure --disable-nls option.  */
-#if ENABLE_NLS
-
-/* Get declarations of GNU message catalog functions.  */
-# include <libintl.h>
-
-#else
-
-/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
-   chokes if dcgettext is defined as a macro.  So include it now, to make
-   later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
-   as well because people using "gettext.h" will not include <libintl.h>,
-   and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
-   is OK.  */
-#if defined(__sun)
-# include <locale.h>
-#endif
-
-/* Disabled NLS.
-   The casts to 'const char *' serve the purpose of producing warnings
-   for invalid uses of the value returned from these functions.
-   On pre-ANSI systems without 'const', the config.h file is supposed to
-   contain "#define const".  */
-# define gettext(Msgid) ((const char *) (Msgid))
-# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
-# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
-# define ngettext(Msgid1, Msgid2, N) \
-    ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-# define dngettext(Domainname, Msgid1, Msgid2, N) \
-    ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
-    ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-# define textdomain(Domainname) ((const char *) (Domainname))
-# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
-# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
-
-#endif
-
-/* A pseudo function call that serves as a marker for the automated
-   extraction of messages, but does not call gettext().  The run-time
-   translation is done at a different place in the code.
-   The argument, String, should be a literal string.  Concatenated strings
-   and other string expressions won't work.
-   The macro's expansion is not parenthesized, so that it is suitable as
-   initializer for static 'char[]' or 'const char[]' variables.  */
-#define gettext_noop(String) String
-
-#endif /* _LIBGETTEXT_H */
index 77f6cd5027ac12d225833ea00e934b943d2c2ec4..0c309364fc7d741c133d42d577f43f92b273a3b8 100644 (file)
 void output_date(void) {
        struct tm tm;
        time_t now;
-
-       static char *wdays[7];
-       static char *months[12];
-
-       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");
+       char buf[128];
 
        time(&now);
        localtime_r(&now, &tm);
 
-       wprintf("%s, %s %d, %d",
-               wdays[tm.tm_wday],
-               months[tm.tm_mon],
-               tm.tm_mday,
-               tm.tm_year + 1900
-       );
+       strftime_l(buf, 32, "%A, %x", &tm, wc_locales[WC->selected_language]);
+       wprintf("%s", buf);
 }
 
 
index ecd8d5d2de3eb9933fdc5746c961b3e68211dac9..0684163d2f7e920b55bf0de96ebee11e78dec555 100644 (file)
 #include <iconv.h>
 #endif
 
-#include "gettext.h"
-
-#if ENABLE_NLS
+#ifdef ENABLE_NLS
+#include <libintl.h>
 #include <locale.h>
+extern locale_t wc_locales[];
 #define _(string)      gettext(string)
 #else
 #define _(string)      (string)