blob: 26d7d7f750d2898ce78b2fe168bde7ff7c1d36f1 [file] [log] [blame]
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001/***********************************************************
Jack Jansen42218ce1997-01-31 16:15:11 +00002Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Guido van Rossumefd97671995-01-26 22:56:16 +00003The Netherlands.
Jack Jansen84fa5ec1995-01-18 14:04:40 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Jack Jansenf5c20571997-01-30 15:48:07 +000025#include "Python.h"
Jack Jansen84fa5ec1995-01-18 14:04:40 +000026#include "macglue.h"
Jack Jansena5bca572001-08-03 15:39:27 +000027#include "pymactoolbox.h"
Jack Jansen84fa5ec1995-01-18 14:04:40 +000028
Jack Jansen6143d532001-05-19 12:34:59 +000029#ifdef WITHOUT_FRAMEWORKS
Guido van Rossumbecdbec1995-02-14 01:27:24 +000030#include <Memory.h>
Jack Jansen84fa5ec1995-01-18 14:04:40 +000031#include <Files.h>
Jack Jansen2c673621995-06-18 20:05:14 +000032#include <Folders.h>
Jack Jansen84fa5ec1995-01-18 14:04:40 +000033#include <StandardFile.h>
34#include <Aliases.h>
Jack Jansend99d2831996-07-22 15:26:01 +000035#include <LowMem.h>
Jack Jansen6143d532001-05-19 12:34:59 +000036#else
37#include <Carbon/Carbon.h>
38#endif
Jack Jansen84fa5ec1995-01-18 14:04:40 +000039
Jack Jansen924ca851996-09-20 15:25:16 +000040#include "getapplbycreator.h"
Jack Jansen84fa5ec1995-01-18 14:04:40 +000041
Jack Jansen01a94622001-11-01 14:00:19 +000042#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +000043#include "pythonresources.h"
44extern PyMac_PrefRecord PyMac_options;
Jack Jansen01a94622001-11-01 14:00:19 +000045#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +000046
Jack Jansena5bca572001-08-03 15:39:27 +000047#ifdef USE_TOOLBOX_OBJECT_GLUE
48extern int _PyMac_GetFSSpec(PyObject *, FSSpec *);
Jack Jansen61142972001-09-02 00:09:35 +000049extern PyObject *_PyMac_BuildFSSpec(FSSpec *);
50extern int _PyMac_GetFSRef(PyObject *, FSRef *);
Jack Jansenfabd00f2001-09-01 23:39:58 +000051extern PyObject *_PyMac_BuildFSRef(FSRef *);
Jack Jansena5bca572001-08-03 15:39:27 +000052#define PyMac_GetFSSpec _PyMac_GetFSSpec
Jack Jansenfabd00f2001-09-01 23:39:58 +000053#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
54#define PyMac_GetFSRef _PyMac_GetFSRef
55#define PyMac_BuildFSRef _PyMac_BuildFSRef
Jack Jansena5bca572001-08-03 15:39:27 +000056#endif
Jack Jansenf5c20571997-01-30 15:48:07 +000057static PyObject *ErrorObject;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000058
Jack Jansen697842f2001-09-10 22:00:39 +000059#ifdef TARGET_API_MAC_OSX
60#define PATHNAMELEN 1024
61#else
62#define PATHNAMELEN 256
63#endif
64
Jack Jansen84fa5ec1995-01-18 14:04:40 +000065/* ----------------------------------------------------- */
Jack Jansen17ba43f1995-01-26 16:22:07 +000066/* Declarations for objects of type Alias */
67
68typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000069 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000070 AliasHandle alias;
71} mfsaobject;
72
Jack Jansenf5c20571997-01-30 15:48:07 +000073staticforward PyTypeObject Mfsatype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000074
75#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
76
77/* ---------------------------------------------------------------- */
78/* Declarations for objects of type FSSpec */
79
80typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000081 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000082 FSSpec fsspec;
83} mfssobject;
84
Jack Jansenf5c20571997-01-30 15:48:07 +000085staticforward PyTypeObject Mfsstype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000086
87#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
88
Jack Jansen4e566ab2001-07-08 22:07:23 +000089/* ---------------------------------------------------------------- */
90/* Declarations for objects of type FSRef */
91
92typedef struct {
93 PyObject_HEAD
94 FSRef fsref;
95} mfsrobject;
96
97staticforward PyTypeObject Mfsrtype;
98
99#define is_mfsrobject(v) ((v)->ob_type == &Mfsrtype)
100
Guido van Rossumefd97671995-01-26 22:56:16 +0000101
Jack Jansen3d185931995-08-07 14:04:10 +0000102/* ---------------------------------------------------------------- */
103/* Declarations for objects of type FInfo */
104
105typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +0000106 PyObject_HEAD
Jack Jansen3d185931995-08-07 14:04:10 +0000107 FInfo finfo;
108} mfsiobject;
109
Jack Jansenf5c20571997-01-30 15:48:07 +0000110staticforward PyTypeObject Mfsitype;
Jack Jansen3d185931995-08-07 14:04:10 +0000111
112#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
113
114
Jack Jansen4e566ab2001-07-08 22:07:23 +0000115staticforward mfssobject *newmfssobject(FSSpec *fss); /* Forward */
116staticforward mfsrobject *newmfsrobject(FSRef *fsr); /* Forward */
Guido van Rossumefd97671995-01-26 22:56:16 +0000117
Jack Jansen17ba43f1995-01-26 16:22:07 +0000118/* ---------------------------------------------------------------- */
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000119
Jack Jansenf5c20571997-01-30 15:48:07 +0000120static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000121mfsa_Resolve(mfsaobject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000122{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000123 FSSpec from, *fromp, result;
124 Boolean changed;
125 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000126
Jack Jansen17ba43f1995-01-26 16:22:07 +0000127 from.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000128 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000129 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000130 if (from.name[0] )
131 fromp = &from;
132 else
133 fromp = NULL;
134 err = ResolveAlias(fromp, self->alias, &result, &changed);
Jack Jansend9936481997-06-16 14:31:38 +0000135 if ( err && err != fnfErr ) {
Jack Jansen17ba43f1995-01-26 16:22:07 +0000136 PyErr_Mac(ErrorObject, err);
137 return NULL;
138 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000139 return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000140}
141
Jack Jansenf5c20571997-01-30 15:48:07 +0000142static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000143mfsa_GetInfo(mfsaobject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000144{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000145 Str63 value;
146 int i;
147 OSErr err;
148
Jack Jansenf5c20571997-01-30 15:48:07 +0000149 if (!PyArg_ParseTuple(args, "i", &i))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000150 return NULL;
151 err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
152 if ( err ) {
153 PyErr_Mac(ErrorObject, err);
154 return 0;
155 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000156 return PyString_FromStringAndSize((char *)&value[1], value[0]);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000157}
158
Jack Jansenf5c20571997-01-30 15:48:07 +0000159static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000160mfsa_Update(mfsaobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000161{
162 FSSpec target, fromfile, *fromfilep;
163 OSErr err;
164 Boolean changed;
165
166 fromfile.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000167 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target,
Jack Jansen17ba43f1995-01-26 16:22:07 +0000168 PyMac_GetFSSpec, &fromfile))
169 return NULL;
170 if ( fromfile.name[0] )
171 fromfilep = &fromfile;
172 else
173 fromfilep = NULL;
174 err = UpdateAlias(fromfilep, &target, self->alias, &changed);
175 if ( err ) {
176 PyErr_Mac(ErrorObject, err);
177 return 0;
178 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000179 return Py_BuildValue("i", (int)changed);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000180}
181
Jack Jansenf5c20571997-01-30 15:48:07 +0000182static struct PyMethodDef mfsa_methods[] = {
183 {"Resolve", (PyCFunction)mfsa_Resolve, 1},
184 {"GetInfo", (PyCFunction)mfsa_GetInfo, 1},
185 {"Update", (PyCFunction)mfsa_Update, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000186
187 {NULL, NULL} /* sentinel */
188};
189
190/* ---------- */
191
Jack Jansenf5c20571997-01-30 15:48:07 +0000192static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000193mfsa_getattr(mfsaobject *self, char *name)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000194{
Jack Jansenc889b761995-02-13 12:00:46 +0000195 if ( strcmp(name, "data") == 0 ) {
196 int size;
197 PyObject *rv;
198
199 size = GetHandleSize((Handle)self->alias);
200 HLock((Handle)self->alias);
201 rv = PyString_FromStringAndSize(*(Handle)self->alias, size);
202 HUnlock((Handle)self->alias);
203 return rv;
204 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000205 return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000206}
207
Jack Jansen9ae898b2000-07-11 21:16:03 +0000208static mfsaobject *
209newmfsaobject(AliasHandle alias)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000210{
211 mfsaobject *self;
212
Jack Jansenf5c20571997-01-30 15:48:07 +0000213 self = PyObject_NEW(mfsaobject, &Mfsatype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000214 if (self == NULL)
215 return NULL;
216 self->alias = alias;
217 return self;
218}
219
220
221static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000222mfsa_dealloc(mfsaobject *self)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000223{
224#if 0
225 if ( self->alias ) {
226 should we do something here?
227 }
228#endif
229
Jack Jansenf5c20571997-01-30 15:48:07 +0000230 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000231}
232
Jack Jansenf5c20571997-01-30 15:48:07 +0000233statichere PyTypeObject Mfsatype = {
234 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000235 0, /*ob_size*/
236 "Alias", /*tp_name*/
237 sizeof(mfsaobject), /*tp_basicsize*/
238 0, /*tp_itemsize*/
239 /* methods */
240 (destructor)mfsa_dealloc, /*tp_dealloc*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000241 (printfunc)0, /*tp_print*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000242 (getattrfunc)mfsa_getattr, /*tp_getattr*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000243 (setattrfunc)0, /*tp_setattr*/
244 (cmpfunc)0, /*tp_compare*/
245 (reprfunc)0, /*tp_repr*/
246 0, /*tp_as_number*/
247 0, /*tp_as_sequence*/
248 0, /*tp_as_mapping*/
249 (hashfunc)0, /*tp_hash*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000250};
251
252/* End of code for Alias objects */
253/* -------------------------------------------------------- */
254
Jack Jansen3d185931995-08-07 14:04:10 +0000255/* ---------------------------------------------------------------- */
256
Jack Jansenf5c20571997-01-30 15:48:07 +0000257static struct PyMethodDef mfsi_methods[] = {
Jack Jansen3d185931995-08-07 14:04:10 +0000258
259 {NULL, NULL} /* sentinel */
260};
261
262/* ---------- */
263
264static mfsiobject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000265newmfsiobject(void)
Jack Jansen3d185931995-08-07 14:04:10 +0000266{
267 mfsiobject *self;
268
Jack Jansenf5c20571997-01-30 15:48:07 +0000269 self = PyObject_NEW(mfsiobject, &Mfsitype);
Jack Jansen3d185931995-08-07 14:04:10 +0000270 if (self == NULL)
271 return NULL;
272 memset((char *)&self->finfo, '\0', sizeof(self->finfo));
273 return self;
274}
275
276static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000277mfsi_dealloc(mfsiobject *self)
Jack Jansen3d185931995-08-07 14:04:10 +0000278{
Jack Jansenf5c20571997-01-30 15:48:07 +0000279 PyMem_DEL(self);
Jack Jansen3d185931995-08-07 14:04:10 +0000280}
281
Jack Jansenf5c20571997-01-30 15:48:07 +0000282static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000283mfsi_getattr(mfsiobject *self, char *name)
Jack Jansen3d185931995-08-07 14:04:10 +0000284{
Jack Jansen3d185931995-08-07 14:04:10 +0000285 if ( strcmp(name, "Type") == 0 )
286 return PyMac_BuildOSType(self->finfo.fdType);
287 else if ( strcmp(name, "Creator") == 0 )
288 return PyMac_BuildOSType(self->finfo.fdCreator);
289 else if ( strcmp(name, "Flags") == 0 )
290 return Py_BuildValue("i", (int)self->finfo.fdFlags);
291 else if ( strcmp(name, "Location") == 0 )
292 return PyMac_BuildPoint(self->finfo.fdLocation);
293 else if ( strcmp(name, "Fldr") == 0 )
294 return Py_BuildValue("i", (int)self->finfo.fdFldr);
295 else
Jack Jansenf5c20571997-01-30 15:48:07 +0000296 return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
Jack Jansen3d185931995-08-07 14:04:10 +0000297}
298
299
300static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000301mfsi_setattr(mfsiobject *self, char *name, PyObject *v)
Jack Jansen3d185931995-08-07 14:04:10 +0000302{
303 int rv;
304 int i;
305
306 if ( v == NULL ) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000307 PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000308 return -1;
309 }
310 if ( strcmp(name, "Type") == 0 )
311 rv = PyMac_GetOSType(v, &self->finfo.fdType);
312 else if ( strcmp(name, "Creator") == 0 )
313 rv = PyMac_GetOSType(v, &self->finfo.fdCreator);
314 else if ( strcmp(name, "Flags") == 0 ) {
315 rv = PyArg_Parse(v, "i", &i);
316 self->finfo.fdFlags = (short)i;
317 } else if ( strcmp(name, "Location") == 0 )
318 rv = PyMac_GetPoint(v, &self->finfo.fdLocation);
319 else if ( strcmp(name, "Fldr") == 0 ) {
320 rv = PyArg_Parse(v, "i", &i);
321 self->finfo.fdFldr = (short)i;
322 } else {
Jack Jansenf5c20571997-01-30 15:48:07 +0000323 PyErr_SetString(PyExc_AttributeError, "No such attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000324 return -1;
325 }
326 if (rv)
327 return 0;
328 return -1;
329}
330
331
Jack Jansenf5c20571997-01-30 15:48:07 +0000332static PyTypeObject Mfsitype = {
333 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen3d185931995-08-07 14:04:10 +0000334 0, /*ob_size*/
Jack Jansena755e681997-09-20 17:40:22 +0000335 "FInfo", /*tp_name*/
Jack Jansen3d185931995-08-07 14:04:10 +0000336 sizeof(mfsiobject), /*tp_basicsize*/
337 0, /*tp_itemsize*/
338 /* methods */
339 (destructor)mfsi_dealloc, /*tp_dealloc*/
340 (printfunc)0, /*tp_print*/
341 (getattrfunc)mfsi_getattr, /*tp_getattr*/
342 (setattrfunc)mfsi_setattr, /*tp_setattr*/
343 (cmpfunc)0, /*tp_compare*/
344 (reprfunc)0, /*tp_repr*/
345 0, /*tp_as_number*/
346 0, /*tp_as_sequence*/
347 0, /*tp_as_mapping*/
348 (hashfunc)0, /*tp_hash*/
349};
350
351/* End of code for FInfo object objects */
352/* -------------------------------------------------------- */
353
354
Jack Jansen17ba43f1995-01-26 16:22:07 +0000355/*
Jack Jansen4e566ab2001-07-08 22:07:23 +0000356** Helper routines for the FSRef and FSSpec creators in macglue.c
357** They return an FSSpec/FSRef if the Python object encapsulating
358** either is passed. They return a boolean success indicator.
359** Note that they do not set an exception on failure, they're only
360** helper routines.
Jack Jansen17ba43f1995-01-26 16:22:07 +0000361*/
Jack Jansen4e566ab2001-07-08 22:07:23 +0000362static int
363_mfs_GetFSSpecFromFSSpec(PyObject *self, FSSpec *fssp)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000364{
Jack Jansen4e566ab2001-07-08 22:07:23 +0000365 if ( is_mfssobject(self) ) {
366 *fssp = ((mfssobject *)self)->fsspec;
367 return 1;
368 }
369 return 0;
370}
371
372/* Return an FSSpec if this is an FSref */
373static int
374_mfs_GetFSSpecFromFSRef(PyObject *self, FSSpec *fssp)
375{
Jack Jansencbed91b2001-08-03 13:31:36 +0000376#if !TARGET_API_MAC_OS8
Jack Jansen4e566ab2001-07-08 22:07:23 +0000377 static FSRef *fsrp;
378
379 if ( is_mfsrobject(self) ) {
380 fsrp = &((mfsrobject *)self)->fsref;
381 if ( FSGetCatalogInfo(&((mfsrobject *)self)->fsref, kFSCatInfoNone, NULL, NULL, fssp, NULL) == noErr )
382 return 1;
383 }
Jack Jansencbed91b2001-08-03 13:31:36 +0000384#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000385 return 0;
386}
387
388/* Return an FSRef if this is an FSRef */
389static int
390_mfs_GetFSRefFromFSRef(PyObject *self, FSRef *fsrp)
391{
Jack Jansencbed91b2001-08-03 13:31:36 +0000392#if !TARGET_API_MAC_OS8
Jack Jansen4e566ab2001-07-08 22:07:23 +0000393 if ( is_mfsrobject(self) ) {
394 *fsrp = ((mfsrobject *)self)->fsref;
395 return 1;
396 }
Jack Jansencbed91b2001-08-03 13:31:36 +0000397#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000398 return 0;
399}
400
401/* Return an FSRef if this is an FSSpec */
402static int
403_mfs_GetFSRefFromFSSpec(PyObject *self, FSRef *fsrp)
404{
Jack Jansencbed91b2001-08-03 13:31:36 +0000405#if !TARGET_API_MAC_OS8
Jack Jansen4e566ab2001-07-08 22:07:23 +0000406 if ( is_mfssobject(self) ) {
407 if ( FSpMakeFSRef(&((mfssobject *)self)->fsspec, fsrp) == noErr )
408 return 1;
409 }
Jack Jansencbed91b2001-08-03 13:31:36 +0000410#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000411 return 0;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000412}
413
Jack Jansen0bdf9791996-09-15 22:11:25 +0000414/*
415** Two generally useful routines
416*/
417static OSErr
Jack Jansendeefbe52001-08-08 13:46:49 +0000418PyMac_GetFileDates(FSSpec *fss, unsigned long *crdat, unsigned long *mddat,
419 unsigned long *bkdat)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000420{
421 CInfoPBRec pb;
422 OSErr error;
423
424 pb.dirInfo.ioNamePtr = fss->name;
425 pb.dirInfo.ioFDirIndex = 0;
426 pb.dirInfo.ioVRefNum = fss->vRefNum;
427 pb.dirInfo.ioDrDirID = fss->parID;
428 error = PBGetCatInfoSync(&pb);
429 if ( error ) return error;
430 *crdat = pb.hFileInfo.ioFlCrDat;
431 *mddat = pb.hFileInfo.ioFlMdDat;
432 *bkdat = pb.hFileInfo.ioFlBkDat;
433 return 0;
434}
435
436static OSErr
Jack Jansendeefbe52001-08-08 13:46:49 +0000437PyMac_SetFileDates(FSSpec *fss, unsigned long crdat, unsigned long mddat,
438 unsigned long bkdat)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000439{
440 CInfoPBRec pb;
441 OSErr error;
442
443 pb.dirInfo.ioNamePtr = fss->name;
444 pb.dirInfo.ioFDirIndex = 0;
445 pb.dirInfo.ioVRefNum = fss->vRefNum;
446 pb.dirInfo.ioDrDirID = fss->parID;
447 error = PBGetCatInfoSync(&pb);
448 if ( error ) return error;
449 pb.dirInfo.ioNamePtr = fss->name;
450 pb.dirInfo.ioFDirIndex = 0;
451 pb.dirInfo.ioVRefNum = fss->vRefNum;
452 pb.dirInfo.ioDrDirID = fss->parID;
453 pb.hFileInfo.ioFlCrDat = crdat;
454 pb.hFileInfo.ioFlMdDat = mddat;
455 pb.hFileInfo.ioFlBkDat = bkdat;
456 error = PBSetCatInfoSync(&pb);
457 return error;
458}
459
Jack Jansenf5c20571997-01-30 15:48:07 +0000460static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000461mfss_as_pathname(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000462{
Jack Jansen697842f2001-09-10 22:00:39 +0000463 char strbuf[PATHNAMELEN];
Jack Jansen17ba43f1995-01-26 16:22:07 +0000464 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000465
Jack Jansenf5c20571997-01-30 15:48:07 +0000466 if (!PyArg_ParseTuple(args, ""))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000467 return NULL;
Jack Jansen697842f2001-09-10 22:00:39 +0000468 err = PyMac_GetFullPathname(&self->fsspec, strbuf, PATHNAMELEN);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000469 if ( err ) {
470 PyErr_Mac(ErrorObject, err);
471 return NULL;
472 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000473 return PyString_FromString(strbuf);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000474}
475
Jack Jansenf5c20571997-01-30 15:48:07 +0000476static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000477mfss_as_tuple(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000478{
Jack Jansenf5c20571997-01-30 15:48:07 +0000479 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000480 return NULL;
481 return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
482 &self->fsspec.name[1], self->fsspec.name[0]);
483}
484
Jack Jansenf5c20571997-01-30 15:48:07 +0000485static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000486mfss_NewAlias(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000487{
488 FSSpec src, *srcp;
489 OSErr err;
490 AliasHandle alias;
491
492 src.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000493 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000494 return NULL;
495 if ( src.name[0] )
496 srcp = &src;
497 else
498 srcp = NULL;
499 err = NewAlias(srcp, &self->fsspec, &alias);
500 if ( err ) {
501 PyErr_Mac(ErrorObject, err);
502 return NULL;
503 }
504
Jack Jansenf5c20571997-01-30 15:48:07 +0000505 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000506}
507
Jack Jansenf5c20571997-01-30 15:48:07 +0000508static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000509mfss_NewAliasMinimal(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000510{
511 OSErr err;
512 AliasHandle alias;
513
Jack Jansenf5c20571997-01-30 15:48:07 +0000514 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000515 return NULL;
516 err = NewAliasMinimal(&self->fsspec, &alias);
517 if ( err ) {
518 PyErr_Mac(ErrorObject, err);
519 return NULL;
520 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000521 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000522}
523
Jack Jansen4e566ab2001-07-08 22:07:23 +0000524static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000525mfss_FSpMakeFSRef(mfssobject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000526{
Jack Jansencbed91b2001-08-03 13:31:36 +0000527#if TARGET_API_MAC_OS8
528 PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform");
529 return 0;
530#else
Jack Jansen4e566ab2001-07-08 22:07:23 +0000531 OSErr err;
532 FSRef fsref;
533
534 if (!PyArg_ParseTuple(args, ""))
535 return NULL;
536 err = FSpMakeFSRef(&self->fsspec, &fsref);
537 if ( err ) {
538 PyErr_Mac(ErrorObject, err);
539 return NULL;
540 }
541 return (PyObject *)newmfsrobject(&fsref);
Jack Jansencbed91b2001-08-03 13:31:36 +0000542#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000543}
544
Jack Jansen3d185931995-08-07 14:04:10 +0000545/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
Jack Jansenf5c20571997-01-30 15:48:07 +0000546static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000547mfss_GetCreatorType(mfssobject *self, PyObject *args)
Jack Jansen8828fcf1995-02-02 14:23:52 +0000548{
549 OSErr err;
550 FInfo info;
551
Jack Jansenf5c20571997-01-30 15:48:07 +0000552 if (!PyArg_ParseTuple(args, ""))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000553 return NULL;
554 err = FSpGetFInfo(&self->fsspec, &info);
555 if ( err ) {
556 PyErr_Mac(ErrorObject, err);
557 return NULL;
558 }
559 return Py_BuildValue("(O&O&)",
560 PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
561}
562
Jack Jansenf5c20571997-01-30 15:48:07 +0000563static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000564mfss_SetCreatorType(mfssobject *self, PyObject *args)
Jack Jansen8828fcf1995-02-02 14:23:52 +0000565{
566 OSErr err;
567 OSType creator, type;
568 FInfo info;
569
Jack Jansenf5c20571997-01-30 15:48:07 +0000570 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000571 return NULL;
572 err = FSpGetFInfo(&self->fsspec, &info);
573 if ( err ) {
574 PyErr_Mac(ErrorObject, err);
575 return NULL;
576 }
577 info.fdType = type;
578 info.fdCreator = creator;
579 err = FSpSetFInfo(&self->fsspec, &info);
580 if ( err ) {
581 PyErr_Mac(ErrorObject, err);
582 return NULL;
583 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000584 Py_INCREF(Py_None);
585 return Py_None;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000586}
587
Jack Jansenf5c20571997-01-30 15:48:07 +0000588static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000589mfss_GetFInfo(mfssobject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +0000590{
591 OSErr err;
592 mfsiobject *fip;
593
594
Jack Jansenf5c20571997-01-30 15:48:07 +0000595 if (!PyArg_ParseTuple(args, ""))
Jack Jansen3d185931995-08-07 14:04:10 +0000596 return NULL;
597 if ( (fip=newmfsiobject()) == NULL )
598 return NULL;
599 err = FSpGetFInfo(&self->fsspec, &fip->finfo);
600 if ( err ) {
601 PyErr_Mac(ErrorObject, err);
Jack Jansenf5c20571997-01-30 15:48:07 +0000602 Py_DECREF(fip);
Jack Jansen3d185931995-08-07 14:04:10 +0000603 return NULL;
604 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000605 return (PyObject *)fip;
Jack Jansen3d185931995-08-07 14:04:10 +0000606}
607
Jack Jansenf5c20571997-01-30 15:48:07 +0000608static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000609mfss_SetFInfo(mfssobject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +0000610{
611 OSErr err;
612 mfsiobject *fip;
613
Jack Jansenf5c20571997-01-30 15:48:07 +0000614 if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
Jack Jansen3d185931995-08-07 14:04:10 +0000615 return NULL;
616 err = FSpSetFInfo(&self->fsspec, &fip->finfo);
617 if ( err ) {
618 PyErr_Mac(ErrorObject, err);
619 return NULL;
620 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000621 Py_INCREF(Py_None);
622 return Py_None;
Jack Jansen3d185931995-08-07 14:04:10 +0000623}
624
Jack Jansenf5c20571997-01-30 15:48:07 +0000625static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000626mfss_GetDates(mfssobject *self, PyObject *args)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000627{
628 OSErr err;
629 unsigned long crdat, mddat, bkdat;
630
Jack Jansenf5c20571997-01-30 15:48:07 +0000631 if (!PyArg_ParseTuple(args, ""))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000632 return NULL;
633 err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
634 if ( err ) {
635 PyErr_Mac(ErrorObject, err);
636 return NULL;
637 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000638 return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
Jack Jansen0bdf9791996-09-15 22:11:25 +0000639}
640
Jack Jansenf5c20571997-01-30 15:48:07 +0000641static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000642mfss_SetDates(mfssobject *self, PyObject *args)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000643{
644 OSErr err;
645 double crdat, mddat, bkdat;
646
Jack Jansenf5c20571997-01-30 15:48:07 +0000647 if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000648 return NULL;
649 err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
650 (unsigned long)mddat, (unsigned long)bkdat);
651 if ( err ) {
652 PyErr_Mac(ErrorObject, err);
653 return NULL;
654 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000655 Py_INCREF(Py_None);
656 return Py_None;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000657}
658
Jack Jansenf5c20571997-01-30 15:48:07 +0000659static struct PyMethodDef mfss_methods[] = {
660 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
661 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
Jack Jansen4e566ab2001-07-08 22:07:23 +0000662 {"as_fsref", (PyCFunction)mfss_FSpMakeFSRef, 1},
663 {"FSpMakeFSRef", (PyCFunction)mfss_FSpMakeFSRef, 1},
Jack Jansenf5c20571997-01-30 15:48:07 +0000664 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
665 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
666 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
667 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
668 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
669 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
670 {"GetDates", (PyCFunction)mfss_GetDates, 1},
671 {"SetDates", (PyCFunction)mfss_SetDates, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000672
673 {NULL, NULL} /* sentinel */
674};
675
676/* ---------- */
677
Jack Jansenf5c20571997-01-30 15:48:07 +0000678static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000679mfss_getattr(mfssobject *self, char *name)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000680{
Jack Jansenc889b761995-02-13 12:00:46 +0000681 if ( strcmp(name, "data") == 0)
682 return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
Jack Jansenf5c20571997-01-30 15:48:07 +0000683 return Py_FindMethod(mfss_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000684}
685
686mfssobject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000687newmfssobject(FSSpec *fss)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000688{
689 mfssobject *self;
690
Jack Jansenf5c20571997-01-30 15:48:07 +0000691 self = PyObject_NEW(mfssobject, &Mfsstype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000692 if (self == NULL)
693 return NULL;
694 self->fsspec = *fss;
695 return self;
696}
697
698static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000699mfss_dealloc(mfssobject *self)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000700{
Jack Jansenf5c20571997-01-30 15:48:07 +0000701 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000702}
703
Jack Jansenf5c20571997-01-30 15:48:07 +0000704static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000705mfss_repr(mfssobject *self)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000706{
707 char buf[512];
708
Jack Jansen101de912001-12-05 23:27:58 +0000709 PyOS_snprintf(buf, sizeof(buf), "FSSpec((%d, %ld, '%.*s'))",
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000710 self->fsspec.vRefNum,
711 self->fsspec.parID,
712 self->fsspec.name[0], self->fsspec.name+1);
Jack Jansenf5c20571997-01-30 15:48:07 +0000713 return PyString_FromString(buf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000714}
715
716static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000717mfss_compare(mfssobject *v, mfssobject *w)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000718{
719 int minlen;
720 int res;
721
722 if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1;
723 if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1;
724 if ( v->fsspec.parID < w->fsspec.parID ) return -1;
725 if ( v->fsspec.parID > w->fsspec.parID ) return 1;
726 minlen = v->fsspec.name[0];
727 if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0];
728 res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen);
729 if ( res ) return res;
730 if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1;
731 if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1;
732 return res;
733}
734
Jack Jansenf5c20571997-01-30 15:48:07 +0000735statichere PyTypeObject Mfsstype = {
736 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000737 0, /*ob_size*/
738 "FSSpec", /*tp_name*/
739 sizeof(mfssobject), /*tp_basicsize*/
740 0, /*tp_itemsize*/
741 /* methods */
742 (destructor)mfss_dealloc, /*tp_dealloc*/
743 (printfunc)0, /*tp_print*/
744 (getattrfunc)mfss_getattr, /*tp_getattr*/
745 (setattrfunc)0, /*tp_setattr*/
746 (cmpfunc)mfss_compare, /*tp_compare*/
747 (reprfunc)mfss_repr, /*tp_repr*/
748 0, /*tp_as_number*/
749 0, /*tp_as_sequence*/
750 0, /*tp_as_mapping*/
751 (hashfunc)0, /*tp_hash*/
752};
753
754/* End of code for FSSpec objects */
755/* -------------------------------------------------------- */
Jack Jansencbed91b2001-08-03 13:31:36 +0000756#if !TARGET_API_MAC_OS8
Jack Jansenf5c20571997-01-30 15:48:07 +0000757static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000758mfsr_as_fsspec(mfsrobject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000759{
760 OSErr err;
761 FSSpec fss;
762
763 if (!PyArg_ParseTuple(args, ""))
764 return NULL;
765 err = FSGetCatalogInfo(&self->fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL);
766 if ( err ) {
767 PyErr_Mac(ErrorObject, err);
768 return NULL;
769 }
770 Py_INCREF(Py_None);
771 return (PyObject *)newmfssobject(&fss);
772}
773
774static struct PyMethodDef mfsr_methods[] = {
775 {"as_fsspec", (PyCFunction)mfsr_as_fsspec, 1},
776#if 0
777 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
778 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
779 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
780 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
781 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
782 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
783 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
784 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
785 {"GetDates", (PyCFunction)mfss_GetDates, 1},
786 {"SetDates", (PyCFunction)mfss_SetDates, 1},
787#endif
788
789 {NULL, NULL} /* sentinel */
790};
791
792/* ---------- */
793
794static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000795mfsr_getattr(mfsrobject *self, char *name)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000796{
797 if ( strcmp(name, "data") == 0)
798 return PyString_FromStringAndSize((char *)&self->fsref, sizeof(FSRef));
799 return Py_FindMethod(mfsr_methods, (PyObject *)self, name);
800}
801
802mfsrobject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000803newmfsrobject(FSRef *fsr)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000804{
805 mfsrobject *self;
806
807 self = PyObject_NEW(mfsrobject, &Mfsrtype);
808 if (self == NULL)
809 return NULL;
810 self->fsref = *fsr;
811 return self;
812}
813
814static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000815mfsr_compare(mfsrobject *v, mfsrobject *w)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000816{
817 OSErr err;
818
819 if ( v == w ) return 0;
820 err = FSCompareFSRefs(&v->fsref, &w->fsref);
821 if ( err == 0 )
822 return 0;
823 if (v < w )
824 return -1;
825 return 1;
826}
827
828static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000829mfsr_dealloc(mfsrobject *self)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000830{
831 PyMem_DEL(self);
832}
833
834statichere PyTypeObject Mfsrtype = {
835 PyObject_HEAD_INIT(&PyType_Type)
836 0, /*ob_size*/
837 "FSRef", /*tp_name*/
838 sizeof(mfsrobject), /*tp_basicsize*/
839 0, /*tp_itemsize*/
840 /* methods */
841 (destructor)mfsr_dealloc, /*tp_dealloc*/
842 (printfunc)0, /*tp_print*/
843 (getattrfunc)mfsr_getattr, /*tp_getattr*/
844 (setattrfunc)0, /*tp_setattr*/
845 (cmpfunc)mfsr_compare, /*tp_compare*/
846 (reprfunc)0, /*tp_repr*/
847 0, /*tp_as_number*/
848 0, /*tp_as_sequence*/
849 0, /*tp_as_mapping*/
850 (hashfunc)0, /*tp_hash*/
851};
852
853/* End of code for FSRef objects */
Jack Jansencbed91b2001-08-03 13:31:36 +0000854#endif /* !TARGET_API_MAC_OS8 */
Jack Jansen4e566ab2001-07-08 22:07:23 +0000855/* -------------------------------------------------------- */
856
857static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000858mfs_ResolveAliasFile(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000859{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000860 FSSpec fss;
861 Boolean chain = 1, isfolder, wasaliased;
862 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000863
Jack Jansenf5c20571997-01-30 15:48:07 +0000864 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000865 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000866 err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
867 if ( err ) {
868 PyErr_Mac(ErrorObject, err);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000869 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000870 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000871 return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000872}
873
Jack Jansen74a1e632000-07-14 22:37:27 +0000874#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000875static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000876mfs_StandardGetFile(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000877{
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000878 SFTypeList list;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000879 short numtypes;
880 StandardFileReply reply;
881
882 list[0] = list[1] = list[2] = list[3] = 0;
883 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000884 if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
Jack Jansen17ba43f1995-01-26 16:22:07 +0000885 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
886 PyMac_GetOSType, &list[3]) )
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000887 return NULL;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000888 while ( numtypes < 4 && list[numtypes] ) {
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000889 numtypes++;
890 }
Jack Jansenc2632861995-06-03 21:15:50 +0000891 if ( numtypes == 0 )
892 numtypes = -1;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000893 StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000894 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000895}
896
Jack Jansenf5c20571997-01-30 15:48:07 +0000897static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000898mfs_PromptGetFile(PyObject *self, PyObject *args)
Jack Jansend5d5f461995-08-14 12:22:56 +0000899{
900 SFTypeList list;
901 short numtypes;
902 StandardFileReply reply;
903 char *prompt = NULL;
904
905 list[0] = list[1] = list[2] = list[3] = 0;
906 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000907 if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
Jack Jansend5d5f461995-08-14 12:22:56 +0000908 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
909 PyMac_GetOSType, &list[3]) )
910 return NULL;
911 while ( numtypes < 4 && list[numtypes] ) {
912 numtypes++;
913 }
914 if ( numtypes == 0 )
915 numtypes = -1;
916 PyMac_PromptGetFile(numtypes, list, &reply, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000917 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansend5d5f461995-08-14 12:22:56 +0000918}
919
Jack Jansenf5c20571997-01-30 15:48:07 +0000920static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000921mfs_StandardPutFile(PyObject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000922{
923 Str255 prompt, dft;
924 StandardFileReply reply;
925
926 dft[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000927 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
Jack Jansen17ba43f1995-01-26 16:22:07 +0000928 return NULL;
929 StandardPutFile(prompt, dft, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000930 return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000931}
932
Jack Jansend99d2831996-07-22 15:26:01 +0000933/*
934** Set initial directory for file dialogs */
Jack Jansenf5c20571997-01-30 15:48:07 +0000935static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000936mfs_SetFolder(PyObject *self, PyObject *args)
Jack Jansend99d2831996-07-22 15:26:01 +0000937{
938 FSSpec spec;
939 FSSpec ospec;
940 short orefnum;
941 long oparid;
942
943 /* Get old values */
944 orefnum = -LMGetSFSaveDisk();
945 oparid = LMGetCurDirStore();
946 (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec);
947
948 /* Go to working directory by default */
949 (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
Jack Jansenf5c20571997-01-30 15:48:07 +0000950 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
Jack Jansend99d2831996-07-22 15:26:01 +0000951 return NULL;
952 /* Set standard-file working directory */
953 LMSetSFSaveDisk(-spec.vRefNum);
954 LMSetCurDirStore(spec.parID);
Jack Jansenf5c20571997-01-30 15:48:07 +0000955 return (PyObject *)newmfssobject(&ospec);
Jack Jansend99d2831996-07-22 15:26:01 +0000956}
Jack Jansene79dc762000-06-02 21:35:07 +0000957#endif
Jack Jansend99d2831996-07-22 15:26:01 +0000958
Jack Jansenf5c20571997-01-30 15:48:07 +0000959static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000960mfs_FSSpec(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000961{
962 FSSpec fss;
963
Jack Jansenf5c20571997-01-30 15:48:07 +0000964 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000965 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000966 return (PyObject *)newmfssobject(&fss);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000967}
968
Jack Jansenf5c20571997-01-30 15:48:07 +0000969static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000970mfs_FSRef(PyObject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000971{
Jack Jansencbed91b2001-08-03 13:31:36 +0000972#if TARGET_API_MAC_OS8
973 PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform");
974 return 0;
975#else
Jack Jansen4e566ab2001-07-08 22:07:23 +0000976 FSRef fsr;
977
978 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &fsr))
979 return NULL;
980 return (PyObject *)newmfsrobject(&fsr);
Jack Jansencbed91b2001-08-03 13:31:36 +0000981#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000982}
983
984static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000985mfs_RawFSSpec(PyObject *self, PyObject *args)
Jack Jansenc889b761995-02-13 12:00:46 +0000986{
987 FSSpec *fssp;
988 int size;
989
Jack Janseneeccca91997-05-07 15:46:31 +0000990 if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000991 return NULL;
992 if ( size != sizeof(FSSpec) ) {
993 PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
994 return NULL;
995 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000996 return (PyObject *)newmfssobject(fssp);
Jack Jansenc889b761995-02-13 12:00:46 +0000997}
998
Jack Jansenf5c20571997-01-30 15:48:07 +0000999static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001000mfs_RawAlias(PyObject *self, PyObject *args)
Jack Jansenc889b761995-02-13 12:00:46 +00001001{
1002 char *dataptr;
1003 Handle h;
1004 int size;
1005
Jack Janseneeccca91997-05-07 15:46:31 +00001006 if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
Jack Jansenc889b761995-02-13 12:00:46 +00001007 return NULL;
1008 h = NewHandle(size);
1009 if ( h == NULL ) {
1010 PyErr_NoMemory();
1011 return NULL;
1012 }
1013 HLock(h);
1014 memcpy((char *)*h, dataptr, size);
1015 HUnlock(h);
Jack Jansenf5c20571997-01-30 15:48:07 +00001016 return (PyObject *)newmfsaobject((AliasHandle)h);
Jack Jansenc889b761995-02-13 12:00:46 +00001017}
1018
Jack Jansen74a1e632000-07-14 22:37:27 +00001019#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +00001020static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001021mfs_GetDirectory(PyObject *self, PyObject *args)
Jack Jansen81f51c71995-02-20 15:45:25 +00001022{
1023 FSSpec fsdir;
1024 int ok;
Jack Jansend5d5f461995-08-14 12:22:56 +00001025 char *prompt = NULL;
Jack Jansen81f51c71995-02-20 15:45:25 +00001026
Jack Jansenf5c20571997-01-30 15:48:07 +00001027 if (!PyArg_ParseTuple(args, "|s", &prompt) )
Jack Jansen81f51c71995-02-20 15:45:25 +00001028 return NULL;
1029
Jack Jansend5d5f461995-08-14 12:22:56 +00001030 ok = PyMac_GetDirectory(&fsdir, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +00001031 return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
Jack Jansen81f51c71995-02-20 15:45:25 +00001032}
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001033#endif
Jack Jansen81f51c71995-02-20 15:45:25 +00001034
Jack Jansenf5c20571997-01-30 15:48:07 +00001035static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001036mfs_FindFolder(PyObject *self, PyObject *args)
Jack Jansen2c673621995-06-18 20:05:14 +00001037{
1038 OSErr err;
1039 short where;
1040 OSType which;
1041 int create;
1042 short refnum;
1043 long dirid;
1044
Jack Jansenabd703d2001-03-15 14:38:10 +00001045 if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
Jack Jansen2c673621995-06-18 20:05:14 +00001046 return NULL;
1047 err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
1048 if ( err ) {
1049 PyErr_Mac(ErrorObject, err);
1050 return NULL;
1051 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001052 return Py_BuildValue("(ii)", refnum, dirid);
Jack Jansen2c673621995-06-18 20:05:14 +00001053}
1054
Jack Jansenf5c20571997-01-30 15:48:07 +00001055static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001056mfs_FindApplication(PyObject *self, PyObject *args)
Jack Jansen924ca851996-09-20 15:25:16 +00001057{
1058 OSErr err;
1059 OSType which;
1060 FSSpec fss;
1061
Jack Jansenf5c20571997-01-30 15:48:07 +00001062 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
Jack Jansen924ca851996-09-20 15:25:16 +00001063 return NULL;
1064 err = FindApplicationFromCreator(which, &fss);
1065 if ( err ) {
1066 PyErr_Mac(ErrorObject, err);
1067 return NULL;
1068 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001069 return (PyObject *)newmfssobject(&fss);
Jack Jansen924ca851996-09-20 15:25:16 +00001070}
1071
Jack Jansenf5c20571997-01-30 15:48:07 +00001072static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001073mfs_FInfo(PyObject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +00001074{
Jack Jansenf5c20571997-01-30 15:48:07 +00001075 return (PyObject *)newmfsiobject();
Jack Jansen3d185931995-08-07 14:04:10 +00001076}
1077
Jack Jansend9936481997-06-16 14:31:38 +00001078static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001079mfs_NewAliasMinimalFromFullPath(PyObject *self, PyObject *args)
Jack Jansend9936481997-06-16 14:31:38 +00001080{
1081 OSErr err;
1082 char *fullpath;
1083 int fullpathlen;
1084 AliasHandle alias;
1085 Str32 zonename;
1086 Str31 servername;
1087
1088 if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) )
1089 return NULL;
1090 zonename[0] = 0;
1091 servername[0] = 0;
1092 err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,
1093 servername, &alias);
1094 if ( err ) {
1095 PyErr_Mac(ErrorObject, err);
1096 return NULL;
1097 }
1098 return (PyObject *)newmfsaobject(alias);
1099}
1100
1101
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001102/* List of methods defined in the module */
1103
Jack Jansenf5c20571997-01-30 15:48:07 +00001104static struct PyMethodDef mfs_methods[] = {
Jack Jansen17ba43f1995-01-26 16:22:07 +00001105 {"ResolveAliasFile", mfs_ResolveAliasFile, 1},
Jack Jansen74a1e632000-07-14 22:37:27 +00001106#if !TARGET_API_MAC_CARBON
Jack Jansen17ba43f1995-01-26 16:22:07 +00001107 {"StandardGetFile", mfs_StandardGetFile, 1},
Jack Jansend5d5f461995-08-14 12:22:56 +00001108 {"PromptGetFile", mfs_PromptGetFile, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +00001109 {"StandardPutFile", mfs_StandardPutFile, 1},
Jack Jansen81f51c71995-02-20 15:45:25 +00001110 {"GetDirectory", mfs_GetDirectory, 1},
Jack Jansend99d2831996-07-22 15:26:01 +00001111 {"SetFolder", mfs_SetFolder, 1},
Jack Jansene79dc762000-06-02 21:35:07 +00001112#endif
Jack Jansen17ba43f1995-01-26 16:22:07 +00001113 {"FSSpec", mfs_FSSpec, 1},
Jack Jansen4e566ab2001-07-08 22:07:23 +00001114 {"FSRef", mfs_FSRef, 1},
Jack Jansenc889b761995-02-13 12:00:46 +00001115 {"RawFSSpec", mfs_RawFSSpec, 1},
1116 {"RawAlias", mfs_RawAlias, 1},
Jack Jansen2c673621995-06-18 20:05:14 +00001117 {"FindFolder", mfs_FindFolder, 1},
Jack Jansen924ca851996-09-20 15:25:16 +00001118 {"FindApplication", mfs_FindApplication, 1},
Jack Jansen3d185931995-08-07 14:04:10 +00001119 {"FInfo", mfs_FInfo, 1},
Jack Jansend9936481997-06-16 14:31:38 +00001120 {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1},
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001121
1122 {NULL, NULL} /* sentinel */
1123};
1124
Jack Jansen4e566ab2001-07-08 22:07:23 +00001125/*
1126** Convert a Python object to an FSSpec.
1127** The object may either be a full pathname, an FSSpec, an FSRef or a triple
1128** (vrefnum, dirid, path).
1129*/
1130int
1131PyMac_GetFSRef(PyObject *v, FSRef *fsr)
1132{
Jack Jansencbed91b2001-08-03 13:31:36 +00001133#if TARGET_API_MAC_OS8
Jack Jansen2bf52da2001-11-06 15:57:26 +00001134 PyErr_SetString(PyExc_TypeError, "FSRef objects not supported on this platform");
Jack Jansencbed91b2001-08-03 13:31:36 +00001135 return 0;
1136#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001137 /* If it's an FSRef we're also okay. */
1138 if (_mfs_GetFSRefFromFSRef(v, fsr))
1139 return 1;
1140 /* first check whether it already is an FSSpec */
1141 if ( _mfs_GetFSRefFromFSSpec(v, fsr) )
1142 return 1;
1143 if ( PyString_Check(v) ) {
Jack Jansena5bca572001-08-03 15:39:27 +00001144#if TARGET_API_MAC_OSX
1145 OSStatus err;
1146 if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
1147 PyErr_Mac(ErrorObject, err);
1148 return 0;
1149 }
1150 return 1;
1151#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001152 PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform");
1153 return 0;
Jack Jansena5bca572001-08-03 15:39:27 +00001154#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001155 }
1156 PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname");
1157 return 0;
Jack Jansencbed91b2001-08-03 13:31:36 +00001158#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001159}
1160
1161/* Convert FSSpec to PyObject */
1162PyObject *PyMac_BuildFSRef(FSRef *v)
1163{
Jack Jansencbed91b2001-08-03 13:31:36 +00001164#if TARGET_API_MAC_OS8
1165 return NULL;
1166#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001167 return (PyObject *)newmfsrobject(v);
Jack Jansencbed91b2001-08-03 13:31:36 +00001168#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001169}
1170
1171/*
1172** Convert a Python object to an FSRef.
1173** The object may either be a full pathname (OSX only), an FSSpec or an FSRef.
1174*/
1175int
1176PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
1177{
1178 Str255 path;
1179 short refnum;
1180 long parid;
1181 OSErr err;
1182
1183 /* first check whether it already is an FSSpec */
1184 if ( _mfs_GetFSSpecFromFSSpec(v, fs) )
1185 return 1;
1186 /* If it's an FSRef we're also okay. */
1187 if (_mfs_GetFSSpecFromFSRef(v, fs))
1188 return 1;
1189 if ( PyString_Check(v) ) {
1190 /* It's a pathname */
1191 if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
1192 return 0;
1193 refnum = 0; /* XXXX Should get CurWD here?? */
1194 parid = 0;
1195 } else {
1196 if( !PyArg_Parse(v, "(hlO&); FSSpec should be FSSpec, FSRef, fullpath or (vrefnum,dirid,path)",
1197 &refnum, &parid, PyMac_GetStr255, &path)) {
1198 return 0;
1199 }
1200 }
1201 err = FSMakeFSSpec(refnum, parid, path, fs);
1202 if ( err && err != fnfErr ) {
1203 PyMac_Error(err);
1204 return 0;
1205 }
1206 return 1;
1207}
1208
1209/* Convert FSSpec to PyObject */
1210PyObject *PyMac_BuildFSSpec(FSSpec *v)
1211{
1212 return (PyObject *)newmfssobject(v);
1213}
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001214
Just van Rossumab57c7d2001-10-31 22:55:08 +00001215
1216/*
1217** Import the macfsn module, which will override the Standard File
1218** calls in the macfs builtin module by Navigation Services versions,
1219** if available on this machine.
1220*/
1221static void
1222PyMac_InstallNavServicesForSF(void)
1223{
Jack Jansen01a94622001-11-01 14:00:19 +00001224#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +00001225 if ( !PyMac_options.nonavservice ) {
Jack Jansen01a94622001-11-01 14:00:19 +00001226#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +00001227 PyObject *m = PyImport_ImportModule("macfsn");
1228
1229 if ( m == NULL ) {
1230 PySys_WriteStderr("'import macfsn' failed; ");
1231 if (Py_VerboseFlag) {
1232 PySys_WriteStderr("traceback:\n");
1233 PyErr_Print();
1234 }
1235 else {
1236 PySys_WriteStderr("use -v for traceback\n");
1237 }
1238 PyErr_Clear();
1239 }
Jack Jansen01a94622001-11-01 14:00:19 +00001240#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +00001241 }
Jack Jansen01a94622001-11-01 14:00:19 +00001242#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +00001243}
1244
1245
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001246/* Initialization function for the module (*must* be called initmacfs) */
1247
1248void
Jack Jansendeefbe52001-08-08 13:46:49 +00001249initmacfs(void)
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001250{
Jack Jansenf5c20571997-01-30 15:48:07 +00001251 PyObject *m, *d;
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001252
Jack Jansen45900492001-08-06 15:32:30 +00001253 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
Jack Jansenfabd00f2001-09-01 23:39:58 +00001254 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
1255 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
1256 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
Jack Jansena5bca572001-08-03 15:39:27 +00001257
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001258 /* Create the module and add the functions */
Jack Jansenf5c20571997-01-30 15:48:07 +00001259 m = Py_InitModule("macfs", mfs_methods);
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001260
1261 /* Add some symbolic constants to the module */
Jack Jansenf5c20571997-01-30 15:48:07 +00001262 d = PyModule_GetDict(m);
Jack Jansen4377a1a2000-01-24 10:37:59 +00001263 ErrorObject = PyMac_GetOSErrException();
Jack Jansenf5c20571997-01-30 15:48:07 +00001264 PyDict_SetItemString(d, "error", ErrorObject);
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001265
Jack Jansena755e681997-09-20 17:40:22 +00001266 Mfsatype.ob_type = &PyType_Type;
1267 Py_INCREF(&Mfsatype);
1268 PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype);
1269 Mfsstype.ob_type = &PyType_Type;
1270 Py_INCREF(&Mfsstype);
1271 PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype);
1272 Mfsitype.ob_type = &PyType_Type;
1273 Py_INCREF(&Mfsitype);
1274 PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
Just van Rossumab57c7d2001-10-31 22:55:08 +00001275
1276 PyMac_InstallNavServicesForSF();
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001277}