This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fetch week start value for gcal 3.01 from locale


Here is a patch to gcal to get it to use the locale value for
week_start when selecting default start day for the week.  After
looking at the code, I suspect it is a good idea to remove all the
special handling (USE_DE, GCAL_NLS and is_en) and only use the locale
values.  Some glibc locales need to be updated to get this to work,
but that should not be too hard. :)

I've tested the patch with the bg_BG, fa_IR and C locale, and got
monday, saturday and sunday as first day of week as expected. :)

Please include the patch in the next version of gcal.  I hope I was
able to extract the correct pieces of my local changes. :)

I send a copy to the glibc developer list, because this topic have
come up in the past, when discussing how to test if the week_start
values for a given locale is correct.  It would be nice if gcal would
release a version with this patch, as it would give us a working test
program. :)

diff -ur gcal-3.01-orig/configure.in gcal-3.01/configure.in
--- gcal-3.01-orig/configure.in	Wed Jun 14 02:03:00 2000
+++ gcal-3.01/configure.in	Thu Jan  1 15:28:25 2004
@@ -662,7 +662,7 @@
 dnl
 AC_STDC_HEADERS
 AC_CHECK_HEADERS(stdio.h stdlib.h string.h unistd.h ctype.h errno.h limits.h)
-AC_CHECK_HEADERS(assert.h signal.h termio.h termios.h sgtty.h)
+AC_CHECK_HEADERS(assert.h signal.h termio.h termios.h sgtty.h langinfo.h)
 if test "$gcal_cv_use_term" = yes; then
   if test "$gcal_ttylibs_ok" = yes || test "$gcal_libtermlib_ok" = yes; then
     AC_CHECK_HEADERS(termcap.h)
@@ -740,7 +740,7 @@
 if test "$gcal_cv_use_pager" = yes; then
   AC_CHECK_FUNCS([dup dup2])
 fi
-AC_CHECK_FUNCS([signal strtol strstr strchr strrchr strcspn strcasecmp strncasecmp])
+AC_CHECK_FUNCS([signal strtol strstr strchr strrchr strcspn strcasecmp strncasecmp nl_langinfo])
 dnl
 dnl Some systems have termios.h but not the corresponding functions.
 dnl
diff -ur gcal-3.01-orig/src/gcal.c gcal-3.01/src/gcal.c
--- gcal-3.01-orig/src/gcal.c	Thu Jun 29 03:00:01 2000
+++ gcal-3.01/src/gcal.c	Thu Jan  1 16:42:17 2004
@@ -52,6 +54,10 @@
 #if HAVE_SYS_STAT_H
 #  include <sys/stat.h>
 #endif
+#if HAVE_LANGINFO_H
+#undef ERA /* langinfo.h define ERA conflict with define in tailor.h */
+#  include <langinfo.h>
+#endif /* HAVE_LANGINFO_H */
 #ifdef GCAL_EPAGER
 #  if HAVE_FCNTL_H
 #    include <fcntl.h>
@@ -6052,18 +6058,29 @@
         /*
            Set starting day of week to language/territory default value.
         */
-#if USE_DE
+#if HAVE_NL_LANGINFO
+  /* locale value is 1 (sunday) to 7 (saturday), start-day should be 1
+     (monday) to 7 (sunday) */
+
+  start_day = *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1 ;
+  if (0 == start_day) start_day = 7;
+
+#else /* not HAVE_NL_LANGINFO */
+
+#  if USE_DE
         start_day = DAY_MIN;
-#else /* !USE_DE */
-#  ifdef GCAL_NLS
+#  else /* !USE_DE */
+#    ifdef GCAL_NLS
         if (!is_en)
           start_day = DAY_MIN;
         else
           start_day = DAY_MAX;
-#  else /* !GCAL_NLS */
+#    else /* !GCAL_NLS */
         start_day = DAY_MAX;
-#  endif /* !GCAL_NLS */
-#endif /* !USE_DE */
+#    endif /* !GCAL_NLS */
+#  endif /* !USE_DE */
+#endif /* not HAVE_NL_LANGINFO */
+
       }
    /*
       Post-process a time offset argument, which is based relative to


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]