From 81b98869002ec69ad72a9237305a423a7ce7f108 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 12 Feb 2006 05:10:31 +0000 Subject: [PATCH] Began moving date outputs to strftime_l() --- webcit/calendar_view.c | 10 +++--- webcit/configure.in | 24 ++++++++------ webcit/fmt_date.c | 17 +--------- webcit/gettext.c | 12 ++++++- webcit/gettext.h | 71 ------------------------------------------ webcit/summary.c | 33 ++------------------ webcit/webcit.h | 6 ++-- 7 files changed, 39 insertions(+), 134 deletions(-) delete mode 100644 webcit/gettext.h diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index f5756114f..d071ca4a2 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -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("%i:%i" + wprintf("%i:%2i" "" "", 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("" "%s%s", @@ -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("" " \n", _("Week"), diff --git a/webcit/configure.in b/webcit/configure.in index 625b547b7..6a863d8ee 100644 --- a/webcit/configure.in +++ b/webcit/configure.in @@ -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 - #include - main() { - char *foo; - uselocale(LC_GLOBAL_LOCALE); - foo = gettext("bar"); - exit(0); + #define _GNU_SOURCE + #include + #include + #include + 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, diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c index 0475f91cf..cdc4f1803 100644 --- a/webcit/fmt_date.c +++ b/webcit/fmt_date.c @@ -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]); } } diff --git a/webcit/gettext.c b/webcit/gettext.c index 3596c5d7c..c83c41ee0 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -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 index 4e3cbd2a8..000000000 --- a/webcit/gettext.h +++ /dev/null @@ -1,71 +0,0 @@ - - -/* Convenience header for conditional use of GNU . - 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 - -#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 a NOP. We don't include - as well because people using "gettext.h" will not include , - and also including would fail on SunOS 4, whereas - is OK. */ -#if defined(__sun) -# include -#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 */ diff --git a/webcit/summary.c b/webcit/summary.c index 77f6cd502..0c309364f 100644 --- a/webcit/summary.c +++ b/webcit/summary.c @@ -14,40 +14,13 @@ 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); } diff --git a/webcit/webcit.h b/webcit/webcit.h index ecd8d5d2d..0684163d2 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -45,10 +45,10 @@ #include #endif -#include "gettext.h" - -#if ENABLE_NLS +#ifdef ENABLE_NLS +#include #include +extern locale_t wc_locales[]; #define _(string) gettext(string) #else #define _(string) (string) -- 2.39.2
%s %s
%s%s%s%s