summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2005-07-12 11:33:42 +0000
committerYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2005-07-12 11:33:42 +0000
commitf9ddcf00018d17d1b15c3bc2bfb52b2497acedc6 (patch)
tree4324091fccd6c806297f185797e232fc3547c746 /src
parented3cb6535a6441fd409f5ed909e641b98f25a807 (diff)
downloademacs-f9ddcf00018d17d1b15c3bc2bfb52b2497acedc6.tar.gz
[!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')
-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. */
#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 @@ Boston, MA 02110-1301, USA. */
#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 @@ xrm_cfproperty_list_to_value (plist)
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 @@ chmod (const char *path, mode_t mode)
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 @@ initialize_applescript ()
}
-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)
-{
- 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);
- }
+/* 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. */)
- (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 @@ DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1,
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-creator", Fmac_get_file_creator, Smac_get_file_creator, 1,
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 @@ DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
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-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0,
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 @@ If non-nil, CODE must be a 32-bit integer or a 4-character string. Otherwise,
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 @@ If non-nil, CODE must be a 32-bit integer or a 4-character string. Otherwise,
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 @@ CODE must be a 32-bit integer or a 4-character string. Return non-nil if success
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;