diff Python/mactoolboxglue.c @ 26415:d58824ceb35d legacy-trunk

Patch #632973: Implement _getdefaultlocale for OS X.
author Martin v. Löwis <martin@v.loewis.de>
date Tue, 26 Nov 2002 09:05:36 +0000
parents 076512a0c6c2
children 6b31b26e418d
line wrap: on
line diff
--- a/Python/mactoolboxglue.c	Tue Nov 26 08:06:50 2002 +0000
+++ b/Python/mactoolboxglue.c	Tue Nov 26 09:05:36 2002 +0000
@@ -38,11 +38,22 @@
 char *PyMac_getscript()
 {
 #if TARGET_API_MAC_OSX
-    /* We cannot use GetSysFont because it requires the window manager
-    ** There are other APIs to query the default 8 bit encoding, but
-    ** I don't know about them (yet).
-    */
-    return "ascii";
+    CFStringEncoding enc = CFStringGetSystemEncoding();
+    static CFStringRef name = NULL;
+    /* Return the code name for the encodings for which we have codecs. */
+    switch(enc) {
+    case kCFStringEncodingMacRoman: return "mac-roman";
+    case kCFStringEncodingMacGreek: return "mac-greek";
+    case kCFStringEncodingMacCyrillic: return "mac-cyrillic";
+    case kCFStringEncodingMacTurkish: return "mac-turkish";
+    case kCFStringEncodingMacIcelandic: return "mac-icelandic";
+    /* XXX which one is mac-latin2? */
+    }
+    if (!name) {
+        /* This leaks a an object. */
+        name = CFStringConvertEncodingToIANACharSetName(enc);
+    }
+    return CFStringGetCStringPtr(name, 0); 
 #else
    int font, script, lang;
     font = 0;