bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Building and testing Bison 3.0.2 with MinGW [3/5]


From: Eli Zaretskii
Subject: Re: Building and testing Bison 3.0.2 with MinGW [3/5]
Date: Mon, 26 Jan 2015 20:03:16 +0200

> From: Akim Demaille <address@hidden>
> Date: Thu, 22 Jan 2015 16:20:16 +0100
> Cc: Bison Bugs <address@hidden>
> 
> > --- /dev/null       1970-01-01 02:00:00 +0200
> > +++ src/mingw-setlocale.c   2015-01-20 18:48:47 +0200
> > @@ -0,0 +1,26 @@
> > +#ifdef __MINGW32__
> > +static void
> > +mingw_setlocale (void)
> 
> That would be great!  Put a #define setlocale  mingw_setlocale
> in system.h, and I'm the happiest Bison maintainer in the world :)

It's not _that_ easy.

Does the below make you happy enough?

--- src/main.c~0        2014-10-07 07:45:06 +0300
+++ src/main.c  2015-01-25 12:54:03 +0200
@@ -221,3 +221,5 @@ main (int argc, char *argv[])
 
   return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
 }
+
+#include "mingw-setlocale.c"


--- src/system.h~0      2013-08-02 17:35:13 +0300
+++ src/system.h        2015-01-25 13:05:18 +0200
@@ -39,6 +39,18 @@
 # include <stdlib.h>
 # include <string.h>
 
+# ifdef __MINGW32__
+/* This is needed to get O_TEXT for output.c  */
+#  include <fcntl.h>
+/* This is needed for mbschr in parse-gram.y  */
+#  include <mbstring.h>
+/* This is needed to get the prototype of 'setlocale' before we
+   redirect it to 'mingw_setlocale'.  */
+#  include <locale.h>
+#  define setlocale(c,v)  mingw_setlocale(c,v)
+char * mingw_setlocale (int, const char *);
+# endif
+
 # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
 # define STREQ(L, R)  (strcmp(L, R) == 0)
 # define STRNEQ(L, R) (!STREQ(L, R))


--- /dev/null   1970-01-01 02:00:00 +0200
+++ src/mingw-setlocale.c       2015-01-25 13:19:41 +0200
@@ -0,0 +1,38 @@
+#ifdef __MINGW32__
+
+#undef setlocale
+
+char *
+mingw_setlocale (int cat, const char *val)
+{
+  char *retval;
+
+  if (cat == LC_ALL && val && val[0] == '\0')
+    {
+      /* The Windows 'setlocale' doesn't look at the environment
+        variables, so do it here by hand.  */
+      char const *cp = getenv ("LC_ALL");
+
+      if (cp)
+       retval = setlocale (LC_ALL, cp);
+      else
+       {
+         retval = setlocale (LC_ALL, val);
+         if ((cp = getenv ("LANG")) != NULL)
+           setlocale (LC_ALL, cp);
+         if ((cp = getenv ("LC_COLLATE")) != NULL)
+           setlocale (LC_COLLATE, cp);
+         if ((cp = getenv ("LC_CTYPE")) != NULL)
+           setlocale (LC_CTYPE, cp);
+         if ((cp = getenv ("LC_NUMERIC")) != NULL)
+           setlocale (LC_NUMERIC, cp);
+         if ((cp = getenv ("LC_MONETARY")) != NULL)
+           setlocale (LC_MONETARY, cp);
+         if ((cp = getenv ("LC_TIME")) != NULL)
+           setlocale (LC_TIME, cp);
+       }
+    }
+  else
+    return setlocale (cat, val);
+}
+#endif /* __MINGW32__ */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]