]> git.sesse.net Git - vlc/blobdiff - src/text/wincp.c
Remove useless <errno.h> inclusions
[vlc] / src / text / wincp.c
index d0447e19a22dd1c2ba60611ee3ba6d0023e70e6a..66013c4f0dbb6c8a57b2b3303856d974ed9c88df 100644 (file)
 
 /*** We need your help to complete this file!! Look for FIXME ***/
 
-#include <vlc/vlc.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 
 #ifndef WIN32
 # include <locale.h>
@@ -34,7 +35,6 @@
 #endif
 
 #ifdef __APPLE__
-#   include <errno.h>
 #   include <string.h>
 #endif
 
@@ -58,7 +58,7 @@ static const char *FindFallbackEncoding (const char *locale)
 {
     if ((locale == NULL) || (strlen (locale) < 2)
      || !strcasecmp (locale, "POSIX"))
-        return "ASCII";
+        return "CP1252"; /* Yeah, this is totally western-biased */
 
 
     /*** The ISO-8859 series (anything but Asia) ***/
@@ -84,12 +84,14 @@ static const char *FindFallbackEncoding (const char *locale)
     // -> Latin-1 instead
 
     /* Cyrillic alphabet languages (ISO-8859-5) */
-    static const char cyrillic[] = "be" "bg" "mk" "ru" "sr";
+    static const char cyrillic[] = "be" "bg" "mk" "ru" "sr" "mn";
+    // FIXME: cyrillic only true for mn in Mongolia
     if (!locale_match (cyrillic, locale))
         return "CP1251"; // KOI8, ISO-8859-5 and CP1251 are incompatible(?)
 
     /* Arabic (ISO-8859-6) */
-    if (!locale_match ("ar", locale))
+    static const char arabic[] = "ar" "fa";
+    if (!locale_match (arabic, locale))
         // FIXME: someone check if we should return CP1256 or ISO-8859-6
         return "CP1256"; // CP1256 is(?) more common, but incompatible(?)
 
@@ -100,7 +102,7 @@ static const char *FindFallbackEncoding (const char *locale)
 
     /* Hebrew (ISO-8859-8) */
     if (!locale_match ("he" "iw" "yi", locale))
-        return "CP1255"; // Compatible Microsoft superset
+        return "ISO-8859-8"; // CP1255 is reportedly screwed up
 
     /* Latin-5 Turkish (ISO-8859-9) */
     if (!locale_match ("tr" "ku", locale))
@@ -142,10 +144,12 @@ static const char *FindFallbackEncoding (const char *locale)
 
     // Korean
     if (!locale_match ("ko", locale))
-        return "EUC-KR";
+        return "CP949"; // Microsoft non-standard superset of EUC-KR
 
     // Thai
-    if (!locale_match ("th", locale))
+    static const char thai[] = "th" "km" "lo";
+    //FIXME: afaik, khmer and lao are/were not in windows and are close to tahi
+    if (!locale_match (thai, locale))
         return "TIS-620";
 
     // Vietnamese (FIXME: more infos needed)
@@ -194,28 +198,33 @@ static const char *FindFallbackEncoding (const char *locale)
 const char *GetFallbackEncoding( void )
 {
 #ifndef WIN32
-    const char *psz_lang = NULL;
-
-    /* Some systems (like Darwin, SunOS 4 or DJGPP) have only the C locale.
-     * Therefore we don't use setlocale here; it would return "C". */
-#  if defined (HAVE_SETLOCALE) && !defined ( __APPLE__)
-    psz_lang = setlocale (LC_ALL, NULL);
-#  endif
-    if (psz_lang == NULL)
+    const char *psz_lang;
+
+    psz_lang = getenv ("LC_ALL");
+    if ((psz_lang == NULL) || !*psz_lang)
     {
-        psz_lang = getenv ("LC_ALL");
+        psz_lang = getenv ("LC_CTYPE");
         if ((psz_lang == NULL) || !*psz_lang)
-        {
-            psz_lang = getenv ("LC_CTYPE");
-            if ((psz_lang == NULL))
-                psz_lang = getenv ("LANG");
-        }
+            psz_lang = getenv ("LANG");
     }
 
     return FindFallbackEncoding (psz_lang);
 #else
+    static char buf[16] = "";
+
     if (buf[0] == 0)
-        snprintf (buf, sizeof (buf), "CP%u", GetACP ());
+    {
+        int cp = GetACP ();
+
+        switch (cp)
+        {
+            case 1255: // Hebrew, CP1255 screws up somewhat
+                strcpy (buf, "ISO-8859-8");
+                break;
+            default:
+                snprintf (buf, sizeof (buf), "CP%u", cp);
+        }
+    }
     return buf;
 #endif
 }