texinfo-commits
[Top][All Lists]
Advanced

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

[6410] try harder to get UTF-8 locale


From: Gavin D. Smith
Subject: [6410] try harder to get UTF-8 locale
Date: Sat, 11 Jul 2015 12:42:23 +0000

Revision: 6410
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6410
Author:   gavin
Date:     2015-07-11 12:42:21 +0000 (Sat, 11 Jul 2015)
Log Message:
-----------
try harder to get UTF-8 locale

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Convert/XSParagraph/mylib/xspara.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-07-11 07:15:10 UTC (rev 6409)
+++ trunk/ChangeLog     2015-07-11 12:42:21 UTC (rev 6410)
@@ -1,3 +1,9 @@
+2015-07-11  Gavin Smith  <address@hidden>
+
+       * tp/Texinfo/Convert/XSParagraph/mylib/xspara.c (xspara_hello): 
+       If setting "en_US.UTF-8" as the locale fails, try basing a 
+       locale name on the current locale name.
+
 2015-07-11  Eli Zaretskii  <address@hidden>
 
        * info/pcterm.c (highvideo, normvideo) [_WIN32]: New functions.

Modified: trunk/tp/Texinfo/Convert/XSParagraph/mylib/xspara.c
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/mylib/xspara.c 2015-07-11 07:15:10 UTC 
(rev 6409)
+++ trunk/tp/Texinfo/Convert/XSParagraph/mylib/xspara.c 2015-07-11 12:42:21 UTC 
(rev 6410)
@@ -72,15 +72,51 @@
 void
 xspara_hello (void)
 {
+  char *utf8_locale = 0;
+  int len;
+  char *cur;
+  char *dot;
+
   //puts ("initializing XSParagraph");
-  if (!setlocale (LC_CTYPE, "en_US.UTF-8")
-      && !setlocale (LC_CTYPE, "en_US.utf8"))
+  if (setlocale (LC_CTYPE, "en_US.UTF-8")
+      || setlocale (LC_CTYPE, "en_US.utf8"))
+    goto success;
+
+  cur = setlocale (LC_CTYPE, 0); /* Name of current locale. */
+  if (!cur)
+    goto failure;
+  len = strlen (cur);
+  if (len >= 6 && !memcmp (".UTF-8", cur + len - 6, 6)
+      || len >= 5 && !memcmp (".utf8", cur + len - 5, 5)
+      || len >= 6 && !memcmp (".utf-8", cur + len - 6, 6)
+      || len >= 5 && !memcmp (".UTF8", cur + len - 5, 5))
+    goto success; /* In a UTF-8 locale already. */
+
+  /* Otherwise try altering the current locale name. */
+  dot = strchr (cur, '.');
+  if (!dot)
+    dot = cur + len;
+  utf8_locale = malloc (len + 6 + 1); /* enough to add ".UTF-8" to end */
+  memcpy (utf8_locale, cur, dot - cur);
+  dot = utf8_locale + (dot - cur);
+  memcpy (dot, ".UTF-8", 7);
+  if (setlocale (LC_CTYPE, utf8_locale))
+    goto success;
+
+  memcpy (dot, ".utf8", 6);
+  if (setlocale (LC_CTYPE, utf8_locale))
+    goto success;
+      
+  if (1)
     {
+failure:
       fprintf (stderr, "Couldn't set UTF-8 character type in locale.\n");
       abort ();
     }
   else
     {
+success: ;
+      free (utf8_locale);
       /*
       fprintf (stderr, "tried to set LC_CTYPE to UTF-8.\n");
       fprintf (stderr, "character encoding is: %s\n",




reply via email to

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