emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master bedf905: Fix the MS-Windows build as followup to Gn


From: Eli Zaretskii
Subject: [Emacs-diffs] master bedf905: Fix the MS-Windows build as followup to Gnulib regex import
Date: Mon, 6 Aug 2018 10:52:14 -0400 (EDT)

branch: master
commit bedf905dd37ef8ad45d5912dd230bfe63a1721b3
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix the MS-Windows build as followup to Gnulib regex import
    
    * lib-src/ntlib.c (nl_langinfo): New function.  (Bug#32194)
---
 lib-src/ntlib.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c
index 9551285..4ca521d 100644
--- a/lib-src/ntlib.c
+++ b/lib-src/ntlib.c
@@ -31,6 +31,10 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include <ctype.h>
 #include <sys/timeb.h>
 #include <mbstring.h>
+#include <locale.h>
+
+#include <nl_types.h>
+#include <langinfo.h>
 
 #include "ntlib.h"
 
@@ -423,3 +427,66 @@ sys_open (const char * path, int oflag, int mode)
 {
   return _open (path, oflag, mode);
 }
+
+/* Emulation of nl_langinfo that supports only CODESET.
+   Used in Gnulib regex.c.  */
+char *
+nl_langinfo (nl_item item)
+{
+  switch (item)
+    {
+      case CODESET:
+       {
+         /* Shamelessly stolen from Gnulib's nl_langinfo.c, modulo
+            CPP directives.  */
+         static char buf[2 + 10 + 1];
+         char const *locale = setlocale (LC_CTYPE, NULL);
+         char *codeset = buf;
+         size_t codesetlen;
+         codeset[0] = '\0';
+
+         if (locale && locale[0])
+           {
+             /* If the locale name contains an encoding after the
+                dot, return it.  */
+             char *dot = strchr (locale, '.');
+
+             if (dot)
+               {
+                 /* Look for the possible @... trailer and remove it,
+                    if any.  */
+                 char *codeset_start = dot + 1;
+                 char const *modifier = strchr (codeset_start, '@');
+
+                 if (! modifier)
+                   codeset = codeset_start;
+                 else
+                   {
+                     codesetlen = modifier - codeset_start;
+                     if (codesetlen < sizeof buf)
+                       {
+                         codeset = memcpy (buf, codeset_start, codesetlen);
+                         codeset[codesetlen] = '\0';
+                       }
+                   }
+               }
+           }
+         /* If setlocale is successful, it returns the number of the
+            codepage, as a string.  Otherwise, fall back on Windows
+            API GetACP, which returns the locale's codepage as a
+            number (although this doesn't change according to what
+            the 'setlocale' call specified).  Either way, prepend
+            "CP" to make it a valid codeset name.  */
+         codesetlen = strlen (codeset);
+         if (0 < codesetlen && codesetlen < sizeof buf - 2)
+           memmove (buf + 2, codeset, codesetlen + 1);
+         else
+           sprintf (buf + 2, "%u", GetACP ());
+         codeset = memcpy (buf, "CP", 2);
+
+         return codeset;
+       }
+      default:
+       return (char *) "";
+    }
+}



reply via email to

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