blob: a251811a3a986f5624cfb8047387fd018b95c42d [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 Jansen0e2f7982002-05-22 14:31:48 +0000230 PyObject_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*/
Guido van Rossum14648392001-12-08 18:02:58 +0000236 "macfs.Alias", /*tp_name*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000237 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 Jansen0e2f7982002-05-22 14:31:48 +0000279 PyObject_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);
Just van Rossum14666cc2001-12-11 14:04:12 +0000295 else if ( strcmp(name, "__members__") == 0 )
296 return Py_BuildValue("[sssss]", "Type", "Creator", "Flags", "Location", "Fldr");
Jack Jansen3d185931995-08-07 14:04:10 +0000297 else
Jack Jansenf5c20571997-01-30 15:48:07 +0000298 return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
Jack Jansen3d185931995-08-07 14:04:10 +0000299}
300
301
302static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000303mfsi_setattr(mfsiobject *self, char *name, PyObject *v)
Jack Jansen3d185931995-08-07 14:04:10 +0000304{
305 int rv;
306 int i;
307
308 if ( v == NULL ) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000309 PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000310 return -1;
311 }
312 if ( strcmp(name, "Type") == 0 )
313 rv = PyMac_GetOSType(v, &self->finfo.fdType);
314 else if ( strcmp(name, "Creator") == 0 )
315 rv = PyMac_GetOSType(v, &self->finfo.fdCreator);
316 else if ( strcmp(name, "Flags") == 0 ) {
317 rv = PyArg_Parse(v, "i", &i);
318 self->finfo.fdFlags = (short)i;
319 } else if ( strcmp(name, "Location") == 0 )
320 rv = PyMac_GetPoint(v, &self->finfo.fdLocation);
321 else if ( strcmp(name, "Fldr") == 0 ) {
322 rv = PyArg_Parse(v, "i", &i);
323 self->finfo.fdFldr = (short)i;
324 } else {
Jack Jansenf5c20571997-01-30 15:48:07 +0000325 PyErr_SetString(PyExc_AttributeError, "No such attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000326 return -1;
327 }
328 if (rv)
329 return 0;
330 return -1;
331}
332
333
Jack Jansenf5c20571997-01-30 15:48:07 +0000334static PyTypeObject Mfsitype = {
335 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen3d185931995-08-07 14:04:10 +0000336 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000337 "macfs.FInfo", /*tp_name*/
Jack Jansen3d185931995-08-07 14:04:10 +0000338 sizeof(mfsiobject), /*tp_basicsize*/
339 0, /*tp_itemsize*/
340 /* methods */
341 (destructor)mfsi_dealloc, /*tp_dealloc*/
342 (printfunc)0, /*tp_print*/
343 (getattrfunc)mfsi_getattr, /*tp_getattr*/
344 (setattrfunc)mfsi_setattr, /*tp_setattr*/
345 (cmpfunc)0, /*tp_compare*/
346 (reprfunc)0, /*tp_repr*/
347 0, /*tp_as_number*/
348 0, /*tp_as_sequence*/
349 0, /*tp_as_mapping*/
350 (hashfunc)0, /*tp_hash*/
351};
352
353/* End of code for FInfo object objects */
354/* -------------------------------------------------------- */
355
356
Jack Jansen17ba43f1995-01-26 16:22:07 +0000357/*
Jack Jansen4e566ab2001-07-08 22:07:23 +0000358** Helper routines for the FSRef and FSSpec creators in macglue.c
359** They return an FSSpec/FSRef if the Python object encapsulating
360** either is passed. They return a boolean success indicator.
361** Note that they do not set an exception on failure, they're only
362** helper routines.
Jack Jansen17ba43f1995-01-26 16:22:07 +0000363*/
Jack Jansen4e566ab2001-07-08 22:07:23 +0000364static int
365_mfs_GetFSSpecFromFSSpec(PyObject *self, FSSpec *fssp)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000366{
Jack Jansen4e566ab2001-07-08 22:07:23 +0000367 if ( is_mfssobject(self) ) {
368 *fssp = ((mfssobject *)self)->fsspec;
369 return 1;
370 }
371 return 0;
372}
373
374/* Return an FSSpec if this is an FSref */
375static int
376_mfs_GetFSSpecFromFSRef(PyObject *self, FSSpec *fssp)
377{
Jack Jansencbed91b2001-08-03 13:31:36 +0000378#if !TARGET_API_MAC_OS8
Jack Jansen4e566ab2001-07-08 22:07:23 +0000379 static FSRef *fsrp;
380
381 if ( is_mfsrobject(self) ) {
382 fsrp = &((mfsrobject *)self)->fsref;
383 if ( FSGetCatalogInfo(&((mfsrobject *)self)->fsref, kFSCatInfoNone, NULL, NULL, fssp, NULL) == noErr )
384 return 1;
385 }
Jack Jansencbed91b2001-08-03 13:31:36 +0000386#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000387 return 0;
388}
389
390/* Return an FSRef if this is an FSRef */
391static int
392_mfs_GetFSRefFromFSRef(PyObject *self, FSRef *fsrp)
393{
Jack Jansencbed91b2001-08-03 13:31:36 +0000394#if !TARGET_API_MAC_OS8
Jack Jansen4e566ab2001-07-08 22:07:23 +0000395 if ( is_mfsrobject(self) ) {
396 *fsrp = ((mfsrobject *)self)->fsref;
397 return 1;
398 }
Jack Jansencbed91b2001-08-03 13:31:36 +0000399#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000400 return 0;
401}
402
403/* Return an FSRef if this is an FSSpec */
404static int
405_mfs_GetFSRefFromFSSpec(PyObject *self, FSRef *fsrp)
406{
Jack Jansencbed91b2001-08-03 13:31:36 +0000407#if !TARGET_API_MAC_OS8
Jack Jansen4e566ab2001-07-08 22:07:23 +0000408 if ( is_mfssobject(self) ) {
409 if ( FSpMakeFSRef(&((mfssobject *)self)->fsspec, fsrp) == noErr )
410 return 1;
411 }
Jack Jansencbed91b2001-08-03 13:31:36 +0000412#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000413 return 0;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000414}
415
Jack Jansen0bdf9791996-09-15 22:11:25 +0000416/*
417** Two generally useful routines
418*/
419static OSErr
Jack Jansendeefbe52001-08-08 13:46:49 +0000420PyMac_GetFileDates(FSSpec *fss, unsigned long *crdat, unsigned long *mddat,
421 unsigned long *bkdat)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000422{
423 CInfoPBRec pb;
424 OSErr error;
425
426 pb.dirInfo.ioNamePtr = fss->name;
427 pb.dirInfo.ioFDirIndex = 0;
428 pb.dirInfo.ioVRefNum = fss->vRefNum;
429 pb.dirInfo.ioDrDirID = fss->parID;
430 error = PBGetCatInfoSync(&pb);
431 if ( error ) return error;
432 *crdat = pb.hFileInfo.ioFlCrDat;
433 *mddat = pb.hFileInfo.ioFlMdDat;
434 *bkdat = pb.hFileInfo.ioFlBkDat;
435 return 0;
436}
437
438static OSErr
Jack Jansendeefbe52001-08-08 13:46:49 +0000439PyMac_SetFileDates(FSSpec *fss, unsigned long crdat, unsigned long mddat,
440 unsigned long bkdat)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000441{
442 CInfoPBRec pb;
443 OSErr error;
444
445 pb.dirInfo.ioNamePtr = fss->name;
446 pb.dirInfo.ioFDirIndex = 0;
447 pb.dirInfo.ioVRefNum = fss->vRefNum;
448 pb.dirInfo.ioDrDirID = fss->parID;
449 error = PBGetCatInfoSync(&pb);
450 if ( error ) return error;
451 pb.dirInfo.ioNamePtr = fss->name;
452 pb.dirInfo.ioFDirIndex = 0;
453 pb.dirInfo.ioVRefNum = fss->vRefNum;
454 pb.dirInfo.ioDrDirID = fss->parID;
455 pb.hFileInfo.ioFlCrDat = crdat;
456 pb.hFileInfo.ioFlMdDat = mddat;
457 pb.hFileInfo.ioFlBkDat = bkdat;
458 error = PBSetCatInfoSync(&pb);
459 return error;
460}
461
Jack Jansenf5c20571997-01-30 15:48:07 +0000462static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000463mfss_as_pathname(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000464{
Jack Jansen697842f2001-09-10 22:00:39 +0000465 char strbuf[PATHNAMELEN];
Jack Jansen17ba43f1995-01-26 16:22:07 +0000466 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000467
Jack Jansenf5c20571997-01-30 15:48:07 +0000468 if (!PyArg_ParseTuple(args, ""))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000469 return NULL;
Jack Jansen697842f2001-09-10 22:00:39 +0000470 err = PyMac_GetFullPathname(&self->fsspec, strbuf, PATHNAMELEN);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000471 if ( err ) {
472 PyErr_Mac(ErrorObject, err);
473 return NULL;
474 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000475 return PyString_FromString(strbuf);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000476}
477
Jack Jansenf5c20571997-01-30 15:48:07 +0000478static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000479mfss_as_tuple(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000480{
Jack Jansenf5c20571997-01-30 15:48:07 +0000481 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000482 return NULL;
483 return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
484 &self->fsspec.name[1], self->fsspec.name[0]);
485}
486
Jack Jansenf5c20571997-01-30 15:48:07 +0000487static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000488mfss_NewAlias(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000489{
490 FSSpec src, *srcp;
491 OSErr err;
492 AliasHandle alias;
493
494 src.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000495 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000496 return NULL;
497 if ( src.name[0] )
498 srcp = &src;
499 else
500 srcp = NULL;
501 err = NewAlias(srcp, &self->fsspec, &alias);
502 if ( err ) {
503 PyErr_Mac(ErrorObject, err);
504 return NULL;
505 }
506
Jack Jansenf5c20571997-01-30 15:48:07 +0000507 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000508}
509
Jack Jansenf5c20571997-01-30 15:48:07 +0000510static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000511mfss_NewAliasMinimal(mfssobject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000512{
513 OSErr err;
514 AliasHandle alias;
515
Jack Jansenf5c20571997-01-30 15:48:07 +0000516 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000517 return NULL;
518 err = NewAliasMinimal(&self->fsspec, &alias);
519 if ( err ) {
520 PyErr_Mac(ErrorObject, err);
521 return NULL;
522 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000523 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000524}
525
Jack Jansen4e566ab2001-07-08 22:07:23 +0000526static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000527mfss_FSpMakeFSRef(mfssobject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000528{
Jack Jansencbed91b2001-08-03 13:31:36 +0000529#if TARGET_API_MAC_OS8
530 PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform");
531 return 0;
532#else
Jack Jansen4e566ab2001-07-08 22:07:23 +0000533 OSErr err;
534 FSRef fsref;
535
536 if (!PyArg_ParseTuple(args, ""))
537 return NULL;
538 err = FSpMakeFSRef(&self->fsspec, &fsref);
539 if ( err ) {
540 PyErr_Mac(ErrorObject, err);
541 return NULL;
542 }
543 return (PyObject *)newmfsrobject(&fsref);
Jack Jansencbed91b2001-08-03 13:31:36 +0000544#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000545}
546
Jack Jansen3d185931995-08-07 14:04:10 +0000547/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
Jack Jansenf5c20571997-01-30 15:48:07 +0000548static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000549mfss_GetCreatorType(mfssobject *self, PyObject *args)
Jack Jansen8828fcf1995-02-02 14:23:52 +0000550{
551 OSErr err;
552 FInfo info;
553
Jack Jansenf5c20571997-01-30 15:48:07 +0000554 if (!PyArg_ParseTuple(args, ""))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000555 return NULL;
556 err = FSpGetFInfo(&self->fsspec, &info);
557 if ( err ) {
558 PyErr_Mac(ErrorObject, err);
559 return NULL;
560 }
561 return Py_BuildValue("(O&O&)",
562 PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
563}
564
Jack Jansenf5c20571997-01-30 15:48:07 +0000565static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000566mfss_SetCreatorType(mfssobject *self, PyObject *args)
Jack Jansen8828fcf1995-02-02 14:23:52 +0000567{
568 OSErr err;
569 OSType creator, type;
570 FInfo info;
571
Jack Jansenf5c20571997-01-30 15:48:07 +0000572 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000573 return NULL;
574 err = FSpGetFInfo(&self->fsspec, &info);
575 if ( err ) {
576 PyErr_Mac(ErrorObject, err);
577 return NULL;
578 }
579 info.fdType = type;
580 info.fdCreator = creator;
581 err = FSpSetFInfo(&self->fsspec, &info);
582 if ( err ) {
583 PyErr_Mac(ErrorObject, err);
584 return NULL;
585 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000586 Py_INCREF(Py_None);
587 return Py_None;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000588}
589
Jack Jansenf5c20571997-01-30 15:48:07 +0000590static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000591mfss_GetFInfo(mfssobject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +0000592{
593 OSErr err;
594 mfsiobject *fip;
595
596
Jack Jansenf5c20571997-01-30 15:48:07 +0000597 if (!PyArg_ParseTuple(args, ""))
Jack Jansen3d185931995-08-07 14:04:10 +0000598 return NULL;
599 if ( (fip=newmfsiobject()) == NULL )
600 return NULL;
601 err = FSpGetFInfo(&self->fsspec, &fip->finfo);
602 if ( err ) {
603 PyErr_Mac(ErrorObject, err);
Jack Jansenf5c20571997-01-30 15:48:07 +0000604 Py_DECREF(fip);
Jack Jansen3d185931995-08-07 14:04:10 +0000605 return NULL;
606 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000607 return (PyObject *)fip;
Jack Jansen3d185931995-08-07 14:04:10 +0000608}
609
Jack Jansenf5c20571997-01-30 15:48:07 +0000610static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000611mfss_SetFInfo(mfssobject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +0000612{
613 OSErr err;
614 mfsiobject *fip;
615
Jack Jansenf5c20571997-01-30 15:48:07 +0000616 if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
Jack Jansen3d185931995-08-07 14:04:10 +0000617 return NULL;
618 err = FSpSetFInfo(&self->fsspec, &fip->finfo);
619 if ( err ) {
620 PyErr_Mac(ErrorObject, err);
621 return NULL;
622 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000623 Py_INCREF(Py_None);
624 return Py_None;
Jack Jansen3d185931995-08-07 14:04:10 +0000625}
626
Jack Jansenf5c20571997-01-30 15:48:07 +0000627static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000628mfss_GetDates(mfssobject *self, PyObject *args)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000629{
630 OSErr err;
631 unsigned long crdat, mddat, bkdat;
632
Jack Jansenf5c20571997-01-30 15:48:07 +0000633 if (!PyArg_ParseTuple(args, ""))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000634 return NULL;
635 err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
636 if ( err ) {
637 PyErr_Mac(ErrorObject, err);
638 return NULL;
639 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000640 return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
Jack Jansen0bdf9791996-09-15 22:11:25 +0000641}
642
Jack Jansenf5c20571997-01-30 15:48:07 +0000643static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000644mfss_SetDates(mfssobject *self, PyObject *args)
Jack Jansen0bdf9791996-09-15 22:11:25 +0000645{
646 OSErr err;
647 double crdat, mddat, bkdat;
648
Jack Jansenf5c20571997-01-30 15:48:07 +0000649 if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000650 return NULL;
651 err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
652 (unsigned long)mddat, (unsigned long)bkdat);
653 if ( err ) {
654 PyErr_Mac(ErrorObject, err);
655 return NULL;
656 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000657 Py_INCREF(Py_None);
658 return Py_None;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000659}
660
Jack Jansenf5c20571997-01-30 15:48:07 +0000661static struct PyMethodDef mfss_methods[] = {
662 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
663 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
Jack Jansen4e566ab2001-07-08 22:07:23 +0000664 {"as_fsref", (PyCFunction)mfss_FSpMakeFSRef, 1},
665 {"FSpMakeFSRef", (PyCFunction)mfss_FSpMakeFSRef, 1},
Jack Jansenf5c20571997-01-30 15:48:07 +0000666 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
667 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
668 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
669 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
670 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
671 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
672 {"GetDates", (PyCFunction)mfss_GetDates, 1},
673 {"SetDates", (PyCFunction)mfss_SetDates, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000674
675 {NULL, NULL} /* sentinel */
676};
677
678/* ---------- */
679
Jack Jansenf5c20571997-01-30 15:48:07 +0000680static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000681mfss_getattr(mfssobject *self, char *name)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000682{
Jack Jansenc889b761995-02-13 12:00:46 +0000683 if ( strcmp(name, "data") == 0)
684 return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
Jack Jansenf5c20571997-01-30 15:48:07 +0000685 return Py_FindMethod(mfss_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000686}
687
688mfssobject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000689newmfssobject(FSSpec *fss)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000690{
691 mfssobject *self;
692
Jack Jansenf5c20571997-01-30 15:48:07 +0000693 self = PyObject_NEW(mfssobject, &Mfsstype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000694 if (self == NULL)
695 return NULL;
696 self->fsspec = *fss;
697 return self;
698}
699
700static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000701mfss_dealloc(mfssobject *self)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000702{
Jack Jansen0e2f7982002-05-22 14:31:48 +0000703 PyObject_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000704}
705
Jack Jansenf5c20571997-01-30 15:48:07 +0000706static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000707mfss_repr(mfssobject *self)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000708{
709 char buf[512];
710
Jack Jansen101de912001-12-05 23:27:58 +0000711 PyOS_snprintf(buf, sizeof(buf), "FSSpec((%d, %ld, '%.*s'))",
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000712 self->fsspec.vRefNum,
713 self->fsspec.parID,
714 self->fsspec.name[0], self->fsspec.name+1);
Jack Jansenf5c20571997-01-30 15:48:07 +0000715 return PyString_FromString(buf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000716}
717
718static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000719mfss_compare(mfssobject *v, mfssobject *w)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000720{
721 int minlen;
722 int res;
723
724 if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1;
725 if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1;
726 if ( v->fsspec.parID < w->fsspec.parID ) return -1;
727 if ( v->fsspec.parID > w->fsspec.parID ) return 1;
728 minlen = v->fsspec.name[0];
729 if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0];
730 res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen);
731 if ( res ) return res;
732 if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1;
733 if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1;
734 return res;
735}
736
Jack Jansenf5c20571997-01-30 15:48:07 +0000737statichere PyTypeObject Mfsstype = {
738 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000739 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000740 "macfs.FSSpec", /*tp_name*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000741 sizeof(mfssobject), /*tp_basicsize*/
742 0, /*tp_itemsize*/
743 /* methods */
744 (destructor)mfss_dealloc, /*tp_dealloc*/
745 (printfunc)0, /*tp_print*/
746 (getattrfunc)mfss_getattr, /*tp_getattr*/
747 (setattrfunc)0, /*tp_setattr*/
748 (cmpfunc)mfss_compare, /*tp_compare*/
749 (reprfunc)mfss_repr, /*tp_repr*/
750 0, /*tp_as_number*/
751 0, /*tp_as_sequence*/
752 0, /*tp_as_mapping*/
753 (hashfunc)0, /*tp_hash*/
754};
755
756/* End of code for FSSpec objects */
757/* -------------------------------------------------------- */
Jack Jansencbed91b2001-08-03 13:31:36 +0000758#if !TARGET_API_MAC_OS8
Jack Jansenf5c20571997-01-30 15:48:07 +0000759static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000760mfsr_as_fsspec(mfsrobject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000761{
762 OSErr err;
763 FSSpec fss;
764
765 if (!PyArg_ParseTuple(args, ""))
766 return NULL;
767 err = FSGetCatalogInfo(&self->fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL);
768 if ( err ) {
769 PyErr_Mac(ErrorObject, err);
770 return NULL;
771 }
772 Py_INCREF(Py_None);
773 return (PyObject *)newmfssobject(&fss);
774}
775
Jack Jansenba4fe772002-01-18 16:13:15 +0000776static PyObject *
777mfsr_as_pathname(mfsrobject *self, PyObject *args)
778{
Jack Jansen5ae815a2002-02-26 21:36:19 +0000779 unsigned char strbuf[PATHNAMELEN];
Jack Jansenba4fe772002-01-18 16:13:15 +0000780 OSStatus err;
781
782 if (!PyArg_ParseTuple(args, ""))
783 return NULL;
784 err = FSRefMakePath(&self->fsref, strbuf, PATHNAMELEN);
785 if ( err ) {
786 PyErr_Mac(ErrorObject, err);
787 return NULL;
788 }
Jack Jansen5ae815a2002-02-26 21:36:19 +0000789 return PyString_FromString((char *)strbuf);
Jack Jansenba4fe772002-01-18 16:13:15 +0000790}
791
Jack Jansen4e566ab2001-07-08 22:07:23 +0000792static struct PyMethodDef mfsr_methods[] = {
793 {"as_fsspec", (PyCFunction)mfsr_as_fsspec, 1},
Jack Jansenba4fe772002-01-18 16:13:15 +0000794 {"as_pathname", (PyCFunction)mfsr_as_pathname, 1},
Jack Jansen4e566ab2001-07-08 22:07:23 +0000795#if 0
Jack Jansen4e566ab2001-07-08 22:07:23 +0000796 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
797 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
798 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
799 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
800 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
801 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
802 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
803 {"GetDates", (PyCFunction)mfss_GetDates, 1},
804 {"SetDates", (PyCFunction)mfss_SetDates, 1},
805#endif
806
807 {NULL, NULL} /* sentinel */
808};
809
810/* ---------- */
811
812static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000813mfsr_getattr(mfsrobject *self, char *name)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000814{
815 if ( strcmp(name, "data") == 0)
816 return PyString_FromStringAndSize((char *)&self->fsref, sizeof(FSRef));
817 return Py_FindMethod(mfsr_methods, (PyObject *)self, name);
818}
819
820mfsrobject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000821newmfsrobject(FSRef *fsr)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000822{
823 mfsrobject *self;
824
825 self = PyObject_NEW(mfsrobject, &Mfsrtype);
826 if (self == NULL)
827 return NULL;
828 self->fsref = *fsr;
829 return self;
830}
831
832static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000833mfsr_compare(mfsrobject *v, mfsrobject *w)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000834{
835 OSErr err;
836
837 if ( v == w ) return 0;
838 err = FSCompareFSRefs(&v->fsref, &w->fsref);
839 if ( err == 0 )
840 return 0;
841 if (v < w )
842 return -1;
843 return 1;
844}
845
846static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000847mfsr_dealloc(mfsrobject *self)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000848{
Jack Jansen0e2f7982002-05-22 14:31:48 +0000849 PyObject_DEL(self);
Jack Jansen4e566ab2001-07-08 22:07:23 +0000850}
851
852statichere PyTypeObject Mfsrtype = {
853 PyObject_HEAD_INIT(&PyType_Type)
854 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000855 "macfs.FSRef", /*tp_name*/
Jack Jansen4e566ab2001-07-08 22:07:23 +0000856 sizeof(mfsrobject), /*tp_basicsize*/
857 0, /*tp_itemsize*/
858 /* methods */
859 (destructor)mfsr_dealloc, /*tp_dealloc*/
860 (printfunc)0, /*tp_print*/
861 (getattrfunc)mfsr_getattr, /*tp_getattr*/
862 (setattrfunc)0, /*tp_setattr*/
863 (cmpfunc)mfsr_compare, /*tp_compare*/
864 (reprfunc)0, /*tp_repr*/
865 0, /*tp_as_number*/
866 0, /*tp_as_sequence*/
867 0, /*tp_as_mapping*/
868 (hashfunc)0, /*tp_hash*/
869};
870
871/* End of code for FSRef objects */
Jack Jansencbed91b2001-08-03 13:31:36 +0000872#endif /* !TARGET_API_MAC_OS8 */
Jack Jansen4e566ab2001-07-08 22:07:23 +0000873/* -------------------------------------------------------- */
874
875static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000876mfs_ResolveAliasFile(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000877{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000878 FSSpec fss;
879 Boolean chain = 1, isfolder, wasaliased;
880 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000881
Jack Jansenf5c20571997-01-30 15:48:07 +0000882 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000883 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000884 err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
885 if ( err ) {
886 PyErr_Mac(ErrorObject, err);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000887 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000888 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000889 return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000890}
891
Jack Jansen74a1e632000-07-14 22:37:27 +0000892#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000893static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000894mfs_StandardGetFile(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000895{
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000896 SFTypeList list;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000897 short numtypes;
898 StandardFileReply reply;
899
900 list[0] = list[1] = list[2] = list[3] = 0;
901 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000902 if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
Jack Jansen17ba43f1995-01-26 16:22:07 +0000903 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
904 PyMac_GetOSType, &list[3]) )
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000905 return NULL;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000906 while ( numtypes < 4 && list[numtypes] ) {
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000907 numtypes++;
908 }
Jack Jansenc2632861995-06-03 21:15:50 +0000909 if ( numtypes == 0 )
910 numtypes = -1;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000911 StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000912 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000913}
914
Jack Jansenf5c20571997-01-30 15:48:07 +0000915static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000916mfs_PromptGetFile(PyObject *self, PyObject *args)
Jack Jansend5d5f461995-08-14 12:22:56 +0000917{
918 SFTypeList list;
919 short numtypes;
920 StandardFileReply reply;
921 char *prompt = NULL;
922
923 list[0] = list[1] = list[2] = list[3] = 0;
924 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000925 if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
Jack Jansend5d5f461995-08-14 12:22:56 +0000926 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
927 PyMac_GetOSType, &list[3]) )
928 return NULL;
929 while ( numtypes < 4 && list[numtypes] ) {
930 numtypes++;
931 }
932 if ( numtypes == 0 )
933 numtypes = -1;
934 PyMac_PromptGetFile(numtypes, list, &reply, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000935 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansend5d5f461995-08-14 12:22:56 +0000936}
937
Jack Jansenf5c20571997-01-30 15:48:07 +0000938static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000939mfs_StandardPutFile(PyObject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000940{
941 Str255 prompt, dft;
942 StandardFileReply reply;
943
944 dft[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000945 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
Jack Jansen17ba43f1995-01-26 16:22:07 +0000946 return NULL;
947 StandardPutFile(prompt, dft, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000948 return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000949}
950
Jack Jansend99d2831996-07-22 15:26:01 +0000951/*
952** Set initial directory for file dialogs */
Jack Jansenf5c20571997-01-30 15:48:07 +0000953static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000954mfs_SetFolder(PyObject *self, PyObject *args)
Jack Jansend99d2831996-07-22 15:26:01 +0000955{
956 FSSpec spec;
957 FSSpec ospec;
958 short orefnum;
959 long oparid;
960
961 /* Get old values */
962 orefnum = -LMGetSFSaveDisk();
963 oparid = LMGetCurDirStore();
964 (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec);
965
966 /* Go to working directory by default */
967 (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
Jack Jansenf5c20571997-01-30 15:48:07 +0000968 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
Jack Jansend99d2831996-07-22 15:26:01 +0000969 return NULL;
970 /* Set standard-file working directory */
971 LMSetSFSaveDisk(-spec.vRefNum);
972 LMSetCurDirStore(spec.parID);
Jack Jansenf5c20571997-01-30 15:48:07 +0000973 return (PyObject *)newmfssobject(&ospec);
Jack Jansend99d2831996-07-22 15:26:01 +0000974}
Jack Jansene79dc762000-06-02 21:35:07 +0000975#endif
Jack Jansend99d2831996-07-22 15:26:01 +0000976
Jack Jansenf5c20571997-01-30 15:48:07 +0000977static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000978mfs_FSSpec(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000979{
980 FSSpec fss;
981
Jack Jansenf5c20571997-01-30 15:48:07 +0000982 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000983 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000984 return (PyObject *)newmfssobject(&fss);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000985}
986
Jack Jansenf5c20571997-01-30 15:48:07 +0000987static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000988mfs_FSRef(PyObject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000989{
Jack Jansencbed91b2001-08-03 13:31:36 +0000990#if TARGET_API_MAC_OS8
991 PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform");
992 return 0;
993#else
Jack Jansen4e566ab2001-07-08 22:07:23 +0000994 FSRef fsr;
995
996 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &fsr))
997 return NULL;
998 return (PyObject *)newmfsrobject(&fsr);
Jack Jansencbed91b2001-08-03 13:31:36 +0000999#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001000}
1001
1002static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001003mfs_RawFSSpec(PyObject *self, PyObject *args)
Jack Jansenc889b761995-02-13 12:00:46 +00001004{
1005 FSSpec *fssp;
1006 int size;
1007
Jack Janseneeccca91997-05-07 15:46:31 +00001008 if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
Jack Jansenc889b761995-02-13 12:00:46 +00001009 return NULL;
1010 if ( size != sizeof(FSSpec) ) {
1011 PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
1012 return NULL;
1013 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001014 return (PyObject *)newmfssobject(fssp);
Jack Jansenc889b761995-02-13 12:00:46 +00001015}
1016
Jack Jansenf5c20571997-01-30 15:48:07 +00001017static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001018mfs_RawAlias(PyObject *self, PyObject *args)
Jack Jansenc889b761995-02-13 12:00:46 +00001019{
1020 char *dataptr;
1021 Handle h;
1022 int size;
1023
Jack Janseneeccca91997-05-07 15:46:31 +00001024 if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
Jack Jansenc889b761995-02-13 12:00:46 +00001025 return NULL;
1026 h = NewHandle(size);
1027 if ( h == NULL ) {
1028 PyErr_NoMemory();
1029 return NULL;
1030 }
1031 HLock(h);
1032 memcpy((char *)*h, dataptr, size);
1033 HUnlock(h);
Jack Jansenf5c20571997-01-30 15:48:07 +00001034 return (PyObject *)newmfsaobject((AliasHandle)h);
Jack Jansenc889b761995-02-13 12:00:46 +00001035}
1036
Jack Jansen74a1e632000-07-14 22:37:27 +00001037#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +00001038static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001039mfs_GetDirectory(PyObject *self, PyObject *args)
Jack Jansen81f51c71995-02-20 15:45:25 +00001040{
1041 FSSpec fsdir;
1042 int ok;
Jack Jansend5d5f461995-08-14 12:22:56 +00001043 char *prompt = NULL;
Jack Jansen81f51c71995-02-20 15:45:25 +00001044
Jack Jansenf5c20571997-01-30 15:48:07 +00001045 if (!PyArg_ParseTuple(args, "|s", &prompt) )
Jack Jansen81f51c71995-02-20 15:45:25 +00001046 return NULL;
1047
Jack Jansend5d5f461995-08-14 12:22:56 +00001048 ok = PyMac_GetDirectory(&fsdir, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +00001049 return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
Jack Jansen81f51c71995-02-20 15:45:25 +00001050}
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001051#endif
Jack Jansen81f51c71995-02-20 15:45:25 +00001052
Jack Jansenf5c20571997-01-30 15:48:07 +00001053static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001054mfs_FindFolder(PyObject *self, PyObject *args)
Jack Jansen2c673621995-06-18 20:05:14 +00001055{
1056 OSErr err;
1057 short where;
1058 OSType which;
1059 int create;
1060 short refnum;
1061 long dirid;
1062
Jack Jansenabd703d2001-03-15 14:38:10 +00001063 if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
Jack Jansen2c673621995-06-18 20:05:14 +00001064 return NULL;
1065 err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
1066 if ( err ) {
1067 PyErr_Mac(ErrorObject, err);
1068 return NULL;
1069 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001070 return Py_BuildValue("(ii)", refnum, dirid);
Jack Jansen2c673621995-06-18 20:05:14 +00001071}
1072
Jack Jansenf5c20571997-01-30 15:48:07 +00001073static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001074mfs_FindApplication(PyObject *self, PyObject *args)
Jack Jansen924ca851996-09-20 15:25:16 +00001075{
1076 OSErr err;
1077 OSType which;
1078 FSSpec fss;
1079
Jack Jansenf5c20571997-01-30 15:48:07 +00001080 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
Jack Jansen924ca851996-09-20 15:25:16 +00001081 return NULL;
1082 err = FindApplicationFromCreator(which, &fss);
1083 if ( err ) {
1084 PyErr_Mac(ErrorObject, err);
1085 return NULL;
1086 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001087 return (PyObject *)newmfssobject(&fss);
Jack Jansen924ca851996-09-20 15:25:16 +00001088}
1089
Jack Jansenf5c20571997-01-30 15:48:07 +00001090static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001091mfs_FInfo(PyObject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +00001092{
Jack Jansenf5c20571997-01-30 15:48:07 +00001093 return (PyObject *)newmfsiobject();
Jack Jansen3d185931995-08-07 14:04:10 +00001094}
1095
Jack Jansend9936481997-06-16 14:31:38 +00001096static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001097mfs_NewAliasMinimalFromFullPath(PyObject *self, PyObject *args)
Jack Jansend9936481997-06-16 14:31:38 +00001098{
1099 OSErr err;
1100 char *fullpath;
1101 int fullpathlen;
1102 AliasHandle alias;
1103 Str32 zonename;
1104 Str31 servername;
1105
1106 if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) )
1107 return NULL;
1108 zonename[0] = 0;
1109 servername[0] = 0;
1110 err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,
1111 servername, &alias);
1112 if ( err ) {
1113 PyErr_Mac(ErrorObject, err);
1114 return NULL;
1115 }
1116 return (PyObject *)newmfsaobject(alias);
1117}
1118
1119
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001120/* List of methods defined in the module */
1121
Jack Jansenf5c20571997-01-30 15:48:07 +00001122static struct PyMethodDef mfs_methods[] = {
Jack Jansen17ba43f1995-01-26 16:22:07 +00001123 {"ResolveAliasFile", mfs_ResolveAliasFile, 1},
Jack Jansen74a1e632000-07-14 22:37:27 +00001124#if !TARGET_API_MAC_CARBON
Jack Jansen17ba43f1995-01-26 16:22:07 +00001125 {"StandardGetFile", mfs_StandardGetFile, 1},
Jack Jansend5d5f461995-08-14 12:22:56 +00001126 {"PromptGetFile", mfs_PromptGetFile, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +00001127 {"StandardPutFile", mfs_StandardPutFile, 1},
Jack Jansen81f51c71995-02-20 15:45:25 +00001128 {"GetDirectory", mfs_GetDirectory, 1},
Jack Jansend99d2831996-07-22 15:26:01 +00001129 {"SetFolder", mfs_SetFolder, 1},
Jack Jansene79dc762000-06-02 21:35:07 +00001130#endif
Jack Jansen17ba43f1995-01-26 16:22:07 +00001131 {"FSSpec", mfs_FSSpec, 1},
Jack Jansen4e566ab2001-07-08 22:07:23 +00001132 {"FSRef", mfs_FSRef, 1},
Jack Jansenc889b761995-02-13 12:00:46 +00001133 {"RawFSSpec", mfs_RawFSSpec, 1},
1134 {"RawAlias", mfs_RawAlias, 1},
Jack Jansen2c673621995-06-18 20:05:14 +00001135 {"FindFolder", mfs_FindFolder, 1},
Jack Jansen924ca851996-09-20 15:25:16 +00001136 {"FindApplication", mfs_FindApplication, 1},
Jack Jansen3d185931995-08-07 14:04:10 +00001137 {"FInfo", mfs_FInfo, 1},
Jack Jansend9936481997-06-16 14:31:38 +00001138 {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1},
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001139
1140 {NULL, NULL} /* sentinel */
1141};
1142
Jack Jansen4e566ab2001-07-08 22:07:23 +00001143/*
1144** Convert a Python object to an FSSpec.
1145** The object may either be a full pathname, an FSSpec, an FSRef or a triple
1146** (vrefnum, dirid, path).
1147*/
1148int
1149PyMac_GetFSRef(PyObject *v, FSRef *fsr)
1150{
Jack Jansencbed91b2001-08-03 13:31:36 +00001151#if TARGET_API_MAC_OS8
Jack Jansen2bf52da2001-11-06 15:57:26 +00001152 PyErr_SetString(PyExc_TypeError, "FSRef objects not supported on this platform");
Jack Jansencbed91b2001-08-03 13:31:36 +00001153 return 0;
1154#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001155 /* If it's an FSRef we're also okay. */
1156 if (_mfs_GetFSRefFromFSRef(v, fsr))
1157 return 1;
1158 /* first check whether it already is an FSSpec */
1159 if ( _mfs_GetFSRefFromFSSpec(v, fsr) )
1160 return 1;
1161 if ( PyString_Check(v) ) {
Jack Jansena5bca572001-08-03 15:39:27 +00001162#if TARGET_API_MAC_OSX
1163 OSStatus err;
1164 if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
1165 PyErr_Mac(ErrorObject, err);
1166 return 0;
1167 }
1168 return 1;
1169#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001170 PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform");
1171 return 0;
Jack Jansena5bca572001-08-03 15:39:27 +00001172#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001173 }
1174 PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname");
1175 return 0;
Jack Jansencbed91b2001-08-03 13:31:36 +00001176#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001177}
1178
1179/* Convert FSSpec to PyObject */
1180PyObject *PyMac_BuildFSRef(FSRef *v)
1181{
Jack Jansencbed91b2001-08-03 13:31:36 +00001182#if TARGET_API_MAC_OS8
1183 return NULL;
1184#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001185 return (PyObject *)newmfsrobject(v);
Jack Jansencbed91b2001-08-03 13:31:36 +00001186#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001187}
1188
1189/*
1190** Convert a Python object to an FSRef.
1191** The object may either be a full pathname (OSX only), an FSSpec or an FSRef.
1192*/
1193int
1194PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
1195{
1196 Str255 path;
1197 short refnum;
1198 long parid;
1199 OSErr err;
1200
1201 /* first check whether it already is an FSSpec */
1202 if ( _mfs_GetFSSpecFromFSSpec(v, fs) )
1203 return 1;
1204 /* If it's an FSRef we're also okay. */
1205 if (_mfs_GetFSSpecFromFSRef(v, fs))
1206 return 1;
1207 if ( PyString_Check(v) ) {
Jack Jansend48b1062002-01-13 23:16:32 +00001208#if TARGET_API_MAC_OSX
1209 FSRef fsr;
1210
1211 if ( !PyMac_GetFSRef(v, &fsr) )
1212 return 0;
1213 if ( FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, fs, NULL) == noErr )
1214 return 1;
1215 return 0;
1216#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001217 /* It's a pathname */
1218 if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
1219 return 0;
1220 refnum = 0; /* XXXX Should get CurWD here?? */
1221 parid = 0;
Jack Jansend48b1062002-01-13 23:16:32 +00001222#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001223 } else {
1224 if( !PyArg_Parse(v, "(hlO&); FSSpec should be FSSpec, FSRef, fullpath or (vrefnum,dirid,path)",
1225 &refnum, &parid, PyMac_GetStr255, &path)) {
1226 return 0;
1227 }
1228 }
1229 err = FSMakeFSSpec(refnum, parid, path, fs);
1230 if ( err && err != fnfErr ) {
1231 PyMac_Error(err);
1232 return 0;
1233 }
1234 return 1;
1235}
1236
1237/* Convert FSSpec to PyObject */
1238PyObject *PyMac_BuildFSSpec(FSSpec *v)
1239{
1240 return (PyObject *)newmfssobject(v);
1241}
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001242
Just van Rossumab57c7d2001-10-31 22:55:08 +00001243
1244/*
1245** Import the macfsn module, which will override the Standard File
1246** calls in the macfs builtin module by Navigation Services versions,
1247** if available on this machine.
1248*/
1249static void
1250PyMac_InstallNavServicesForSF(void)
1251{
Jack Jansen01a94622001-11-01 14:00:19 +00001252#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +00001253 if ( !PyMac_options.nonavservice ) {
Jack Jansen01a94622001-11-01 14:00:19 +00001254#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +00001255 PyObject *m = PyImport_ImportModule("macfsn");
1256
1257 if ( m == NULL ) {
1258 PySys_WriteStderr("'import macfsn' failed; ");
1259 if (Py_VerboseFlag) {
1260 PySys_WriteStderr("traceback:\n");
1261 PyErr_Print();
1262 }
1263 else {
1264 PySys_WriteStderr("use -v for traceback\n");
1265 }
1266 PyErr_Clear();
1267 }
Jack Jansen01a94622001-11-01 14:00:19 +00001268#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +00001269 }
Jack Jansen01a94622001-11-01 14:00:19 +00001270#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +00001271}
1272
1273
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001274/* Initialization function for the module (*must* be called initmacfs) */
1275
1276void
Jack Jansendeefbe52001-08-08 13:46:49 +00001277initmacfs(void)
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001278{
Jack Jansenf5c20571997-01-30 15:48:07 +00001279 PyObject *m, *d;
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001280
Jack Jansen45900492001-08-06 15:32:30 +00001281 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
Jack Jansenfabd00f2001-09-01 23:39:58 +00001282 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
1283 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
1284 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
Jack Jansena5bca572001-08-03 15:39:27 +00001285
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001286 /* Create the module and add the functions */
Jack Jansenf5c20571997-01-30 15:48:07 +00001287 m = Py_InitModule("macfs", mfs_methods);
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001288
1289 /* Add some symbolic constants to the module */
Jack Jansenf5c20571997-01-30 15:48:07 +00001290 d = PyModule_GetDict(m);
Jack Jansen4377a1a2000-01-24 10:37:59 +00001291 ErrorObject = PyMac_GetOSErrException();
Jack Jansenf5c20571997-01-30 15:48:07 +00001292 PyDict_SetItemString(d, "error", ErrorObject);
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001293
Jack Jansena755e681997-09-20 17:40:22 +00001294 Mfsatype.ob_type = &PyType_Type;
1295 Py_INCREF(&Mfsatype);
1296 PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype);
1297 Mfsstype.ob_type = &PyType_Type;
1298 Py_INCREF(&Mfsstype);
1299 PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype);
1300 Mfsitype.ob_type = &PyType_Type;
1301 Py_INCREF(&Mfsitype);
1302 PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
Just van Rossumab57c7d2001-10-31 22:55:08 +00001303
1304 PyMac_InstallNavServicesForSF();
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001305}