aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu2005-07-12 11:33:42 +0000
committerYAMAMOTO Mitsuharu2005-07-12 11:33:42 +0000
commit908b04563d653cc410afdff3715c159eea347c9a (patch)
tree861d67d9cd3c1ff72dc1af78219447102ab59f3d /src/mac.c
parent7e06fe61068ce107d3221a2872639e76b7927661 (diff)
downloademacs-908b04563d653cc410afdff3715c159eea347c9a.tar.gz
emacs-908b04563d653cc410afdff3715c159eea347c9a.zip
[!TARGET_API_MAC_CARBON] Include charset.h, coding.h, and Endian.h.
[!MAC_OSX] (fchmod, fchown): New functions. (mac_get_code_from_arg): Don't accept Lisp integer as argument. Use SBYTES and EndianU32_BtoN. (mac_get_object_from_code): Return 4 byte string even if argument is 0. Use make_unibyte_string and EndianU32_NtoB. (Fmac_get_file_creator, Fmac_get_file_type, Fmac_set_file_creator) (Fmac_set_file_type): Fix documents and argument declarations. Don't specify kFSCatInfoNodeFlags. Support Mac OS Classic.
Diffstat (limited to 'src/mac.c')
-rw-r--r--src/mac.c195
1 files changed, 136 insertions, 59 deletions
diff --git a/src/mac.c b/src/mac.c
index 965272d69b1..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,66 +3404,58 @@ 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
3397/* Convert a lisp string or integer to the 4 byte character code 3414/* Convert a lisp string to the 4 byte character code. */
3398 */
3399 3415
3400OSType mac_get_code_from_arg(Lisp_Object arg, OSType defCode) 3416OSType
3417mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
3401{ 3418{
3402 OSType result; 3419 OSType result;
3403 if (NILP(arg)) 3420 if (NILP(arg))
3404 { 3421 {
3405 result = defCode; 3422 result = defCode;
3406 } 3423 }
3407 else if (INTEGERP(arg))
3408 {
3409 result = XFASTINT(arg);
3410 }
3411 else 3424 else
3412 { 3425 {
3413 /* check type string */ 3426 /* check type string */
3414 CHECK_STRING(arg); 3427 CHECK_STRING(arg);
3415 if (strlen(SDATA(arg)) != 4) 3428 if (SBYTES (arg) != 4)
3416 { 3429 {
3417 error ("Wrong argument: need string of length 4 for code"); 3430 error ("Wrong argument: need string of length 4 for code");
3418 } 3431 }
3419 /* Should work cross-endian */ 3432 result = EndianU32_BtoN (*((UInt32 *) SDATA (arg)));
3420 result = SDATA(arg)[3] + (SDATA(arg)[2] << 8) +
3421 (SDATA(arg)[1] << 16) + (SDATA(arg)[0] << 24);
3422 } 3433 }
3423 return result; 3434 return result;
3424} 3435}
3425 3436
3426/** 3437/* Convert the 4 byte character code into a 4 byte string. */
3427 Convert the 4 byte character code into a 4 byte string 3438
3428 */ 3439Lisp_Object
3429Lisp_Object mac_get_object_from_code(OSType defCode) 3440mac_get_object_from_code(OSType defCode)
3430{ 3441{
3431 if (defCode == 0) { 3442 UInt32 code = EndianU32_NtoB (defCode);
3432 return make_specified_string("", -1, 0, 0); 3443
3433 } else { 3444 return make_unibyte_string ((char *)&code, 4);
3434 /* Should work cross-endian */
3435 char code[4];
3436 code[0] = defCode >> 24 & 0xff;
3437 code[1] = defCode >> 16 & 0xff;
3438 code[2] = defCode >> 8 & 0xff;
3439 code[3] = defCode & 0xff;
3440 return make_specified_string(code, -1, 4, 0);
3441 }
3442} 3445}
3443 3446
3444 3447
3445DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1, 1, 0, 3448DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1, 1, 0,
3446 doc: /* Get the creator code of FILENAME as a four character string. */) 3449 doc: /* Get the creator code of FILENAME as a four character string. */)
3447 (Lisp_Object filename) 3450 (filename)
3451 Lisp_Object filename;
3448{ 3452{
3449 OSErr status; 3453 OSErr status;
3450 FSRef defLoc; 3454#ifdef MAC_OSX
3455 FSRef fref;
3456#else
3457 FSSpec fss;
3458#endif
3451 OSType cCode; 3459 OSType cCode;
3452 Lisp_Object result = Qnil; 3460 Lisp_Object result = Qnil;
3453 CHECK_STRING (filename); 3461 CHECK_STRING (filename);
@@ -3458,17 +3466,31 @@ DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1,
3458 filename = Fexpand_file_name (filename, Qnil); 3466 filename = Fexpand_file_name (filename, Qnil);
3459 3467
3460 BLOCK_INPUT; 3468 BLOCK_INPUT;
3461 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL); 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
3462 3474
3463 if (status == noErr) 3475 if (status == noErr)
3464 { 3476 {
3477#ifdef MAC_OSX
3465 FSCatalogInfo catalogInfo; 3478 FSCatalogInfo catalogInfo;
3466 FSRef parentDir; 3479
3467 status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo, 3480 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3468 &catalogInfo, NULL, NULL, &parentDir); 3481 &catalogInfo, NULL, NULL, NULL);
3482#else
3483 FInfo finder_info;
3484
3485 status = FSpGetFInfo (&fss, &finder_info);
3486#endif
3469 if (status == noErr) 3487 if (status == noErr)
3470 { 3488 {
3489#ifdef MAC_OSX
3471 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator); 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
3472 } 3494 }
3473 } 3495 }
3474 UNBLOCK_INPUT; 3496 UNBLOCK_INPUT;
@@ -3480,10 +3502,15 @@ DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1,
3480 3502
3481DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0, 3503DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
3482 doc: /* Get the type code of FILENAME as a four character string. */) 3504 doc: /* Get the type code of FILENAME as a four character string. */)
3483 (Lisp_Object filename) 3505 (filename)
3506 Lisp_Object filename;
3484{ 3507{
3485 OSErr status; 3508 OSErr status;
3486 FSRef defLoc; 3509#ifdef MAC_OSX
3510 FSRef fref;
3511#else
3512 FSSpec fss;
3513#endif
3487 OSType cCode; 3514 OSType cCode;
3488 Lisp_Object result = Qnil; 3515 Lisp_Object result = Qnil;
3489 CHECK_STRING (filename); 3516 CHECK_STRING (filename);
@@ -3494,17 +3521,31 @@ DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
3494 filename = Fexpand_file_name (filename, Qnil); 3521 filename = Fexpand_file_name (filename, Qnil);
3495 3522
3496 BLOCK_INPUT; 3523 BLOCK_INPUT;
3497 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL); 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
3498 3529
3499 if (status == noErr) 3530 if (status == noErr)
3500 { 3531 {
3532#ifdef MAC_OSX
3501 FSCatalogInfo catalogInfo; 3533 FSCatalogInfo catalogInfo;
3502 FSRef parentDir; 3534
3503 status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo, 3535 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3504 &catalogInfo, NULL, NULL, &parentDir); 3536 &catalogInfo, NULL, NULL, NULL);
3537#else
3538 FInfo finder_info;
3539
3540 status = FSpGetFInfo (&fss, &finder_info);
3541#endif
3505 if (status == noErr) 3542 if (status == noErr)
3506 { 3543 {
3544#ifdef MAC_OSX
3507 result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType); 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
3508 } 3549 }
3509 } 3550 }
3510 UNBLOCK_INPUT; 3551 UNBLOCK_INPUT;
@@ -3516,13 +3557,17 @@ DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
3516 3557
3517DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 1, 2, 0, 3558DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 1, 2, 0,
3518 doc: /* Set creator code of file FILENAME to CODE. 3559 doc: /* Set creator code of file FILENAME to CODE.
3519If non-nil, CODE must be a 32-bit integer or a 4-character string. Otherwise, 3560If non-nil, CODE must be a 4-character string. Otherwise, 'EMAx' is
3520'EMAx' is assumed. Return non-nil if successful. 3561assumed. Return non-nil if successful. */)
3521 */) 3562 (filename, code)
3522 (Lisp_Object filename, Lisp_Object code) 3563 Lisp_Object filename, code;
3523{ 3564{
3524 OSErr status; 3565 OSErr status;
3525 FSRef defLoc; 3566#ifdef MAC_OSX
3567 FSRef fref;
3568#else
3569 FSSpec fss;
3570#endif
3526 OSType cCode; 3571 OSType cCode;
3527 CHECK_STRING (filename); 3572 CHECK_STRING (filename);
3528 3573
@@ -3534,19 +3579,34 @@ If non-nil, CODE must be a 32-bit integer or a 4-character string. Otherwise,
3534 filename = Fexpand_file_name (filename, Qnil); 3579 filename = Fexpand_file_name (filename, Qnil);
3535 3580
3536 BLOCK_INPUT; 3581 BLOCK_INPUT;
3537 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL); 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
3538 3587
3539 if (status == noErr) 3588 if (status == noErr)
3540 { 3589 {
3590#ifdef MAC_OSX
3541 FSCatalogInfo catalogInfo; 3591 FSCatalogInfo catalogInfo;
3542 FSRef parentDir; 3592 FSRef parentDir;
3543 status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo, 3593 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3544 &catalogInfo, NULL, NULL, &parentDir); 3594 &catalogInfo, NULL, NULL, &parentDir);
3595#else
3596 FInfo finder_info;
3597
3598 status = FSpGetFInfo (&fss, &finder_info);
3599#endif
3545 if (status == noErr) 3600 if (status == noErr)
3546 { 3601 {
3602#ifdef MAC_OSX
3547 ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode; 3603 ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
3548 status = FSSetCatalogInfo(&defLoc, kFSCatInfoFinderInfo, &catalogInfo); 3604 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
3549 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */ 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
3550 } 3610 }
3551 } 3611 }
3552 UNBLOCK_INPUT; 3612 UNBLOCK_INPUT;
@@ -3558,14 +3618,16 @@ If non-nil, CODE must be a 32-bit integer or a 4-character string. Otherwise,
3558 3618
3559DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0, 3619DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0,
3560 doc: /* Set file code of file FILENAME to CODE. 3620 doc: /* Set file code of file FILENAME to CODE.
3561CODE must be a 32-bit integer or a 4-character string. Return non-nil if successful. 3621CODE must be a 4-character string. Return non-nil if successful. */)
3562 */)
3563 (filename, code) 3622 (filename, code)
3564 Lisp_Object filename; 3623 Lisp_Object filename, code;
3565 Lisp_Object code;
3566{ 3624{
3567 OSErr status; 3625 OSErr status;
3568 FSRef defLoc; 3626#ifdef MAC_OSX
3627 FSRef fref;
3628#else
3629 FSSpec fss;
3630#endif
3569 OSType cCode; 3631 OSType cCode;
3570 CHECK_STRING (filename); 3632 CHECK_STRING (filename);
3571 3633
@@ -3577,19 +3639,34 @@ CODE must be a 32-bit integer or a 4-character string. Return non-nil if success
3577 filename = Fexpand_file_name (filename, Qnil); 3639 filename = Fexpand_file_name (filename, Qnil);
3578 3640
3579 BLOCK_INPUT; 3641 BLOCK_INPUT;
3580 status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL); 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
3581 3647
3582 if (status == noErr) 3648 if (status == noErr)
3583 { 3649 {
3650#ifdef MAC_OSX
3584 FSCatalogInfo catalogInfo; 3651 FSCatalogInfo catalogInfo;
3585 FSRef parentDir; 3652 FSRef parentDir;
3586 status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo, 3653 status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
3587 &catalogInfo, NULL, NULL, &parentDir); 3654 &catalogInfo, NULL, NULL, &parentDir);
3655#else
3656 FInfo finder_info;
3657
3658 status = FSpGetFInfo (&fss, &finder_info);
3659#endif
3588 if (status == noErr) 3660 if (status == noErr)
3589 { 3661 {
3662#ifdef MAC_OSX
3590 ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode; 3663 ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
3591 status = FSSetCatalogInfo(&defLoc, kFSCatInfoFinderInfo, &catalogInfo); 3664 status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
3592 /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */ 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
3593 } 3670 }
3594 } 3671 }
3595 UNBLOCK_INPUT; 3672 UNBLOCK_INPUT;