Fix #683: Build fails on macOS due to use of _NL_TIME_FIRST_WEEKDAY
authorColin Clark <colin.clark@cclark.uk>
Sat, 3 Aug 2019 11:25:16 +0000 (12:25 +0100)
committerKlaus Ethgen <Klaus@Ethgen.de>
Tue, 20 Aug 2019 18:32:18 +0000 (19:32 +0100)
https://github.com/BestImageViewer/geeqie/issues/683

configure.ac
src/misc.c

index 4e81943..96ad5ae 100644 (file)
@@ -583,6 +583,21 @@ AC_SUBST(PDF_LIBS)
 
 AM_CONDITIONAL(HAVE_MARKDOWN, [ "$(command -v markdown)" ])
 
+# _NL_TIME_FIRST_WEEKDAY support
+# note that it is an enum and not a define
+# ----------------------------------------------------------------------
+
+AC_MSG_CHECKING([for _NL_TIME_FIRST_WEEKDAY])
+AC_TRY_LINK([#include <langinfo.h>], [
+char c;
+c = *((unsigned char *)  nl_langinfo(_NL_TIME_FIRST_WEEKDAY));
+], nl_ok=yes, nl_ok=no)
+AC_MSG_RESULT($nl_ok)
+if test "$nl_ok" = "yes"; then
+  AC_DEFINE([HAVE__NL_TIME_FIRST_WEEKDAY], [1],
+      [Define if _NL_TIME_FIRST_WEEKDAY is available])
+fi
+
 # ----------------------------------------------------------------------
 
 AH_TOP([
index d780795..85c8765 100644 (file)
@@ -23,6 +23,7 @@
 #include "ui_fileops.h"
 
 #include <langinfo.h>
+#include <locale.h>
 
 gdouble get_zoom_increment(void)
 {
@@ -243,13 +244,32 @@ int runcmd(gchar *cmd)
  * @brief Returns integer representing first_day_of_week
  * @returns Integer in range 1 to 7
  * 
- * Uses current locale to get first day of week
+ * Uses current locale to get first day of week.
+ * If _NL_TIME_FIRST_WEEKDAY is not available, ISO 8601
+ * states first day of week is Monday.
+ * USA, Mexico and Canada (and others) use Sunday as first day of week.
  * 
  * Sunday == 1
  */
 gint date_get_first_day_of_week()
 {
+       gchar *dot;
+       gchar *current_locale;
+
+#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
        return nl_langinfo(_NL_TIME_FIRST_WEEKDAY)[0];
+#else
+       current_locale = setlocale(LC_ALL, NULL);
+       dot = strstr(current_locale, ".");
+       if ((strncmp(dot - 2, "US", 2) == 0) || (strncmp(dot - 2, "MX", 2) == 0) || (strncmp(dot - 2, "CA", 2) == 0))
+               {
+               return 1;
+               }
+       else
+               {
+               return 2;
+               }
+#endif
 }
 
 /**