aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mac.c')
-rw-r--r--src/mac.c82
1 files changed, 77 insertions, 5 deletions
diff --git a/src/mac.c b/src/mac.c
index da6a61633dc..68e3bdfa065 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -31,6 +31,8 @@ Boston, MA 02111-1307, USA. */
31#include "sysselect.h" 31#include "sysselect.h"
32#include "systime.h" 32#include "systime.h"
33#include "blockinput.h" 33#include "blockinput.h"
34#include "charset.h"
35#include "coding.h"
34 36
35#include "macterm.h" 37#include "macterm.h"
36 38
@@ -49,6 +51,7 @@ Boston, MA 02111-1307, USA. */
49#include <Events.h> 51#include <Events.h>
50#include <Processes.h> 52#include <Processes.h>
51#include <EPPC.h> 53#include <EPPC.h>
54#include <MacLocales.h>
52#endif /* not HAVE_CARBON */ 55#endif /* not HAVE_CARBON */
53 56
54#include <utime.h> 57#include <utime.h>
@@ -67,6 +70,12 @@ Boston, MA 02111-1307, USA. */
67 70
68Lisp_Object QCLIPBOARD; 71Lisp_Object QCLIPBOARD;
69 72
73/* The system script code. */
74static int mac_system_script_code;
75
76/* The system locale identifier string. */
77static Lisp_Object Vmac_system_locale;
78
70/* An instance of the AppleScript component. */ 79/* An instance of the AppleScript component. */
71static ComponentInstance as_scripting_component; 80static ComponentInstance as_scripting_component;
72/* The single script context used for all script executions. */ 81/* The single script context used for all script executions. */
@@ -258,7 +267,6 @@ posix_to_mac_pathname (const char *ufn, char *mfn, int mfnbuflen)
258#if TARGET_API_MAC_CARBON 267#if TARGET_API_MAC_CARBON
259static Lisp_Object Qstring, Qnumber, Qboolean, Qdate, Qdata; 268static Lisp_Object Qstring, Qnumber, Qboolean, Qdate, Qdata;
260static Lisp_Object Qarray, Qdictionary; 269static Lisp_Object Qarray, Qdictionary;
261extern Lisp_Object Qutf_8;
262#define DECODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 0) 270#define DECODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 0)
263 271
264struct cfdict_context 272struct cfdict_context
@@ -267,7 +275,7 @@ struct cfdict_context
267 int with_tag, hash_bound; 275 int with_tag, hash_bound;
268}; 276};
269 277
270/* C string to CFString. */ 278/* C string to CFString. */
271 279
272CFStringRef 280CFStringRef
273cfstring_create_with_utf8_cstring (c_str) 281cfstring_create_with_utf8_cstring (c_str)
@@ -284,6 +292,37 @@ cfstring_create_with_utf8_cstring (c_str)
284} 292}
285 293
286 294
295/* Lisp string to CFString. */
296
297CFStringRef
298cfstring_create_with_string (s)
299 Lisp_Object s;
300{
301 CFStringRef string = NULL;
302
303 if (STRING_MULTIBYTE (s))
304 {
305 char *p, *end = SDATA (s) + SBYTES (s);
306
307 for (p = SDATA (s); p < end; p++)
308 if (!isascii (*p))
309 {
310 s = ENCODE_UTF_8 (s);
311 break;
312 }
313 string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s),
314 kCFStringEncodingUTF8, false);
315 }
316
317 if (string == NULL)
318 /* Failed to interpret as UTF 8. Fall back on Mac Roman. */
319 string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s),
320 kCFStringEncodingMacRoman, false);
321
322 return string;
323}
324
325
287/* From CFData to a lisp string. Always returns a unibyte string. */ 326/* From CFData to a lisp string. Always returns a unibyte string. */
288 327
289Lisp_Object 328Lisp_Object
@@ -3704,11 +3743,11 @@ otherwise. */)
3704 app_id = kCFPreferencesCurrentApplication; 3743 app_id = kCFPreferencesCurrentApplication;
3705 if (!NILP (application)) 3744 if (!NILP (application))
3706 { 3745 {
3707 app_id = cfstring_create_with_utf8_cstring (SDATA (application)); 3746 app_id = cfstring_create_with_string (application);
3708 if (app_id == NULL) 3747 if (app_id == NULL)
3709 goto out; 3748 goto out;
3710 } 3749 }
3711 key_str = cfstring_create_with_utf8_cstring (SDATA (XCAR (key))); 3750 key_str = cfstring_create_with_string (XCAR (key));
3712 if (key_str == NULL) 3751 if (key_str == NULL)
3713 goto out; 3752 goto out;
3714 app_plist = CFPreferencesCopyAppValue (key_str, app_id); 3753 app_plist = CFPreferencesCopyAppValue (key_str, app_id);
@@ -3721,7 +3760,7 @@ otherwise. */)
3721 { 3760 {
3722 if (CFGetTypeID (plist) != CFDictionaryGetTypeID ()) 3761 if (CFGetTypeID (plist) != CFDictionaryGetTypeID ())
3723 break; 3762 break;
3724 key_str = cfstring_create_with_utf8_cstring (SDATA (XCAR (key))); 3763 key_str = cfstring_create_with_string (XCAR (key));
3725 if (key_str == NULL) 3764 if (key_str == NULL)
3726 goto out; 3765 goto out;
3727 plist = CFDictionaryGetValue (plist, key_str); 3766 plist = CFDictionaryGetValue (plist, key_str);
@@ -4167,6 +4206,29 @@ init_mac_osx_environment ()
4167} 4206}
4168#endif /* MAC_OSX */ 4207#endif /* MAC_OSX */
4169 4208
4209
4210static Lisp_Object
4211mac_get_system_locale ()
4212{
4213 OSErr err;
4214 LangCode lang;
4215 RegionCode region;
4216 LocaleRef locale;
4217 Str255 str;
4218
4219 lang = GetScriptVariable (smSystemScript, smScriptLang);
4220 region = GetScriptManagerVariable (smRegionCode);
4221 err = LocaleRefFromLangOrRegionCode (lang, region, &locale);
4222 if (err == noErr)
4223 err = LocaleRefGetPartString (locale, kLocaleAllPartsMask,
4224 sizeof (str), str);
4225 if (err == noErr)
4226 return build_string (str);
4227 else
4228 return Qnil;
4229}
4230
4231
4170void 4232void
4171syms_of_mac () 4233syms_of_mac ()
4172{ 4234{
@@ -4197,6 +4259,16 @@ syms_of_mac ()
4197 defsubr (&Sdo_applescript); 4259 defsubr (&Sdo_applescript);
4198 defsubr (&Smac_file_name_to_posix); 4260 defsubr (&Smac_file_name_to_posix);
4199 defsubr (&Sposix_file_name_to_mac); 4261 defsubr (&Sposix_file_name_to_mac);
4262
4263 DEFVAR_INT ("mac-system-script-code", &mac_system_script_code,
4264 doc: /* The system script code. */);
4265 mac_system_script_code = (ScriptCode) GetScriptManagerVariable (smSysScript);
4266
4267 DEFVAR_LISP ("mac-system-locale", &Vmac_system_locale,
4268 doc: /* The system locale identifier string.
4269This is not a POSIX locale ID, but an ICU locale ID. So encoding
4270information is not included. */);
4271 Vmac_system_locale = mac_get_system_locale ();
4200} 4272}
4201 4273
4202/* arch-tag: 29d30c1f-0c6b-4f88-8a6d-0558d7f9dbff 4274/* arch-tag: 29d30c1f-0c6b-4f88-8a6d-0558d7f9dbff