aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
authorKaroly Lorentey2005-09-04 03:48:17 +0000
committerKaroly Lorentey2005-09-04 03:48:17 +0000
commitfbf349734468d48b421c3d03074bb66dfcf3115b (patch)
tree0a7d1ee844b6c591a5a499d23e35931945106e5a /src/mac.c
parentf0caabd962b662cccbea472995d86af718cc8d0b (diff)
parent4b5fa40e1f1ba3cafde672863a0331311d1c2695 (diff)
downloademacs-fbf349734468d48b421c3d03074bb66dfcf3115b.tar.gz
emacs-fbf349734468d48b421c3d03074bb66dfcf3115b.zip
Merged in changes from CVS trunk. Plus added lisp/term tweaks.
Patches applied: * lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0 tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474 * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1 Add CVS metadata files. * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2 Update from CVS. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
Diffstat (limited to 'src/mac.c')
-rw-r--r--src/mac.c353
1 files changed, 322 insertions, 31 deletions
diff --git a/src/mac.c b/src/mac.c
index ef136ab6512..0d8c99ffb1e 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -1,5 +1,6 @@
1/* Unix emulation routines for GNU Emacs on the Mac OS. 1/* Unix emulation routines for GNU Emacs on the Mac OS.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
@@ -34,10 +35,9 @@ Boston, MA 02110-1301, USA. */
34 35
35#include "macterm.h" 36#include "macterm.h"
36 37
37#if TARGET_API_MAC_CARBON
38#include "charset.h" 38#include "charset.h"
39#include "coding.h" 39#include "coding.h"
40#else /* not TARGET_API_MAC_CARBON */ 40#if !TARGET_API_MAC_CARBON
41#include <Files.h> 41#include <Files.h>
42#include <MacTypes.h> 42#include <MacTypes.h>
43#include <TextUtils.h> 43#include <TextUtils.h>
@@ -53,17 +53,16 @@ Boston, MA 02110-1301, USA. */
53#include <Processes.h> 53#include <Processes.h>
54#include <EPPC.h> 54#include <EPPC.h>
55#include <MacLocales.h> 55#include <MacLocales.h>
56#include <Endian.h>
56#endif /* not TARGET_API_MAC_CARBON */ 57#endif /* not TARGET_API_MAC_CARBON */
57 58
58#include <utime.h> 59#include <utime.h>
59#include <dirent.h> 60#include <dirent.h>
60#include <sys/types.h> 61#include <sys/types.h>
61#include <sys/stat.h> 62#include <sys/stat.h>
62#include <string.h>
63#include <pwd.h> 63#include <pwd.h>
64#include <grp.h> 64#include <grp.h>
65#include <sys/param.h> 65#include <sys/param.h>
66#include <stdlib.h>
67#include <fcntl.h> 66#include <fcntl.h>
68#if __MWERKS__ 67#if __MWERKS__
69#include <unistd.h> 68#include <unistd.h>
@@ -1021,7 +1020,7 @@ xrm_cfproperty_list_to_value (plist)
1021 CFTypeID type_id = CFGetTypeID (plist); 1020 CFTypeID type_id = CFGetTypeID (plist);
1022 1021
1023 if (type_id == CFStringGetTypeID ()) 1022 if (type_id == CFStringGetTypeID ())
1024 return cfstring_to_lisp (plist); 1023 return cfstring_to_lisp (plist);
1025 else if (type_id == CFNumberGetTypeID ()) 1024 else if (type_id == CFNumberGetTypeID ())
1026 { 1025 {
1027 CFStringRef string; 1026 CFStringRef string;
@@ -2490,6 +2489,22 @@ chmod (const char *path, mode_t mode)
2490 2489
2491 2490
2492int 2491int
2492fchmod (int fd, mode_t mode)
2493{
2494 /* say it always succeed for now */
2495 return 0;
2496}
2497
2498
2499int
2500fchown (int fd, uid_t owner, gid_t group)
2501{
2502 /* say it always succeed for now */
2503 return 0;
2504}
2505
2506
2507int
2493dup (int oldd) 2508dup (int oldd)
2494{ 2509{
2495#ifdef __MRC__ 2510#ifdef __MRC__
@@ -3388,12 +3403,278 @@ initialize_applescript ()
3388} 3403}
3389 3404
3390 3405
3391void terminate_applescript() 3406void
3407terminate_applescript()
3392{ 3408{
3393 OSADispose (as_scripting_component, as_script_context); 3409 OSADispose (as_scripting_component, as_script_context);
3394 CloseComponent (as_scripting_component); 3410 CloseComponent (as_scripting_component);
3395} 3411}
3396 3412
3413/* Convert a lisp string to the 4 byte character code. */
3414
3415OSType
3416mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
3417{
3418 OSType result;
3419 if (NILP(arg))
3420 {
3421 result = defCode;
3422 }
3423 else
3424 {
3425 /* check type string */
3426 CHECK_STRING(arg);
3427 if (SBYTES (arg) != 4)
3428 {
3429 error ("Wrong argument: need string of length 4 for code");
3430 }
3431 result = EndianU32_BtoN (*((UInt32 *) SDATA (arg)));
3432 }
3433 return result;
3434}
3435
3436/* Convert the 4 byte character code into a 4 byte string. */
3437
3438Lisp_Object
3439mac_get_object_from_code(OSType defCode)
3440{
3441 UInt32 code = EndianU32_NtoB (defCode);
3442
3443 return make_unibyte_string ((char *)&code, 4);
3444}
3445
3446
3447DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1, 1, 0,
3448 doc: /* Get the creator code of FILENAME as a four character string. */)
3449 (filename)
3450 Lisp_Object filename;
3451{
3452 OSErr status;
3453#ifdef MAC_OSX
3454 FSRef fref;
3455#else
3456 FSSpec fss;
3457#endif
3458 OSType cCode;
3459 Lisp_Object result = Qnil;
3460 CHECK_STRING (filename);
3461
3462 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3463 return Qnil;
3464 }
3465 filename = Fexpand_file_name (filename, Qnil);
3466
3467 BLOCK_INPUT;
3468#ifdef MAC_OSX
3469 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3470#else
3471 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3472#endif
3473
3474 if (status == noErr)
3475 {
3476#ifdef MAC_OSX
3477 FSCatalogInfo catalogInfo;
3478
3479 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3480 &catalogInfo, NULL, NULL, NULL);
3481#else
3482 FInfo finder_info;
3483
3484 status = FSpGetFInfo (&fss, &finder_info);
3485#endif
3486 if (status == noErr)
3487 {
3488#ifdef MAC_OSX
3489 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator);
3490#else
3491 result = mac_get_object_from_code (finder_info.fdCreator);
3492#endif
3493 }
3494 }
3495 UNBLOCK_INPUT;
3496 if (status != noErr) {
3497 error ("Error while getting file information.");
3498 }
3499 return result;
3500}
3501
3502DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
3503 doc: /* Get the type code of FILENAME as a four character string. */)
3504 (filename)
3505 Lisp_Object filename;
3506{
3507 OSErr status;
3508#ifdef MAC_OSX
3509 FSRef fref;
3510#else
3511 FSSpec fss;
3512#endif
3513 OSType cCode;
3514 Lisp_Object result = Qnil;
3515 CHECK_STRING (filename);
3516
3517 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3518 return Qnil;
3519 }
3520 filename = Fexpand_file_name (filename, Qnil);
3521
3522 BLOCK_INPUT;
3523#ifdef MAC_OSX
3524 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3525#else
3526 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3527#endif
3528
3529 if (status == noErr)
3530 {
3531#ifdef MAC_OSX
3532 FSCatalogInfo catalogInfo;
3533
3534 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3535 &catalogInfo, NULL, NULL, NULL);
3536#else
3537 FInfo finder_info;
3538
3539 status = FSpGetFInfo (&fss, &finder_info);
3540#endif
3541 if (status == noErr)
3542 {
3543#ifdef MAC_OSX
3544 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType);
3545#else
3546 result = mac_get_object_from_code (finder_info.fdType);
3547#endif
3548 }
3549 }
3550 UNBLOCK_INPUT;
3551 if (status != noErr) {
3552 error ("Error while getting file information.");
3553 }
3554 return result;
3555}
3556
3557DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 1, 2, 0,
3558 doc: /* Set creator code of file FILENAME to CODE.
3559If non-nil, CODE must be a 4-character string. Otherwise, 'EMAx' is
3560assumed. Return non-nil if successful. */)
3561 (filename, code)
3562 Lisp_Object filename, code;
3563{
3564 OSErr status;
3565#ifdef MAC_OSX
3566 FSRef fref;
3567#else
3568 FSSpec fss;
3569#endif
3570 OSType cCode;
3571 CHECK_STRING (filename);
3572
3573 cCode = mac_get_code_from_arg(code, 'EMAx');
3574
3575 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3576 return Qnil;
3577 }
3578 filename = Fexpand_file_name (filename, Qnil);
3579
3580 BLOCK_INPUT;
3581#ifdef MAC_OSX
3582 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3583#else
3584 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3585#endif
3586
3587 if (status == noErr)
3588 {
3589#ifdef MAC_OSX
3590 FSCatalogInfo catalogInfo;
3591 FSRef parentDir;
3592 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3593 &catalogInfo, NULL, NULL, &parentDir);
3594#else
3595 FInfo finder_info;
3596
3597 status = FSpGetFInfo (&fss, &finder_info);
3598#endif
3599 if (status == noErr)
3600 {
3601#ifdef MAC_OSX
3602 ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
3603 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
3604 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
3605#else
3606 finder_info.fdCreator = cCode;
3607 status = FSpSetFInfo (&fss, &finder_info);
3608#endif
3609 }
3610 }
3611 UNBLOCK_INPUT;
3612 if (status != noErr) {
3613 error ("Error while setting creator information.");
3614 }
3615 return Qt;
3616}
3617
3618DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0,
3619 doc: /* Set file code of file FILENAME to CODE.
3620CODE must be a 4-character string. Return non-nil if successful. */)
3621 (filename, code)
3622 Lisp_Object filename, code;
3623{
3624 OSErr status;
3625#ifdef MAC_OSX
3626 FSRef fref;
3627#else
3628 FSSpec fss;
3629#endif
3630 OSType cCode;
3631 CHECK_STRING (filename);
3632
3633 cCode = mac_get_code_from_arg(code, 0); /* Default to empty code*/
3634
3635 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3636 return Qnil;
3637 }
3638 filename = Fexpand_file_name (filename, Qnil);
3639
3640 BLOCK_INPUT;
3641#ifdef MAC_OSX
3642 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3643#else
3644 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3645#endif
3646
3647 if (status == noErr)
3648 {
3649#ifdef MAC_OSX
3650 FSCatalogInfo catalogInfo;
3651 FSRef parentDir;
3652 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3653 &catalogInfo, NULL, NULL, &parentDir);
3654#else
3655 FInfo finder_info;
3656
3657 status = FSpGetFInfo (&fss, &finder_info);
3658#endif
3659 if (status == noErr)
3660 {
3661#ifdef MAC_OSX
3662 ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
3663 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
3664 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
3665#else
3666 finder_info.fdType = cCode;
3667 status = FSpSetFInfo (&fss, &finder_info);
3668#endif
3669 }
3670 }
3671 UNBLOCK_INPUT;
3672 if (status != noErr) {
3673 error ("Error while setting creator information.");
3674 }
3675 return Qt;
3676}
3677
3397 3678
3398/* Compile and execute the AppleScript SCRIPT and return the error 3679/* Compile and execute the AppleScript SCRIPT and return the error
3399 status as function value. A zero is returned if compilation and 3680 status as function value. A zero is returned if compilation and
@@ -3484,12 +3765,12 @@ do_applescript (char *script, char **result)
3484 3765
3485 3766
3486DEFUN ("do-applescript", Fdo_applescript, Sdo_applescript, 1, 1, 0, 3767DEFUN ("do-applescript", Fdo_applescript, Sdo_applescript, 1, 1, 0,
3487 doc: /* Compile and execute AppleScript SCRIPT and retrieve and return the result. 3768 doc: /* Compile and execute AppleScript SCRIPT and return the result.
3488If compilation and execution are successful, the resulting script 3769If compilation and execution are successful, the resulting script
3489value is returned as a string. Otherwise the function aborts and 3770value is returned as a string. Otherwise the function aborts and
3490displays the error message returned by the AppleScript scripting 3771displays the error message returned by the AppleScript scripting
3491component. */) 3772component. */)
3492 (script) 3773 (script)
3493 Lisp_Object script; 3774 Lisp_Object script;
3494{ 3775{
3495 char *result, *temp; 3776 char *result, *temp;
@@ -3529,16 +3810,15 @@ component. */)
3529 3810
3530DEFUN ("mac-file-name-to-posix", Fmac_file_name_to_posix, 3811DEFUN ("mac-file-name-to-posix", Fmac_file_name_to_posix,
3531 Smac_file_name_to_posix, 1, 1, 0, 3812 Smac_file_name_to_posix, 1, 1, 0,
3532 doc: /* Convert Macintosh filename to Posix form. */) 3813 doc: /* Convert Macintosh FILENAME to Posix form. */)
3533 (mac_filename) 3814 (filename)
3534 Lisp_Object mac_filename; 3815 Lisp_Object filename;
3535{ 3816{
3536 char posix_filename[MAXPATHLEN+1]; 3817 char posix_filename[MAXPATHLEN+1];
3537 3818
3538 CHECK_STRING (mac_filename); 3819 CHECK_STRING (filename);
3539 3820
3540 if (mac_to_posix_pathname (SDATA (mac_filename), posix_filename, 3821 if (mac_to_posix_pathname (SDATA (filename), posix_filename, MAXPATHLEN))
3541 MAXPATHLEN))
3542 return build_string (posix_filename); 3822 return build_string (posix_filename);
3543 else 3823 else
3544 return Qnil; 3824 return Qnil;
@@ -3547,16 +3827,15 @@ DEFUN ("mac-file-name-to-posix", Fmac_file_name_to_posix,
3547 3827
3548DEFUN ("posix-file-name-to-mac", Fposix_file_name_to_mac, 3828DEFUN ("posix-file-name-to-mac", Fposix_file_name_to_mac,
3549 Sposix_file_name_to_mac, 1, 1, 0, 3829 Sposix_file_name_to_mac, 1, 1, 0,
3550 doc: /* Convert Posix filename to Mac form. */) 3830 doc: /* Convert Posix FILENAME to Mac form. */)
3551 (posix_filename) 3831 (filename)
3552 Lisp_Object posix_filename; 3832 Lisp_Object filename;
3553{ 3833{
3554 char mac_filename[MAXPATHLEN+1]; 3834 char mac_filename[MAXPATHLEN+1];
3555 3835
3556 CHECK_STRING (posix_filename); 3836 CHECK_STRING (filename);
3557 3837
3558 if (posix_to_mac_pathname (SDATA (posix_filename), mac_filename, 3838 if (posix_to_mac_pathname (SDATA (filename), mac_filename, MAXPATHLEN))
3559 MAXPATHLEN))
3560 return build_string (mac_filename); 3839 return build_string (mac_filename);
3561 else 3840 else
3562 return Qnil; 3841 return Qnil;
@@ -3571,8 +3850,8 @@ DEFUN ("mac-get-preference", Fmac_get_preference, Smac_get_preference, 1, 4, 0,
3571 doc: /* Return the application preference value for KEY. 3850 doc: /* Return the application preference value for KEY.
3572KEY is either a string specifying a preference key, or a list of key 3851KEY is either a string specifying a preference key, or a list of key
3573strings. If it is a list, the (i+1)-th element is used as a key for 3852strings. If it is a list, the (i+1)-th element is used as a key for
3574the CFDictionary value obtained by the i-th element. If lookup is 3853the CFDictionary value obtained by the i-th element. Return nil if
3575failed at some stage, nil is returned. 3854lookup is failed at some stage.
3576 3855
3577Optional arg APPLICATION is an application ID string. If omitted or 3856Optional arg APPLICATION is an application ID string. If omitted or
3578nil, that stands for the current application. 3857nil, that stands for the current application.
@@ -3603,7 +3882,7 @@ CFDictionary. If HASH-BOUND is a negative integer or nil, always
3603generate alists. If HASH-BOUND >= 0, generate an alist if the number 3882generate alists. If HASH-BOUND >= 0, generate an alist if the number
3604of keys in the dictionary is smaller than HASH-BOUND, and a hash table 3883of keys in the dictionary is smaller than HASH-BOUND, and a hash table
3605otherwise. */) 3884otherwise. */)
3606 (key, application, format, hash_bound) 3885 (key, application, format, hash_bound)
3607 Lisp_Object key, application, format, hash_bound; 3886 Lisp_Object key, application, format, hash_bound;
3608{ 3887{
3609 CFStringRef app_id, key_str; 3888 CFStringRef app_id, key_str;
@@ -3840,9 +4119,8 @@ charset string, or an integer as a CFStringEncoding value.
3840On Mac OS X 10.2 and later, you can do Unicode Normalization by 4119On Mac OS X 10.2 and later, you can do Unicode Normalization by
3841specifying the optional argument NORMALIZATION-FORM with a symbol NFD, 4120specifying the optional argument NORMALIZATION-FORM with a symbol NFD,
3842NFKD, NFC, NFKC, HFS+D, or HFS+C. 4121NFKD, NFC, NFKC, HFS+D, or HFS+C.
3843On successful conversion, returns the result string, else returns 4122On successful conversion, return the result string, else return nil. */)
3844nil. */) 4123 (string, source, target, normalization_form)
3845 (string, source, target, normalization_form)
3846 Lisp_Object string, source, target, normalization_form; 4124 Lisp_Object string, source, target, normalization_form;
3847{ 4125{
3848 Lisp_Object result = Qnil; 4126 Lisp_Object result = Qnil;
@@ -3862,7 +4140,11 @@ nil. */)
3862 src_encoding = get_cfstring_encoding_from_lisp (source); 4140 src_encoding = get_cfstring_encoding_from_lisp (source);
3863 tgt_encoding = get_cfstring_encoding_from_lisp (target); 4141 tgt_encoding = get_cfstring_encoding_from_lisp (target);
3864 4142
3865 string = string_make_unibyte (string); 4143 /* We really want string_to_unibyte, but since it doesn't exist yet, we
4144 use string_as_unibyte which works as well, except for the fact that
4145 it's too permissive (it doesn't check that the multibyte string only
4146 contain single-byte chars). */
4147 string = Fstring_as_unibyte (string);
3866 if (src_encoding != kCFStringEncodingInvalidId 4148 if (src_encoding != kCFStringEncodingInvalidId
3867 && tgt_encoding != kCFStringEncodingInvalidId) 4149 && tgt_encoding != kCFStringEncodingInvalidId)
3868 str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string), 4150 str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string),
@@ -3897,7 +4179,7 @@ nil. */)
3897 4179
3898DEFUN ("mac-clear-font-name-table", Fmac_clear_font_name_table, Smac_clear_font_name_table, 0, 0, 0, 4180DEFUN ("mac-clear-font-name-table", Fmac_clear_font_name_table, Smac_clear_font_name_table, 0, 0, 0,
3899 doc: /* Clear the font name table. */) 4181 doc: /* Clear the font name table. */)
3900 () 4182 ()
3901{ 4183{
3902 check_mac (); 4184 check_mac ();
3903 mac_clear_font_name_table (); 4185 mac_clear_font_name_table ();
@@ -4197,8 +4479,13 @@ init_mac_osx_environment ()
4197 app_bundle_pathname. */ 4479 app_bundle_pathname. */
4198 4480
4199 bundle = CFBundleGetMainBundle (); 4481 bundle = CFBundleGetMainBundle ();
4200 if (!bundle) 4482 if (!bundle || CFBundleGetIdentifier (bundle) == NULL)
4201 return; 4483 {
4484 /* We could not find the bundle identifier. For now, prevent
4485 the fatal error by bringing it up in the terminal. */
4486 inhibit_window_system = 1;
4487 return;
4488 }
4202 4489
4203 bundleURL = CFBundleCopyBundleURL (bundle); 4490 bundleURL = CFBundleCopyBundleURL (bundle);
4204 if (!bundleURL) 4491 if (!bundleURL)
@@ -4361,6 +4648,10 @@ syms_of_mac ()
4361#endif 4648#endif
4362 defsubr (&Smac_clear_font_name_table); 4649 defsubr (&Smac_clear_font_name_table);
4363 4650
4651 defsubr (&Smac_set_file_creator);
4652 defsubr (&Smac_set_file_type);
4653 defsubr (&Smac_get_file_creator);
4654 defsubr (&Smac_get_file_type);
4364 defsubr (&Sdo_applescript); 4655 defsubr (&Sdo_applescript);
4365 defsubr (&Smac_file_name_to_posix); 4656 defsubr (&Smac_file_name_to_posix);
4366 defsubr (&Sposix_file_name_to_mac); 4657 defsubr (&Sposix_file_name_to_mac);