changeset 64247:e55c855616f5

[!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.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Tue, 12 Jul 2005 11:33:42 +0000
parents 269f91810e62
children 2fc6a5dfb885
files src/mac.c
diffstat 1 files changed, 135 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/src/mac.c	Tue Jul 12 11:33:09 2005 +0000
+++ b/src/mac.c	Tue Jul 12 11:33:42 2005 +0000
@@ -34,10 +34,9 @@
 
 #include "macterm.h"
 
-#if TARGET_API_MAC_CARBON
 #include "charset.h"
 #include "coding.h"
-#else  /* not TARGET_API_MAC_CARBON */
+#if !TARGET_API_MAC_CARBON
 #include <Files.h>
 #include <MacTypes.h>
 #include <TextUtils.h>
@@ -53,6 +52,7 @@
 #include <Processes.h>
 #include <EPPC.h>
 #include <MacLocales.h>
+#include <Endian.h>
 #endif	/* not TARGET_API_MAC_CARBON */
 
 #include <utime.h>
@@ -1021,7 +1021,7 @@
   CFTypeID type_id = CFGetTypeID (plist);
 
   if (type_id == CFStringGetTypeID ())
-      return cfstring_to_lisp (plist);
+    return cfstring_to_lisp (plist);
   else if (type_id == CFNumberGetTypeID ())
     {
       CFStringRef string;
@@ -2490,6 +2490,22 @@
 
 
 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,66 +3404,58 @@
 }
 
 
-void terminate_applescript()
+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
- */
+/* Convert a lisp string to the 4 byte character code.  */
  
-OSType mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
+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)
+      if (SBYTES (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);
+      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)
+/* 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);
-  }
+  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. */)
-  (Lisp_Object filename)
+  (filename)
+     Lisp_Object filename;
 {
   OSErr	status;
-  FSRef defLoc;
+#ifdef MAC_OSX
+  FSRef fref;
+#else
+  FSSpec fss;
+#endif
   OSType cCode;
   Lisp_Object result = Qnil;
   CHECK_STRING (filename);
@@ -3458,17 +3466,31 @@
   filename = Fexpand_file_name (filename, Qnil);
 
   BLOCK_INPUT;
-  status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
+#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(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo,
-				&catalogInfo, NULL, NULL, &parentDir);
+
+      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,10 +3502,15 @@
 
 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)
+  (filename)
+     Lisp_Object filename;
 {
   OSErr	status;
-  FSRef defLoc;
+#ifdef MAC_OSX
+  FSRef fref;
+#else
+  FSSpec fss;
+#endif
   OSType cCode;
   Lisp_Object result = Qnil;
   CHECK_STRING (filename);
@@ -3494,17 +3521,31 @@
   filename = Fexpand_file_name (filename, Qnil);
 
   BLOCK_INPUT;
-  status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
+#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(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo,
-				&catalogInfo, NULL, NULL, &parentDir);
+
+      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,13 +3557,17 @@
 
 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)
+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;
-  FSRef defLoc;
+#ifdef MAC_OSX
+  FSRef fref;
+#else
+  FSSpec fss;
+#endif
   OSType cCode;
   CHECK_STRING (filename);
 
@@ -3534,19 +3579,34 @@
   filename = Fexpand_file_name (filename, Qnil);
 
   BLOCK_INPUT;
-  status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
+#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(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo,
+      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(&defLoc, kFSCatInfoFinderInfo, &catalogInfo);
+	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,14 +3618,16 @@
 
 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.
-   */)
+CODE must be a 4-character string.  Return non-nil if successful.  */)
   (filename, code)
-     Lisp_Object filename;
-     Lisp_Object code;
+     Lisp_Object filename, code;
 {
   OSErr	status;
-  FSRef defLoc;
+#ifdef MAC_OSX
+  FSRef fref;
+#else
+  FSSpec fss;
+#endif
   OSType cCode;
   CHECK_STRING (filename);
 
@@ -3577,19 +3639,34 @@
   filename = Fexpand_file_name (filename, Qnil);
 
   BLOCK_INPUT;
-  status = FSPathMakeRef(SDATA(ENCODE_FILE(filename)), &defLoc, NULL);
+#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(&defLoc, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo,
+      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(&defLoc, kFSCatInfoFinderInfo, &catalogInfo);
+	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;