| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | /***********************************************************
 | 
					
						
							| 
									
										
										
										
											1997-01-31 16:15:11 +00:00
										 |  |  | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:16 +00:00
										 |  |  | The Netherlands. | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                         All Rights Reserved | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Permission to use, copy, modify, and distribute this software and its  | 
					
						
							|  |  |  | documentation for any purpose and without fee is hereby granted,  | 
					
						
							|  |  |  | provided that the above copyright notice appear in all copies and that | 
					
						
							|  |  |  | both that copyright notice and this permission notice appear in  | 
					
						
							|  |  |  | supporting documentation, and that the names of Stichting Mathematisch | 
					
						
							|  |  |  | Centrum or CWI not be used in advertising or publicity pertaining to | 
					
						
							|  |  |  | distribution of the software without specific, written prior permission. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | 
					
						
							|  |  |  | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | 
					
						
							|  |  |  | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | 
					
						
							|  |  |  | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
					
						
							|  |  |  | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
					
						
							|  |  |  | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | 
					
						
							|  |  |  | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ******************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | #include "macglue.h"
 | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | #include "pymactoolbox.h"
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-19 12:34:59 +00:00
										 |  |  | #ifdef WITHOUT_FRAMEWORKS
 | 
					
						
							| 
									
										
										
										
											1995-02-14 01:27:24 +00:00
										 |  |  | #include <Memory.h>
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | #include <Files.h>
 | 
					
						
							| 
									
										
										
										
											1995-06-18 20:05:14 +00:00
										 |  |  | #include <Folders.h>
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | #include <StandardFile.h>
 | 
					
						
							|  |  |  | #include <Aliases.h>
 | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | #include <LowMem.h>
 | 
					
						
							| 
									
										
										
										
											2001-05-19 12:34:59 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | #include <Carbon/Carbon.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-20 15:25:16 +00:00
										 |  |  | #include "getapplbycreator.h"
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | #ifdef USE_TOOLBOX_OBJECT_GLUE
 | 
					
						
							|  |  |  | extern int _PyMac_GetFSSpec(PyObject *, FSSpec *); | 
					
						
							| 
									
										
										
										
											2001-09-02 00:09:35 +00:00
										 |  |  | extern PyObject *_PyMac_BuildFSSpec(FSSpec *); | 
					
						
							|  |  |  | extern int _PyMac_GetFSRef(PyObject *, FSRef *); | 
					
						
							| 
									
										
										
										
											2001-09-01 23:39:58 +00:00
										 |  |  | extern PyObject *_PyMac_BuildFSRef(FSRef *); | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | #define PyMac_GetFSSpec _PyMac_GetFSSpec
 | 
					
						
							| 
									
										
										
										
											2001-09-01 23:39:58 +00:00
										 |  |  | #define PyMac_BuildFSSpec _PyMac_BuildFSSpec
 | 
					
						
							|  |  |  | #define PyMac_GetFSRef _PyMac_GetFSRef
 | 
					
						
							|  |  |  | #define PyMac_BuildFSRef _PyMac_BuildFSRef
 | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject *ErrorObject; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-10 22:00:39 +00:00
										 |  |  | #ifdef TARGET_API_MAC_OSX
 | 
					
						
							|  |  |  | #define PATHNAMELEN 1024
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define PATHNAMELEN 256
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | /* ----------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | /* Declarations for objects of type Alias */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	AliasHandle alias; | 
					
						
							|  |  |  | } mfsaobject; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | staticforward PyTypeObject Mfsatype; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define is_mfsaobject(v)		((v)->ob_type == &Mfsatype)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Declarations for objects of type FSSpec */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	FSSpec fsspec; | 
					
						
							|  |  |  | } mfssobject; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | staticforward PyTypeObject Mfsstype; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define is_mfssobject(v)		((v)->ob_type == &Mfsstype)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Declarations for objects of type FSRef */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							|  |  |  | 	FSRef fsref; | 
					
						
							|  |  |  | } mfsrobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | staticforward PyTypeObject Mfsrtype; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define is_mfsrobject(v)		((v)->ob_type == &Mfsrtype)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Declarations for objects of type FInfo */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 	FInfo finfo; | 
					
						
							|  |  |  | } mfsiobject; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | staticforward PyTypeObject Mfsitype; | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define is_mfsiobject(v)		((v)->ob_type == &Mfsitype)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | staticforward mfssobject *newmfssobject(FSSpec *fss); /* Forward */ | 
					
						
							|  |  |  | staticforward mfsrobject *newmfsrobject(FSRef *fsr); /* Forward */ | 
					
						
							| 
									
										
										
										
											1995-01-26 22:56:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsa_Resolve(mfsaobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	FSSpec from, *fromp, result; | 
					
						
							|  |  |  | 	Boolean changed; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	from.name[0] = 0; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from)) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	if (from.name[0] ) | 
					
						
							|  |  |  | 		fromp = &from; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		fromp = NULL; | 
					
						
							|  |  |  | 	err = ResolveAlias(fromp, self->alias, &result, &changed); | 
					
						
							| 
									
										
										
										
											1997-06-16 14:31:38 +00:00
										 |  |  | 	if ( err && err != fnfErr ) { | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsa_GetInfo(mfsaobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Str63 value; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i", &i)) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = GetAliasInfo(self->alias, (AliasInfoType)i, value); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyString_FromStringAndSize((char *)&value[1], value[0]); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsa_Update(mfsaobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FSSpec target, fromfile, *fromfilep; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	Boolean changed; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	fromfile.name[0] = 0; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O&|O&",  PyMac_GetFSSpec, &target, | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 					 PyMac_GetFSSpec, &fromfile)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if ( fromfile.name[0] ) | 
					
						
							|  |  |  | 		fromfilep = &fromfile; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		fromfilep = NULL; | 
					
						
							|  |  |  | 	err = UpdateAlias(fromfilep, &target, self->alias, &changed); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("i", (int)changed); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static struct PyMethodDef mfsa_methods[] = { | 
					
						
							|  |  |  | 	{"Resolve",	(PyCFunction)mfsa_Resolve,	1}, | 
					
						
							|  |  |  | 	{"GetInfo",	(PyCFunction)mfsa_GetInfo,	1}, | 
					
						
							|  |  |  | 	{"Update",	(PyCFunction)mfsa_Update,	1}, | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  |   | 
					
						
							|  |  |  | 	{NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsa_getattr(mfsaobject *self, char *name) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | 	if ( strcmp(name, "data") == 0 ) { | 
					
						
							|  |  |  | 		int size; | 
					
						
							|  |  |  | 		PyObject *rv; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		size = GetHandleSize((Handle)self->alias); | 
					
						
							|  |  |  | 		HLock((Handle)self->alias); | 
					
						
							|  |  |  | 		rv = PyString_FromStringAndSize(*(Handle)self->alias, size); | 
					
						
							|  |  |  | 		HUnlock((Handle)self->alias); | 
					
						
							|  |  |  | 		return rv; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_FindMethod(mfsa_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-11 21:16:03 +00:00
										 |  |  | static mfsaobject * | 
					
						
							|  |  |  | newmfsaobject(AliasHandle alias) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mfsaobject *self; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	self = PyObject_NEW(mfsaobject, &Mfsatype); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	self->alias = alias; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsa_dealloc(mfsaobject *self) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	if ( self->alias ) { | 
					
						
							|  |  |  | 		should we do something here? | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyMem_DEL(self); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | statichere PyTypeObject Mfsatype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	0,				/*ob_size*/ | 
					
						
							|  |  |  | 	"Alias",			/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(mfsaobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)mfsa_dealloc,	/*tp_dealloc*/ | 
					
						
							| 
									
										
										
										
											1995-02-20 23:43:29 +00:00
										 |  |  | 	(printfunc)0,			/*tp_print*/ | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	(getattrfunc)mfsa_getattr,	/*tp_getattr*/ | 
					
						
							| 
									
										
										
										
											1995-02-20 23:43:29 +00:00
										 |  |  | 	(setattrfunc)0,			/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)0,			/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)0,			/*tp_repr*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_sequence*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_mapping*/ | 
					
						
							|  |  |  | 	(hashfunc)0,			/*tp_hash*/ | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | /* End of code for Alias objects */ | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static struct PyMethodDef mfsi_methods[] = { | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	{NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static mfsiobject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | newmfsiobject(void) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mfsiobject *self; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	self = PyObject_NEW(mfsiobject, &Mfsitype); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	memset((char *)&self->finfo, '\0', sizeof(self->finfo)); | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsi_dealloc(mfsiobject *self) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyMem_DEL(self); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsi_getattr(mfsiobject *self, char *name) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if ( strcmp(name, "Type") == 0 ) | 
					
						
							|  |  |  | 		return PyMac_BuildOSType(self->finfo.fdType); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Creator") == 0 ) | 
					
						
							|  |  |  | 		return PyMac_BuildOSType(self->finfo.fdCreator); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Flags") == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue("i", (int)self->finfo.fdFlags); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Location") == 0 ) | 
					
						
							|  |  |  | 		return PyMac_BuildPoint(self->finfo.fdLocation); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Fldr") == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue("i", (int)self->finfo.fdFldr); | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		return Py_FindMethod(mfsi_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsi_setattr(mfsiobject *self, char *name, PyObject *v) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int rv; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( v == NULL ) { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( strcmp(name, "Type") == 0 ) | 
					
						
							|  |  |  | 		rv = PyMac_GetOSType(v, &self->finfo.fdType); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Creator") == 0 ) | 
					
						
							|  |  |  | 		rv = PyMac_GetOSType(v, &self->finfo.fdCreator); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Flags") == 0 ) { | 
					
						
							|  |  |  | 		rv = PyArg_Parse(v, "i", &i); | 
					
						
							|  |  |  | 		self->finfo.fdFlags = (short)i; | 
					
						
							|  |  |  | 	} else if ( strcmp(name, "Location") == 0 ) | 
					
						
							|  |  |  | 		rv = PyMac_GetPoint(v, &self->finfo.fdLocation); | 
					
						
							|  |  |  | 	else if ( strcmp(name, "Fldr") == 0 ) { | 
					
						
							|  |  |  | 		rv = PyArg_Parse(v, "i", &i); | 
					
						
							|  |  |  | 		self->finfo.fdFldr = (short)i; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		PyErr_SetString(PyExc_AttributeError, "No such attribute"); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (rv) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyTypeObject Mfsitype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 	0,				/*ob_size*/ | 
					
						
							| 
									
										
										
										
											1997-09-20 17:40:22 +00:00
										 |  |  | 	"FInfo",			/*tp_name*/ | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 	sizeof(mfsiobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)mfsi_dealloc,	/*tp_dealloc*/ | 
					
						
							|  |  |  | 	(printfunc)0,		/*tp_print*/ | 
					
						
							|  |  |  | 	(getattrfunc)mfsi_getattr,	/*tp_getattr*/ | 
					
						
							|  |  |  | 	(setattrfunc)mfsi_setattr,	/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)0,		/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)0,		/*tp_repr*/ | 
					
						
							|  |  |  | 	0,			/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,		/*tp_as_sequence*/ | 
					
						
							|  |  |  | 	0,		/*tp_as_mapping*/ | 
					
						
							|  |  |  | 	(hashfunc)0,		/*tp_hash*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End of code for FInfo object objects */ | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | ** Helper routines for the FSRef and FSSpec creators in macglue.c | 
					
						
							|  |  |  | ** They return an FSSpec/FSRef if the Python object encapsulating | 
					
						
							|  |  |  | ** either is passed. They return a boolean success indicator. | 
					
						
							|  |  |  | ** Note that they do not set an exception on failure, they're only | 
					
						
							|  |  |  | ** helper routines. | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | _mfs_GetFSSpecFromFSSpec(PyObject *self, FSSpec *fssp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ( is_mfssobject(self) ) { | 
					
						
							|  |  |  | 		*fssp = ((mfssobject *)self)->fsspec; | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Return an FSSpec if this is an FSref */ | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | _mfs_GetFSSpecFromFSRef(PyObject *self, FSSpec *fssp) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	static FSRef *fsrp; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( is_mfsrobject(self) ) { | 
					
						
							|  |  |  | 		fsrp = &((mfsrobject *)self)->fsref; | 
					
						
							|  |  |  | 		if ( FSGetCatalogInfo(&((mfsrobject *)self)->fsref, kFSCatInfoNone, NULL, NULL, fssp, NULL) == noErr ) | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Return an FSRef if this is an FSRef */ | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | _mfs_GetFSRefFromFSRef(PyObject *self, FSRef *fsrp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	if ( is_mfsrobject(self) ) { | 
					
						
							|  |  |  | 		*fsrp = ((mfsrobject *)self)->fsref; | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Return an FSRef if this is an FSSpec */ | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | _mfs_GetFSRefFromFSSpec(PyObject *self, FSRef *fsrp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	if ( is_mfssobject(self) ) { | 
					
						
							|  |  |  | 		if ( FSpMakeFSRef(&((mfssobject *)self)->fsspec, fsrp) == noErr ) | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Two generally useful routines | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static OSErr | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | PyMac_GetFileDates(FSSpec *fss, unsigned long *crdat, unsigned long *mddat,  | 
					
						
							|  |  |  | 		unsigned long *bkdat) | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	CInfoPBRec pb; | 
					
						
							|  |  |  | 	OSErr error; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	pb.dirInfo.ioNamePtr = fss->name; | 
					
						
							|  |  |  | 	pb.dirInfo.ioFDirIndex = 0; | 
					
						
							|  |  |  | 	pb.dirInfo.ioVRefNum = fss->vRefNum; | 
					
						
							|  |  |  | 	pb.dirInfo.ioDrDirID = fss->parID; | 
					
						
							|  |  |  | 	error = PBGetCatInfoSync(&pb); | 
					
						
							|  |  |  | 	if ( error ) return error; | 
					
						
							|  |  |  | 	*crdat = pb.hFileInfo.ioFlCrDat; | 
					
						
							|  |  |  | 	*mddat = pb.hFileInfo.ioFlMdDat; | 
					
						
							|  |  |  | 	*bkdat = pb.hFileInfo.ioFlBkDat; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static OSErr | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | PyMac_SetFileDates(FSSpec *fss, unsigned long crdat, unsigned long mddat,  | 
					
						
							|  |  |  | 		unsigned long bkdat) | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	CInfoPBRec pb; | 
					
						
							|  |  |  | 	OSErr error; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	pb.dirInfo.ioNamePtr = fss->name; | 
					
						
							|  |  |  | 	pb.dirInfo.ioFDirIndex = 0; | 
					
						
							|  |  |  | 	pb.dirInfo.ioVRefNum = fss->vRefNum; | 
					
						
							|  |  |  | 	pb.dirInfo.ioDrDirID = fss->parID; | 
					
						
							|  |  |  | 	error = PBGetCatInfoSync(&pb); | 
					
						
							|  |  |  | 	if ( error ) return error; | 
					
						
							|  |  |  | 	pb.dirInfo.ioNamePtr = fss->name; | 
					
						
							|  |  |  | 	pb.dirInfo.ioFDirIndex = 0; | 
					
						
							|  |  |  | 	pb.dirInfo.ioVRefNum = fss->vRefNum; | 
					
						
							|  |  |  | 	pb.dirInfo.ioDrDirID = fss->parID; | 
					
						
							|  |  |  | 	pb.hFileInfo.ioFlCrDat = crdat; | 
					
						
							|  |  |  | 	pb.hFileInfo.ioFlMdDat = mddat; | 
					
						
							|  |  |  | 	pb.hFileInfo.ioFlBkDat = bkdat; | 
					
						
							|  |  |  | 	error = PBSetCatInfoSync(&pb); | 
					
						
							|  |  |  | 	return error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_as_pathname(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-09-10 22:00:39 +00:00
										 |  |  | 	char strbuf[PATHNAMELEN]; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	OSErr err; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2001-09-10 22:00:39 +00:00
										 |  |  | 	err = PyMac_GetFullPathname(&self->fsspec, strbuf, PATHNAMELEN); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyString_FromString(strbuf); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_as_tuple(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,  | 
					
						
							|  |  |  | 						&self->fsspec.name[1], self->fsspec.name[0]); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_NewAlias(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FSSpec src, *srcp; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	AliasHandle alias; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	src.name[0] = 0; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src)) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if ( src.name[0] ) | 
					
						
							|  |  |  | 		srcp = &src; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		srcp = NULL; | 
					
						
							|  |  |  | 	err = NewAlias(srcp, &self->fsspec, &alias); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfsaobject(alias); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_NewAliasMinimal(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	AliasHandle alias; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	err = NewAliasMinimal(&self->fsspec, &alias); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfsaobject(alias); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_FSpMakeFSRef(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform"); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	FSRef fsref; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FSpMakeFSRef(&self->fsspec, &fsref); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)newmfsrobject(&fsref); | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | /* XXXX These routines should be replaced by a wrapper to the *FInfo routines */ | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_GetCreatorType(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-02-02 14:23:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	FInfo info; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1995-02-02 14:23:52 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FSpGetFInfo(&self->fsspec, &info); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return Py_BuildValue("(O&O&)", | 
					
						
							|  |  |  | 	           PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_SetCreatorType(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-02-02 14:23:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	OSType creator, type; | 
					
						
							|  |  |  | 	FInfo info; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) | 
					
						
							| 
									
										
										
										
											1995-02-02 14:23:52 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FSpGetFInfo(&self->fsspec, &info); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	info.fdType = type; | 
					
						
							|  |  |  | 	info.fdCreator = creator; | 
					
						
							|  |  |  | 	err = FSpSetFInfo(&self->fsspec, &info); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1995-02-02 14:23:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_GetFInfo(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	mfsiobject *fip; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if ( (fip=newmfsiobject()) == NULL ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FSpGetFInfo(&self->fsspec, &fip->finfo); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		Py_DECREF(fip); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)fip; | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_SetFInfo(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	mfsiobject *fip; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip)) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FSpSetFInfo(&self->fsspec, &fip->finfo); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_GetDates(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	unsigned long crdat, mddat, bkdat; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat); | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_SetDates(mfssobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	double crdat, mddat, bkdat; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat)) | 
					
						
							| 
									
										
										
										
											1996-09-15 22:11:25 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,  | 
					
						
							|  |  |  | 				(unsigned long)mddat, (unsigned long)bkdat); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef mfss_methods[] = { | 
					
						
							|  |  |  | 	{"as_pathname",		(PyCFunction)mfss_as_pathname,			1}, | 
					
						
							|  |  |  | 	{"as_tuple",		(PyCFunction)mfss_as_tuple,				1}, | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	{"as_fsref",	(PyCFunction)mfss_FSpMakeFSRef,			1}, | 
					
						
							|  |  |  | 	{"FSpMakeFSRef",	(PyCFunction)mfss_FSpMakeFSRef,			1}, | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	{"NewAlias",		(PyCFunction)mfss_NewAlias,				1}, | 
					
						
							|  |  |  | 	{"NewAliasMinimal",	(PyCFunction)mfss_NewAliasMinimal,		1}, | 
					
						
							|  |  |  | 	{"GetCreatorType",	(PyCFunction)mfss_GetCreatorType,		1}, | 
					
						
							|  |  |  | 	{"SetCreatorType",	(PyCFunction)mfss_SetCreatorType,		1}, | 
					
						
							|  |  |  | 	{"GetFInfo",		(PyCFunction)mfss_GetFInfo,				1}, | 
					
						
							|  |  |  | 	{"SetFInfo",		(PyCFunction)mfss_SetFInfo,				1}, | 
					
						
							|  |  |  | 	{"GetDates",		(PyCFunction)mfss_GetDates,				1}, | 
					
						
							|  |  |  | 	{"SetDates",		(PyCFunction)mfss_SetDates,				1}, | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  |   | 
					
						
							|  |  |  | 	{NULL,			NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_getattr(mfssobject *self, char *name) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | 	if ( strcmp(name, "data") == 0) | 
					
						
							|  |  |  | 		return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_FindMethod(mfss_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | mfssobject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | newmfssobject(FSSpec *fss) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mfssobject *self; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	self = PyObject_NEW(mfssobject, &Mfsstype); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	self->fsspec = *fss; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_dealloc(mfssobject *self) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyMem_DEL(self); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_repr(mfssobject *self) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char buf[512]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | 	sprintf(buf, "FSSpec((%d, %ld, '%.*s'))", | 
					
						
							| 
									
										
										
										
											1995-02-20 23:43:29 +00:00
										 |  |  | 		self->fsspec.vRefNum,  | 
					
						
							|  |  |  | 		self->fsspec.parID, | 
					
						
							|  |  |  | 		self->fsspec.name[0], self->fsspec.name+1); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyString_FromString(buf); | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfss_compare(mfssobject *v, mfssobject *w) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int minlen; | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1; | 
					
						
							|  |  |  | 	if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1; | 
					
						
							|  |  |  | 	if ( v->fsspec.parID < w->fsspec.parID ) return -1; | 
					
						
							|  |  |  | 	if ( v->fsspec.parID > w->fsspec.parID ) return 1; | 
					
						
							|  |  |  | 	minlen = v->fsspec.name[0]; | 
					
						
							|  |  |  | 	if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0]; | 
					
						
							|  |  |  | 	res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen); | 
					
						
							|  |  |  | 	if ( res ) return res; | 
					
						
							|  |  |  | 	if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1; | 
					
						
							|  |  |  | 	if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1; | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | statichere PyTypeObject Mfsstype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	0,				/*ob_size*/ | 
					
						
							|  |  |  | 	"FSSpec",			/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(mfssobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)mfss_dealloc,	/*tp_dealloc*/ | 
					
						
							|  |  |  | 	(printfunc)0,		/*tp_print*/ | 
					
						
							|  |  |  | 	(getattrfunc)mfss_getattr,	/*tp_getattr*/ | 
					
						
							|  |  |  | 	(setattrfunc)0,	/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)mfss_compare,		/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)mfss_repr,		/*tp_repr*/ | 
					
						
							|  |  |  | 	0,			/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,		/*tp_as_sequence*/ | 
					
						
							|  |  |  | 	0,		/*tp_as_mapping*/ | 
					
						
							|  |  |  | 	(hashfunc)0,		/*tp_hash*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End of code for FSSpec objects */ | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if !TARGET_API_MAC_OS8
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsr_as_fsspec(mfsrobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	FSSpec fss; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FSGetCatalogInfo(&self->fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return (PyObject *)newmfssobject(&fss); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef mfsr_methods[] = { | 
					
						
							|  |  |  | 	{"as_fsspec",		(PyCFunction)mfsr_as_fsspec,	1}, | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	{"as_pathname",		(PyCFunction)mfss_as_pathname,			1}, | 
					
						
							|  |  |  | 	{"as_tuple",		(PyCFunction)mfss_as_tuple,				1}, | 
					
						
							|  |  |  | 	{"NewAlias",		(PyCFunction)mfss_NewAlias,				1}, | 
					
						
							|  |  |  | 	{"NewAliasMinimal",	(PyCFunction)mfss_NewAliasMinimal,		1}, | 
					
						
							|  |  |  | 	{"GetCreatorType",	(PyCFunction)mfss_GetCreatorType,		1}, | 
					
						
							|  |  |  | 	{"SetCreatorType",	(PyCFunction)mfss_SetCreatorType,		1}, | 
					
						
							|  |  |  | 	{"GetFInfo",		(PyCFunction)mfss_GetFInfo,				1}, | 
					
						
							|  |  |  | 	{"SetFInfo",		(PyCFunction)mfss_SetFInfo,				1}, | 
					
						
							|  |  |  | 	{"GetDates",		(PyCFunction)mfss_GetDates,				1}, | 
					
						
							|  |  |  | 	{"SetDates",		(PyCFunction)mfss_SetDates,				1}, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | 	{NULL,			NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsr_getattr(mfsrobject *self, char *name) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if ( strcmp(name, "data") == 0) | 
					
						
							|  |  |  | 		return PyString_FromStringAndSize((char *)&self->fsref, sizeof(FSRef));	 | 
					
						
							|  |  |  | 	return Py_FindMethod(mfsr_methods, (PyObject *)self, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | mfsrobject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | newmfsrobject(FSRef *fsr) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mfsrobject *self; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	self = PyObject_NEW(mfsrobject, &Mfsrtype); | 
					
						
							|  |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	self->fsref = *fsr; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsr_compare(mfsrobject *v, mfsrobject *w) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( v == w ) return 0; | 
					
						
							|  |  |  | 	err = FSCompareFSRefs(&v->fsref, &w->fsref); | 
					
						
							|  |  |  | 	if ( err == 0 ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	if (v < w ) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfsr_dealloc(mfsrobject *self) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	PyMem_DEL(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | statichere PyTypeObject Mfsrtype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,				/*ob_size*/ | 
					
						
							|  |  |  | 	"FSRef",			/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(mfsrobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)mfsr_dealloc,	/*tp_dealloc*/ | 
					
						
							|  |  |  | 	(printfunc)0,		/*tp_print*/ | 
					
						
							|  |  |  | 	(getattrfunc)mfsr_getattr,	/*tp_getattr*/ | 
					
						
							|  |  |  | 	(setattrfunc)0,	/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)mfsr_compare,		/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)0,		/*tp_repr*/ | 
					
						
							|  |  |  | 	0,			/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,		/*tp_as_sequence*/ | 
					
						
							|  |  |  | 	0,		/*tp_as_mapping*/ | 
					
						
							|  |  |  | 	(hashfunc)0,		/*tp_hash*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End of code for FSRef objects */ | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif /* !TARGET_API_MAC_OS8 */
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_ResolveAliasFile(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	FSSpec fss; | 
					
						
							|  |  |  | 	Boolean chain = 1, isfolder, wasaliased; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain)) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 22:37:27 +00:00
										 |  |  | #if !TARGET_API_MAC_CARBON
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_StandardGetFile(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-30 08:56:06 +00:00
										 |  |  | 	SFTypeList list; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 	short numtypes; | 
					
						
							|  |  |  | 	StandardFileReply reply; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	list[0] = list[1] = list[2] = list[3] = 0; | 
					
						
							|  |  |  | 	numtypes = 0; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0], | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 			 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], | 
					
						
							|  |  |  | 			  PyMac_GetOSType, &list[3]) ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1995-01-30 08:56:06 +00:00
										 |  |  | 	while ( numtypes < 4 && list[numtypes] ) { | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		numtypes++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1995-06-03 21:15:50 +00:00
										 |  |  | 	if ( numtypes == 0 ) | 
					
						
							|  |  |  | 		numtypes = -1; | 
					
						
							| 
									
										
										
										
											1995-01-30 08:56:06 +00:00
										 |  |  | 	StandardGetFile((FileFilterUPP)0, numtypes, list, &reply); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_PromptGetFile(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-08-14 12:22:56 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	SFTypeList list; | 
					
						
							|  |  |  | 	short numtypes; | 
					
						
							|  |  |  | 	StandardFileReply reply; | 
					
						
							|  |  |  | 	char *prompt = NULL; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	list[0] = list[1] = list[2] = list[3] = 0; | 
					
						
							|  |  |  | 	numtypes = 0; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0], | 
					
						
							| 
									
										
										
										
											1995-08-14 12:22:56 +00:00
										 |  |  | 			 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], | 
					
						
							|  |  |  | 			  PyMac_GetOSType, &list[3]) ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	while ( numtypes < 4 && list[numtypes] ) { | 
					
						
							|  |  |  | 		numtypes++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( numtypes == 0 ) | 
					
						
							|  |  |  | 		numtypes = -1; | 
					
						
							|  |  |  | 	PyMac_PromptGetFile(numtypes, list, &reply, prompt); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); | 
					
						
							| 
									
										
										
										
											1995-08-14 12:22:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_StandardPutFile(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	Str255 prompt, dft; | 
					
						
							|  |  |  | 	StandardFileReply reply; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	dft[0] = 0; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) ) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	StandardPutFile(prompt, dft, &reply); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Set initial directory for file dialogs */ | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_SetFolder(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FSSpec spec; | 
					
						
							|  |  |  | 	FSSpec ospec; | 
					
						
							|  |  |  | 	short orefnum; | 
					
						
							|  |  |  | 	long oparid; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Get old values */ | 
					
						
							|  |  |  | 	orefnum = -LMGetSFSaveDisk(); | 
					
						
							|  |  |  | 	oparid = LMGetCurDirStore(); | 
					
						
							|  |  |  | 	(void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Go to working directory by default */ | 
					
						
							|  |  |  | 	(void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec)) | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	/* Set standard-file working directory */ | 
					
						
							|  |  |  | 	LMSetSFSaveDisk(-spec.vRefNum); | 
					
						
							|  |  |  | 	LMSetCurDirStore(spec.parID); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfssobject(&ospec); | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-06-02 21:35:07 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_FSSpec(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FSSpec fss; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss)) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfssobject(&fss); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_FSRef(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform"); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	FSRef fsr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &fsr)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	return (PyObject *)newmfsrobject(&fsr); | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_RawFSSpec(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FSSpec *fssp; | 
					
						
							|  |  |  | 	int size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-07 15:46:31 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s#", &fssp, &size)) | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if ( size != sizeof(FSSpec) ) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfssobject(fssp); | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_RawAlias(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *dataptr; | 
					
						
							|  |  |  | 	Handle h; | 
					
						
							|  |  |  | 	int size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-07 15:46:31 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s#", &dataptr, &size)) | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	h = NewHandle(size); | 
					
						
							|  |  |  | 	if ( h == NULL ) { | 
					
						
							|  |  |  | 		PyErr_NoMemory(); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	HLock(h); | 
					
						
							|  |  |  | 	memcpy((char *)*h, dataptr, size); | 
					
						
							|  |  |  | 	HUnlock(h); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfsaobject((AliasHandle)h); | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 22:37:27 +00:00
										 |  |  | #if !TARGET_API_MAC_CARBON
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_GetDirectory(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-02-20 15:45:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FSSpec fsdir; | 
					
						
							|  |  |  | 	int ok; | 
					
						
							| 
									
										
										
										
											1995-08-14 12:22:56 +00:00
										 |  |  | 	char *prompt = NULL; | 
					
						
							| 
									
										
										
										
											1995-02-20 15:45:25 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|s", &prompt) ) | 
					
						
							| 
									
										
										
										
											1995-02-20 15:45:25 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											1995-08-14 12:22:56 +00:00
										 |  |  | 	ok = PyMac_GetDirectory(&fsdir, prompt); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok); | 
					
						
							| 
									
										
										
										
											1995-02-20 15:45:25 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-07-14 22:16:45 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-02-20 15:45:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_FindFolder(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-06-18 20:05:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	short where; | 
					
						
							|  |  |  | 	OSType which; | 
					
						
							|  |  |  | 	int create; | 
					
						
							|  |  |  | 	short refnum; | 
					
						
							|  |  |  | 	long dirid; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-03-15 14:38:10 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) ) | 
					
						
							| 
									
										
										
										
											1995-06-18 20:05:14 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FindFolder(where, which, (Boolean)create, &refnum, &dirid); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return Py_BuildValue("(ii)", refnum, dirid); | 
					
						
							| 
									
										
										
										
											1995-06-18 20:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_FindApplication(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1996-09-20 15:25:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	OSType which; | 
					
						
							|  |  |  | 	FSSpec	fss; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) ) | 
					
						
							| 
									
										
										
										
											1996-09-20 15:25:16 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = FindApplicationFromCreator(which, &fss); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfssobject(&fss); | 
					
						
							| 
									
										
										
										
											1996-09-20 15:25:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_FInfo(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | {	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return (PyObject *)newmfsiobject(); | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-16 14:31:38 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | mfs_NewAliasMinimalFromFullPath(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-06-16 14:31:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	char *fullpath; | 
					
						
							|  |  |  | 	int fullpathlen; | 
					
						
							|  |  |  | 	AliasHandle alias; | 
					
						
							|  |  |  | 	Str32 zonename; | 
					
						
							|  |  |  | 	Str31 servername; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	zonename[0] = 0; | 
					
						
							|  |  |  | 	servername[0] = 0; | 
					
						
							|  |  |  | 	err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,  | 
					
						
							|  |  |  | 			servername, &alias); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)newmfsaobject(alias); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | /* List of methods defined in the module */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static struct PyMethodDef mfs_methods[] = { | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	{"ResolveAliasFile",	mfs_ResolveAliasFile,	1}, | 
					
						
							| 
									
										
										
										
											2000-07-14 22:37:27 +00:00
										 |  |  | #if !TARGET_API_MAC_CARBON
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	{"StandardGetFile",		mfs_StandardGetFile,	1}, | 
					
						
							| 
									
										
										
										
											1995-08-14 12:22:56 +00:00
										 |  |  | 	{"PromptGetFile",		mfs_PromptGetFile,		1}, | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	{"StandardPutFile",		mfs_StandardPutFile,	1}, | 
					
						
							| 
									
										
										
										
											1995-02-20 15:45:25 +00:00
										 |  |  | 	{"GetDirectory",		mfs_GetDirectory,		1}, | 
					
						
							| 
									
										
										
										
											1996-07-22 15:26:01 +00:00
										 |  |  | 	{"SetFolder",			mfs_SetFolder,			1}, | 
					
						
							| 
									
										
										
										
											2000-06-02 21:35:07 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-26 16:22:07 +00:00
										 |  |  | 	{"FSSpec",				mfs_FSSpec,				1}, | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	{"FSRef",				mfs_FSRef,				1}, | 
					
						
							| 
									
										
										
										
											1995-02-13 12:00:46 +00:00
										 |  |  | 	{"RawFSSpec",			mfs_RawFSSpec,			1}, | 
					
						
							|  |  |  | 	{"RawAlias",			mfs_RawAlias,			1}, | 
					
						
							| 
									
										
										
										
											1995-06-18 20:05:14 +00:00
										 |  |  | 	{"FindFolder",			mfs_FindFolder,			1}, | 
					
						
							| 
									
										
										
										
											1996-09-20 15:25:16 +00:00
										 |  |  | 	{"FindApplication",		mfs_FindApplication,	1}, | 
					
						
							| 
									
										
										
										
											1995-08-07 14:04:10 +00:00
										 |  |  | 	{"FInfo",				mfs_FInfo,				1}, | 
					
						
							| 
									
										
										
										
											1997-06-16 14:31:38 +00:00
										 |  |  | 	{"NewAliasMinimalFromFullPath",	mfs_NewAliasMinimalFromFullPath,	1}, | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  |   | 
					
						
							|  |  |  | 	{NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Convert a Python object to an FSSpec. | 
					
						
							|  |  |  | ** The object may either be a full pathname, an FSSpec, an FSRef or a triple | 
					
						
							|  |  |  | ** (vrefnum, dirid, path). | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyMac_GetFSRef(PyObject *v, FSRef *fsr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	/* If it's an FSRef we're also okay. */ | 
					
						
							|  |  |  | 	if (_mfs_GetFSRefFromFSRef(v, fsr)) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	/* first check whether it already is an FSSpec */ | 
					
						
							|  |  |  | 	if ( _mfs_GetFSRefFromFSSpec(v, fsr) ) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	if ( PyString_Check(v) ) { | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | #if TARGET_API_MAC_OSX
 | 
					
						
							|  |  |  | 		OSStatus err; | 
					
						
							|  |  |  | 		if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) { | 
					
						
							|  |  |  | 			PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 		PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname"); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert FSSpec to PyObject */ | 
					
						
							|  |  |  | PyObject *PyMac_BuildFSRef(FSRef *v) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #if TARGET_API_MAC_OS8
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | 	return (PyObject *)newmfsrobject(v); | 
					
						
							| 
									
										
										
										
											2001-08-03 13:31:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-07-08 22:07:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Convert a Python object to an FSRef. | 
					
						
							|  |  |  | ** The object may either be a full pathname (OSX only), an FSSpec or an FSRef. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | PyMac_GetFSSpec(PyObject *v, FSSpec *fs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Str255 path; | 
					
						
							|  |  |  | 	short refnum; | 
					
						
							|  |  |  | 	long parid; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* first check whether it already is an FSSpec */ | 
					
						
							|  |  |  | 	if ( _mfs_GetFSSpecFromFSSpec(v, fs) ) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	/* If it's an FSRef we're also okay. */ | 
					
						
							|  |  |  | 	if (_mfs_GetFSSpecFromFSRef(v, fs)) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	if ( PyString_Check(v) ) { | 
					
						
							|  |  |  | 		/* It's a pathname */ | 
					
						
							|  |  |  | 		if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) ) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		refnum = 0; /* XXXX Should get CurWD here?? */ | 
					
						
							|  |  |  | 		parid = 0; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if( !PyArg_Parse(v, "(hlO&); FSSpec should be FSSpec, FSRef, fullpath or (vrefnum,dirid,path)", | 
					
						
							|  |  |  | 							&refnum, &parid, PyMac_GetStr255, &path)) { | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	err = FSMakeFSSpec(refnum, parid, path, fs); | 
					
						
							|  |  |  | 	if ( err && err != fnfErr ) { | 
					
						
							|  |  |  | 		PyMac_Error(err); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Convert FSSpec to PyObject */ | 
					
						
							|  |  |  | PyObject *PyMac_BuildFSSpec(FSSpec *v) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (PyObject *)newmfssobject(v); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Initialization function for the module (*must* be called initmacfs) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2001-08-08 13:46:49 +00:00
										 |  |  | initmacfs(void) | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *m, *d; | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-06 15:32:30 +00:00
										 |  |  | 		PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec); | 
					
						
							| 
									
										
										
										
											2001-09-01 23:39:58 +00:00
										 |  |  | 		PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef); | 
					
						
							|  |  |  | 		PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec); | 
					
						
							|  |  |  | 		PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef); | 
					
						
							| 
									
										
										
										
											2001-08-03 15:39:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 	/* Create the module and add the functions */ | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	m = Py_InitModule("macfs", mfs_methods); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Add some symbolic constants to the module */ | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	d = PyModule_GetDict(m); | 
					
						
							| 
									
										
										
										
											2000-01-24 10:37:59 +00:00
										 |  |  | 	ErrorObject = PyMac_GetOSErrException(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyDict_SetItemString(d, "error", ErrorObject); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-09-20 17:40:22 +00:00
										 |  |  | 	Mfsatype.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 	Py_INCREF(&Mfsatype); | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype); | 
					
						
							|  |  |  | 	Mfsstype.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 	Py_INCREF(&Mfsstype); | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype); | 
					
						
							|  |  |  | 	Mfsitype.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 	Py_INCREF(&Mfsitype); | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype); | 
					
						
							| 
									
										
										
										
											1995-01-18 14:04:40 +00:00
										 |  |  | 	/* XXXX Add constants here */ | 
					
						
							|  |  |  | } |