Mercurial > emacs
comparison src/mac.c @ 90147:e1fbb019c538
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-39
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 258-271)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 66)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 21 Apr 2005 05:59:53 +0000 |
parents | 02f1dbc4a199 4fdfaa49202b |
children | 08185296b491 |
comparison
equal
deleted
inserted
replaced
90146:a4445dd2a017 | 90147:e1fbb019c538 |
---|---|
29 #include "lisp.h" | 29 #include "lisp.h" |
30 #include "process.h" | 30 #include "process.h" |
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 |
37 #ifndef HAVE_CARBON | 39 #ifndef HAVE_CARBON |
38 #include <Files.h> | 40 #include <Files.h> |
47 #include <AppleScript.h> | 49 #include <AppleScript.h> |
48 #include <Scrap.h> | 50 #include <Scrap.h> |
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> |
55 #include <dirent.h> | 58 #include <dirent.h> |
56 #include <sys/types.h> | 59 #include <sys/types.h> |
64 #if __MWERKS__ | 67 #if __MWERKS__ |
65 #include <unistd.h> | 68 #include <unistd.h> |
66 #endif | 69 #endif |
67 | 70 |
68 Lisp_Object QCLIPBOARD; | 71 Lisp_Object QCLIPBOARD; |
72 | |
73 /* The system script code. */ | |
74 static int mac_system_script_code; | |
75 | |
76 /* The system locale identifier string. */ | |
77 static Lisp_Object Vmac_system_locale; | |
69 | 78 |
70 /* An instance of the AppleScript component. */ | 79 /* An instance of the AppleScript component. */ |
71 static ComponentInstance as_scripting_component; | 80 static ComponentInstance as_scripting_component; |
72 /* The single script context used for all script executions. */ | 81 /* The single script context used for all script executions. */ |
73 static OSAID as_script_context; | 82 static OSAID as_script_context; |
256 ***********************************************************************/ | 265 ***********************************************************************/ |
257 | 266 |
258 #if TARGET_API_MAC_CARBON | 267 #if TARGET_API_MAC_CARBON |
259 static Lisp_Object Qstring, Qnumber, Qboolean, Qdate, Qdata; | 268 static Lisp_Object Qstring, Qnumber, Qboolean, Qdate, Qdata; |
260 static Lisp_Object Qarray, Qdictionary; | 269 static Lisp_Object Qarray, Qdictionary; |
261 extern 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 |
264 struct cfdict_context | 272 struct cfdict_context |
265 { | 273 { |
266 Lisp_Object *result; | 274 Lisp_Object *result; |
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 |
272 CFStringRef | 280 CFStringRef |
273 cfstring_create_with_utf8_cstring (c_str) | 281 cfstring_create_with_utf8_cstring (c_str) |
274 const char *c_str; | 282 const char *c_str; |
275 { | 283 { |
279 if (str == NULL) | 287 if (str == NULL) |
280 /* Failed to interpret as UTF 8. Fall back on Mac Roman. */ | 288 /* Failed to interpret as UTF 8. Fall back on Mac Roman. */ |
281 str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingMacRoman); | 289 str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingMacRoman); |
282 | 290 |
283 return str; | 291 return str; |
292 } | |
293 | |
294 | |
295 /* Lisp string to CFString. */ | |
296 | |
297 CFStringRef | |
298 cfstring_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; | |
284 } | 323 } |
285 | 324 |
286 | 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 |
3702 BLOCK_INPUT; | 3741 BLOCK_INPUT; |
3703 | 3742 |
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); |
3715 CFRelease (key_str); | 3754 CFRelease (key_str); |
3716 if (app_plist == NULL) | 3755 if (app_plist == NULL) |
3719 plist = app_plist; | 3758 plist = app_plist; |
3720 for (key = XCDR (key); CONSP (key); key = XCDR (key)) | 3759 for (key = XCDR (key); CONSP (key); key = XCDR (key)) |
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); |
3728 CFRelease (key_str); | 3767 CFRelease (key_str); |
3729 if (plist == NULL) | 3768 if (plist == NULL) |
4165 setenv ("INFOPATH", p, 1); | 4204 setenv ("INFOPATH", p, 1); |
4166 } | 4205 } |
4167 } | 4206 } |
4168 #endif /* MAC_OSX */ | 4207 #endif /* MAC_OSX */ |
4169 | 4208 |
4209 | |
4210 static Lisp_Object | |
4211 mac_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 | |
4170 void | 4232 void |
4171 syms_of_mac () | 4233 syms_of_mac () |
4172 { | 4234 { |
4173 QCLIPBOARD = intern ("CLIPBOARD"); | 4235 QCLIPBOARD = intern ("CLIPBOARD"); |
4174 staticpro (&QCLIPBOARD); | 4236 staticpro (&QCLIPBOARD); |
4195 defsubr (&Smac_clear_font_name_table); | 4257 defsubr (&Smac_clear_font_name_table); |
4196 | 4258 |
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. | |
4269 This is not a POSIX locale ID, but an ICU locale ID. So encoding | |
4270 information 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 |
4203 (do not change this comment) */ | 4275 (do not change this comment) */ |