aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
authorMiles Bader2005-07-14 08:02:00 +0000
committerMiles Bader2005-07-14 08:02:00 +0000
commitbacb9790f594207469f22ed9f3e8085ab76e5e2b (patch)
treeb1cee62715d6cd2797f3122e4f058d7bc18ceef6 /src/mac.c
parentd3e4babdd1267fb5690a17949196640a47c6f159 (diff)
parentead25b5cabbe092711864eae13a76437e6a65ce1 (diff)
downloademacs-bacb9790f594207469f22ed9f3e8085ab76e5e2b.tar.gz
emacs-bacb9790f594207469f22ed9f3e8085ab76e5e2b.zip
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-69
Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 474-484) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 88-91) - Merge from emacs--cvs-trunk--0 - Update FSF's address in GPL notices - Update from CVS
Diffstat (limited to 'src/mac.c')
-rw-r--r--src/mac.c294
1 files changed, 290 insertions, 4 deletions
diff --git a/src/mac.c b/src/mac.c
index ef136ab6512..203b47a1975 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -34,10 +34,9 @@ Boston, MA 02110-1301, USA. */
34 34
35#include "macterm.h" 35#include "macterm.h"
36 36
37#if TARGET_API_MAC_CARBON
38#include "charset.h" 37#include "charset.h"
39#include "coding.h" 38#include "coding.h"
40#else /* not TARGET_API_MAC_CARBON */ 39#if !TARGET_API_MAC_CARBON
41#include <Files.h> 40#include <Files.h>
42#include <MacTypes.h> 41#include <MacTypes.h>
43#include <TextUtils.h> 42#include <TextUtils.h>
@@ -53,6 +52,7 @@ Boston, MA 02110-1301, USA. */
53#include <Processes.h> 52#include <Processes.h>
54#include <EPPC.h> 53#include <EPPC.h>
55#include <MacLocales.h> 54#include <MacLocales.h>
55#include <Endian.h>
56#endif /* not TARGET_API_MAC_CARBON */ 56#endif /* not TARGET_API_MAC_CARBON */
57 57
58#include <utime.h> 58#include <utime.h>
@@ -1021,7 +1021,7 @@ xrm_cfproperty_list_to_value (plist)
1021 CFTypeID type_id = CFGetTypeID (plist); 1021 CFTypeID type_id = CFGetTypeID (plist);
1022 1022
1023 if (type_id == CFStringGetTypeID ()) 1023 if (type_id == CFStringGetTypeID ())
1024 return cfstring_to_lisp (plist); 1024 return cfstring_to_lisp (plist);
1025 else if (type_id == CFNumberGetTypeID ()) 1025 else if (type_id == CFNumberGetTypeID ())
1026 { 1026 {
1027 CFStringRef string; 1027 CFStringRef string;
@@ -2490,6 +2490,22 @@ chmod (const char *path, mode_t mode)
2490 2490
2491 2491
2492int 2492int
2493fchmod (int fd, mode_t mode)
2494{
2495 /* say it always succeed for now */
2496 return 0;
2497}
2498
2499
2500int
2501fchown (int fd, uid_t owner, gid_t group)
2502{
2503 /* say it always succeed for now */
2504 return 0;
2505}
2506
2507
2508int
2493dup (int oldd) 2509dup (int oldd)
2494{ 2510{
2495#ifdef __MRC__ 2511#ifdef __MRC__
@@ -3388,12 +3404,278 @@ initialize_applescript ()
3388} 3404}
3389 3405
3390 3406
3391void terminate_applescript() 3407void
3408terminate_applescript()
3392{ 3409{
3393 OSADispose (as_scripting_component, as_script_context); 3410 OSADispose (as_scripting_component, as_script_context);
3394 CloseComponent (as_scripting_component); 3411 CloseComponent (as_scripting_component);
3395} 3412}
3396 3413
3414/* Convert a lisp string to the 4 byte character code. */
3415
3416OSType
3417mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
3418{
3419 OSType result;
3420 if (NILP(arg))
3421 {
3422 result = defCode;
3423 }
3424 else
3425 {
3426 /* check type string */
3427 CHECK_STRING(arg);
3428 if (SBYTES (arg) != 4)
3429 {
3430 error ("Wrong argument: need string of length 4 for code");
3431 }
3432 result = EndianU32_BtoN (*((UInt32 *) SDATA (arg)));
3433 }
3434 return result;
3435}
3436
3437/* Convert the 4 byte character code into a 4 byte string. */
3438
3439Lisp_Object
3440mac_get_object_from_code(OSType defCode)
3441{
3442 UInt32 code = EndianU32_NtoB (defCode);
3443
3444 return make_unibyte_string ((char *)&code, 4);
3445}
3446
3447
3448DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1, 1, 0,
3449 doc: /* Get the creator code of FILENAME as a four character string. */)
3450 (filename)
3451 Lisp_Object filename;
3452{
3453 OSErr status;
3454#ifdef MAC_OSX
3455 FSRef fref;
3456#else
3457 FSSpec fss;
3458#endif
3459 OSType cCode;
3460 Lisp_Object result = Qnil;
3461 CHECK_STRING (filename);
3462
3463 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3464 return Qnil;
3465 }
3466 filename = Fexpand_file_name (filename, Qnil);
3467
3468 BLOCK_INPUT;
3469#ifdef MAC_OSX
3470 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3471#else
3472 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3473#endif
3474
3475 if (status == noErr)
3476 {
3477#ifdef MAC_OSX
3478 FSCatalogInfo catalogInfo;
3479
3480 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3481 &catalogInfo, NULL, NULL, NULL);
3482#else
3483 FInfo finder_info;
3484
3485 status = FSpGetFInfo (&fss, &finder_info);
3486#endif
3487 if (status == noErr)
3488 {
3489#ifdef MAC_OSX
3490 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator);
3491#else
3492 result = mac_get_object_from_code (finder_info.fdCreator);
3493#endif
3494 }
3495 }
3496 UNBLOCK_INPUT;
3497 if (status != noErr) {
3498 error ("Error while getting file information.");
3499 }
3500 return result;
3501}
3502
3503DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
3504 doc: /* Get the type code of FILENAME as a four character string. */)
3505 (filename)
3506 Lisp_Object filename;
3507{
3508 OSErr status;
3509#ifdef MAC_OSX
3510 FSRef fref;
3511#else
3512 FSSpec fss;
3513#endif
3514 OSType cCode;
3515 Lisp_Object result = Qnil;
3516 CHECK_STRING (filename);
3517
3518 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3519 return Qnil;
3520 }
3521 filename = Fexpand_file_name (filename, Qnil);
3522
3523 BLOCK_INPUT;
3524#ifdef MAC_OSX
3525 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3526#else
3527 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3528#endif
3529
3530 if (status == noErr)
3531 {
3532#ifdef MAC_OSX
3533 FSCatalogInfo catalogInfo;
3534
3535 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3536 &catalogInfo, NULL, NULL, NULL);
3537#else
3538 FInfo finder_info;
3539
3540 status = FSpGetFInfo (&fss, &finder_info);
3541#endif
3542 if (status == noErr)
3543 {
3544#ifdef MAC_OSX
3545 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType);
3546#else
3547 result = mac_get_object_from_code (finder_info.fdType);
3548#endif
3549 }
3550 }
3551 UNBLOCK_INPUT;
3552 if (status != noErr) {
3553 error ("Error while getting file information.");
3554 }
3555 return result;
3556}
3557
3558DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 1, 2, 0,
3559 doc: /* Set creator code of file FILENAME to CODE.
3560If non-nil, CODE must be a 4-character string. Otherwise, 'EMAx' is
3561assumed. Return non-nil if successful. */)
3562 (filename, code)
3563 Lisp_Object filename, code;
3564{
3565 OSErr status;
3566#ifdef MAC_OSX
3567 FSRef fref;
3568#else
3569 FSSpec fss;
3570#endif
3571 OSType cCode;
3572 CHECK_STRING (filename);
3573
3574 cCode = mac_get_code_from_arg(code, 'EMAx');
3575
3576 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3577 return Qnil;
3578 }
3579 filename = Fexpand_file_name (filename, Qnil);
3580
3581 BLOCK_INPUT;
3582#ifdef MAC_OSX
3583 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3584#else
3585 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3586#endif
3587
3588 if (status == noErr)
3589 {
3590#ifdef MAC_OSX
3591 FSCatalogInfo catalogInfo;
3592 FSRef parentDir;
3593 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3594 &catalogInfo, NULL, NULL, &parentDir);
3595#else
3596 FInfo finder_info;
3597
3598 status = FSpGetFInfo (&fss, &finder_info);
3599#endif
3600 if (status == noErr)
3601 {
3602#ifdef MAC_OSX
3603 ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
3604 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
3605 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
3606#else
3607 finder_info.fdCreator = cCode;
3608 status = FSpSetFInfo (&fss, &finder_info);
3609#endif
3610 }
3611 }
3612 UNBLOCK_INPUT;
3613 if (status != noErr) {
3614 error ("Error while setting creator information.");
3615 }
3616 return Qt;
3617}
3618
3619DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0,
3620 doc: /* Set file code of file FILENAME to CODE.
3621CODE must be a 4-character string. Return non-nil if successful. */)
3622 (filename, code)
3623 Lisp_Object filename, code;
3624{
3625 OSErr status;
3626#ifdef MAC_OSX
3627 FSRef fref;
3628#else
3629 FSSpec fss;
3630#endif
3631 OSType cCode;
3632 CHECK_STRING (filename);
3633
3634 cCode = mac_get_code_from_arg(code, 0); /* Default to empty code*/
3635
3636 if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
3637 return Qnil;
3638 }
3639 filename = Fexpand_file_name (filename, Qnil);
3640
3641 BLOCK_INPUT;
3642#ifdef MAC_OSX
3643 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
3644#else
3645 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
3646#endif
3647
3648 if (status == noErr)
3649 {
3650#ifdef MAC_OSX
3651 FSCatalogInfo catalogInfo;
3652 FSRef parentDir;
3653 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3654 &catalogInfo, NULL, NULL, &parentDir);
3655#else
3656 FInfo finder_info;
3657
3658 status = FSpGetFInfo (&fss, &finder_info);
3659#endif
3660 if (status == noErr)
3661 {
3662#ifdef MAC_OSX
3663 ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
3664 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
3665 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
3666#else
3667 finder_info.fdType = cCode;
3668 status = FSpSetFInfo (&fss, &finder_info);
3669#endif
3670 }
3671 }
3672 UNBLOCK_INPUT;
3673 if (status != noErr) {
3674 error ("Error while setting creator information.");
3675 }
3676 return Qt;
3677}
3678
3397 3679
3398/* Compile and execute the AppleScript SCRIPT and return the error 3680/* Compile and execute the AppleScript SCRIPT and return the error
3399 status as function value. A zero is returned if compilation and 3681 status as function value. A zero is returned if compilation and
@@ -4361,6 +4643,10 @@ syms_of_mac ()
4361#endif 4643#endif
4362 defsubr (&Smac_clear_font_name_table); 4644 defsubr (&Smac_clear_font_name_table);
4363 4645
4646 defsubr (&Smac_set_file_creator);
4647 defsubr (&Smac_set_file_type);
4648 defsubr (&Smac_get_file_creator);
4649 defsubr (&Smac_get_file_type);
4364 defsubr (&Sdo_applescript); 4650 defsubr (&Sdo_applescript);
4365 defsubr (&Smac_file_name_to_posix); 4651 defsubr (&Smac_file_name_to_posix);
4366 defsubr (&Sposix_file_name_to_mac); 4652 defsubr (&Sposix_file_name_to_mac);