emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/mac.c


From: YAMAMOTO Mitsuharu
Subject: [Emacs-diffs] Changes to emacs/src/mac.c
Date: Tue, 12 Jul 2005 07:33:42 -0400

Index: emacs/src/mac.c
diff -c emacs/src/mac.c:1.39 emacs/src/mac.c:1.40
*** emacs/src/mac.c:1.39        Sun Jul 10 18:17:18 2005
--- emacs/src/mac.c     Tue Jul 12 11:33:42 2005
***************
*** 34,43 ****
  
  #include "macterm.h"
  
- #if TARGET_API_MAC_CARBON
  #include "charset.h"
  #include "coding.h"
! #else  /* not TARGET_API_MAC_CARBON */
  #include <Files.h>
  #include <MacTypes.h>
  #include <TextUtils.h>
--- 34,42 ----
  
  #include "macterm.h"
  
  #include "charset.h"
  #include "coding.h"
! #if !TARGET_API_MAC_CARBON
  #include <Files.h>
  #include <MacTypes.h>
  #include <TextUtils.h>
***************
*** 53,58 ****
--- 52,58 ----
  #include <Processes.h>
  #include <EPPC.h>
  #include <MacLocales.h>
+ #include <Endian.h>
  #endif        /* not TARGET_API_MAC_CARBON */
  
  #include <utime.h>
***************
*** 1021,1027 ****
    CFTypeID type_id = CFGetTypeID (plist);
  
    if (type_id == CFStringGetTypeID ())
!       return cfstring_to_lisp (plist);
    else if (type_id == CFNumberGetTypeID ())
      {
        CFStringRef string;
--- 1021,1027 ----
    CFTypeID type_id = CFGetTypeID (plist);
  
    if (type_id == CFStringGetTypeID ())
!     return cfstring_to_lisp (plist);
    else if (type_id == CFNumberGetTypeID ())
      {
        CFStringRef string;
***************
*** 2490,2495 ****
--- 2490,2511 ----
  
  
  int
+ fchmod (int fd, mode_t mode)
+ {
+   /* say it always succeed for now */
+   return 0;
+ }
+ 
+ 
+ int
+ fchown (int fd, uid_t owner, gid_t group)
+ {
+   /* say it always succeed for now */
+   return 0;
+ }
+ 
+ 
+ int
  dup (int oldd)
  {
  #ifdef __MRC__
***************
*** 3388,3453 ****
  }
  
  
! void terminate_applescript()
  {
    OSADispose (as_scripting_component, as_script_context);
    CloseComponent (as_scripting_component);
  }
  
! /* Convert a lisp string or integer to the 4 byte character code
!  */
   
! OSType mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
  {
    OSType result;
    if (NILP(arg))
      {
        result = defCode;
      } 
-   else if (INTEGERP(arg))
-     {
-       result = XFASTINT(arg);
-     }
    else
      {
        /* check type string */
        CHECK_STRING(arg);
!       if (strlen(SDATA(arg)) != 4)
        {
          error ("Wrong argument: need string of length 4 for code");
        }
!       /* Should work cross-endian */
!       result = SDATA(arg)[3] + (SDATA(arg)[2] << 8) + 
!       (SDATA(arg)[1] << 16) + (SDATA(arg)[0] << 24);
      }
    return result;
  }
  
! /**
!    Convert the 4 byte character code into a 4 byte string
!  */
! Lisp_Object mac_get_object_from_code(OSType defCode)
! {
!   if (defCode == 0) {
!     return make_specified_string("", -1, 0, 0);
!   } else {
!     /* Should work cross-endian */
!     char code[4];
!     code[0] = defCode >> 24 & 0xff;
!     code[1] = defCode >> 16 & 0xff;
!     code[2] = defCode >> 8 & 0xff;
!     code[3] = defCode & 0xff;
!     return make_specified_string(code, -1, 4, 0);
!   }
  }
  
  
  DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 
1, 1, 0,
         doc: /* Get the creator code of FILENAME as a four character string. 
*/)
!   (Lisp_Object filename)
  {
    OSErr       status;
!   FSRef defLoc;
    OSType cCode;
    Lisp_Object result = Qnil;
    CHECK_STRING (filename);
--- 3404,3461 ----
  }
  
  
! void
! terminate_applescript()
  {
    OSADispose (as_scripting_component, as_script_context);
    CloseComponent (as_scripting_component);
  }
  
! /* Convert a lisp string to the 4 byte character code.  */
   
! OSType
! mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
  {
    OSType result;
    if (NILP(arg))
      {
        result = defCode;
      } 
    else
      {
        /* check type string */
        CHECK_STRING(arg);
!       if (SBYTES (arg) != 4)
        {
          error ("Wrong argument: need string of length 4 for code");
        }
!       result = EndianU32_BtoN (*((UInt32 *) SDATA (arg)));
      }
    return result;
  }
  
! /* Convert the 4 byte character code into a 4 byte string.  */
! 
! Lisp_Object
! mac_get_object_from_code(OSType defCode)
! {
!   UInt32 code = EndianU32_NtoB (defCode);
! 
!   return make_unibyte_string ((char *)&code, 4);
  }
  
  
  DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 
1, 1, 0,
         doc: /* Get the creator code of FILENAME as a four character string. 
*/)
!   (filename)
!      Lisp_Object filename;
  {
    OSErr       status;
! #ifdef MAC_OSX
!   FSRef fref;
! #else
!   FSSpec fss;
! #endif
    OSType cCode;
    Lisp_Object result = Qnil;
    CHECK_STRING (filename);
***************
*** 3458,3474 ****
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
  
    if (status == noErr)
      {
        FSCatalogInfo catalogInfo;
!       FSRef parentDir;
!       status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + 
kFSCatInfoFinderInfo,
!                               &catalogInfo, NULL, NULL, &parentDir);
        if (status == noErr) 
        {
          result = 
mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator);
        }
      }
    UNBLOCK_INPUT;
--- 3466,3496 ----
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
! #ifdef MAC_OSX
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
! #else
!   status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
! #endif
  
    if (status == noErr)
      {
+ #ifdef MAC_OSX
        FSCatalogInfo catalogInfo;
! 
!       status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
!                               &catalogInfo, NULL, NULL, NULL);
! #else
!       FInfo finder_info;
! 
!       status = FSpGetFInfo (&fss, &finder_info);
! #endif
        if (status == noErr) 
        {
+ #ifdef MAC_OSX
          result = 
mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator);
+ #else
+         result = mac_get_object_from_code (finder_info.fdCreator);
+ #endif
        }
      }
    UNBLOCK_INPUT;
***************
*** 3480,3489 ****
  
  DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
         doc: /* Get the type code of FILENAME as a four character string. */)
!   (Lisp_Object filename)
  {
    OSErr       status;
!   FSRef defLoc;
    OSType cCode;
    Lisp_Object result = Qnil;
    CHECK_STRING (filename);
--- 3502,3516 ----
  
  DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
         doc: /* Get the type code of FILENAME as a four character string. */)
!   (filename)
!      Lisp_Object filename;
  {
    OSErr       status;
! #ifdef MAC_OSX
!   FSRef fref;
! #else
!   FSSpec fss;
! #endif
    OSType cCode;
    Lisp_Object result = Qnil;
    CHECK_STRING (filename);
***************
*** 3494,3510 ****
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
  
    if (status == noErr)
      {
        FSCatalogInfo catalogInfo;
!       FSRef parentDir;
!       status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + 
kFSCatInfoFinderInfo,
!                               &catalogInfo, NULL, NULL, &parentDir);
        if (status == noErr) 
        {
          result = 
mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType);
        }
      }
    UNBLOCK_INPUT;
--- 3521,3551 ----
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
! #ifdef MAC_OSX
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
! #else
!   status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
! #endif
  
    if (status == noErr)
      {
+ #ifdef MAC_OSX
        FSCatalogInfo catalogInfo;
! 
!       status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
!                               &catalogInfo, NULL, NULL, NULL);
! #else
!       FInfo finder_info;
! 
!       status = FSpGetFInfo (&fss, &finder_info);
! #endif
        if (status == noErr) 
        {
+ #ifdef MAC_OSX
          result = 
mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType);
+ #else
+         result = mac_get_object_from_code (finder_info.fdType);
+ #endif
        }
      }
    UNBLOCK_INPUT;
***************
*** 3516,3528 ****
  
  DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 
1, 2, 0,
         doc: /* Set creator code of file FILENAME to CODE.
! If non-nil, CODE must be a 32-bit integer or a 4-character string. Otherwise,
! 'EMAx' is assumed. Return non-nil if successful.
!    */)
!   (Lisp_Object filename, Lisp_Object code)
  {
    OSErr       status;
!   FSRef defLoc;
    OSType cCode;
    CHECK_STRING (filename);
  
--- 3557,3573 ----
  
  DEFUN ("mac-set-file-creator", Fmac_set_file_creator, Smac_set_file_creator, 
1, 2, 0,
         doc: /* Set creator code of file FILENAME to CODE.
! If non-nil, CODE must be a 4-character string.  Otherwise, 'EMAx' is
! assumed. Return non-nil if successful.  */)
!   (filename, code)
!      Lisp_Object filename, code;
  {
    OSErr       status;
! #ifdef MAC_OSX
!   FSRef fref;
! #else
!   FSSpec fss;
! #endif
    OSType cCode;
    CHECK_STRING (filename);
  
***************
*** 3534,3552 ****
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
  
    if (status == noErr)
      {
        FSCatalogInfo catalogInfo;
        FSRef parentDir;
!       status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + 
kFSCatInfoFinderInfo,
                                &catalogInfo, NULL, NULL, &parentDir);
        if (status == noErr) 
        {
        ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
!       status = FSSetCatalogInfo(&defLoc, kFSCatInfoFinderInfo, &catalogInfo);
        /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
        }
      }
    UNBLOCK_INPUT;
--- 3579,3612 ----
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
! #ifdef MAC_OSX
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
! #else
!   status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
! #endif
  
    if (status == noErr)
      {
+ #ifdef MAC_OSX
        FSCatalogInfo catalogInfo;
        FSRef parentDir;
!       status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
                                &catalogInfo, NULL, NULL, &parentDir);
+ #else
+       FInfo finder_info;
+ 
+       status = FSpGetFInfo (&fss, &finder_info);
+ #endif
        if (status == noErr) 
        {
+ #ifdef MAC_OSX
        ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
!       status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
        /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
+ #else
+       finder_info.fdCreator = cCode;
+       status = FSpSetFInfo (&fss, &finder_info);
+ #endif
        }
      }
    UNBLOCK_INPUT;
***************
*** 3558,3571 ****
  
  DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0,
         doc: /* Set file code of file FILENAME to CODE.
! CODE must be a 32-bit integer or a 4-character string. Return non-nil if 
successful.
!    */)
    (filename, code)
!      Lisp_Object filename;
!      Lisp_Object code;
  {
    OSErr       status;
!   FSRef defLoc;
    OSType cCode;
    CHECK_STRING (filename);
  
--- 3618,3633 ----
  
  DEFUN ("mac-set-file-type", Fmac_set_file_type, Smac_set_file_type, 2, 2, 0,
         doc: /* Set file code of file FILENAME to CODE.
! CODE must be a 4-character string.  Return non-nil if successful.  */)
    (filename, code)
!      Lisp_Object filename, code;
  {
    OSErr       status;
! #ifdef MAC_OSX
!   FSRef fref;
! #else
!   FSSpec fss;
! #endif
    OSType cCode;
    CHECK_STRING (filename);
  
***************
*** 3577,3595 ****
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
  
    if (status == noErr)
      {
        FSCatalogInfo catalogInfo;
        FSRef parentDir;
!       status = FSGetCatalogInfo(&defLoc, kFSCatInfoNodeFlags + 
kFSCatInfoFinderInfo,
                                &catalogInfo, NULL, NULL, &parentDir);
        if (status == noErr) 
        {
        ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
!       status = FSSetCatalogInfo(&defLoc, kFSCatInfoFinderInfo, &catalogInfo);
        /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
        }
      }
    UNBLOCK_INPUT;
--- 3639,3672 ----
    filename = Fexpand_file_name (filename, Qnil);
  
    BLOCK_INPUT;
! #ifdef MAC_OSX
!   status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &fref, NULL);
! #else
!   status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (filename)), &fss);
! #endif
  
    if (status == noErr)
      {
+ #ifdef MAC_OSX
        FSCatalogInfo catalogInfo;
        FSRef parentDir;
!       status = FSGetCatalogInfo(&fref, kFSCatInfoFinderInfo,
                                &catalogInfo, NULL, NULL, &parentDir);
+ #else
+       FInfo finder_info;
+ 
+       status = FSpGetFInfo (&fss, &finder_info);
+ #endif
        if (status == noErr) 
        {
+ #ifdef MAC_OSX
        ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
!       status = FSSetCatalogInfo(&fref, kFSCatInfoFinderInfo, &catalogInfo);
        /* TODO: on Mac OS 10.2, we need to touch the parent dir, FNNotify? */
+ #else
+       finder_info.fdType = cCode;
+       status = FSpSetFInfo (&fss, &finder_info);
+ #endif
        }
      }
    UNBLOCK_INPUT;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]