blob: 6dba5782562f2e551512c416f6eb404bd682a7e7 [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*/
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 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);
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 Jansenf5c20571997-01-30 15:48:07 +0000703 PyMem_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
776static struct PyMethodDef mfsr_methods[] = {
777 {"as_fsspec", (PyCFunction)mfsr_as_fsspec, 1},
778#if 0
779 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
780 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
781 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
782 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
783 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
784 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
785 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
786 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
787 {"GetDates", (PyCFunction)mfss_GetDates, 1},
788 {"SetDates", (PyCFunction)mfss_SetDates, 1},
789#endif
790
791 {NULL, NULL} /* sentinel */
792};
793
794/* ---------- */
795
796static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000797mfsr_getattr(mfsrobject *self, char *name)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000798{
799 if ( strcmp(name, "data") == 0)
800 return PyString_FromStringAndSize((char *)&self->fsref, sizeof(FSRef));
801 return Py_FindMethod(mfsr_methods, (PyObject *)self, name);
802}
803
804mfsrobject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000805newmfsrobject(FSRef *fsr)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000806{
807 mfsrobject *self;
808
809 self = PyObject_NEW(mfsrobject, &Mfsrtype);
810 if (self == NULL)
811 return NULL;
812 self->fsref = *fsr;
813 return self;
814}
815
816static int
Jack Jansendeefbe52001-08-08 13:46:49 +0000817mfsr_compare(mfsrobject *v, mfsrobject *w)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000818{
819 OSErr err;
820
821 if ( v == w ) return 0;
822 err = FSCompareFSRefs(&v->fsref, &w->fsref);
823 if ( err == 0 )
824 return 0;
825 if (v < w )
826 return -1;
827 return 1;
828}
829
830static void
Jack Jansendeefbe52001-08-08 13:46:49 +0000831mfsr_dealloc(mfsrobject *self)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000832{
833 PyMem_DEL(self);
834}
835
836statichere PyTypeObject Mfsrtype = {
837 PyObject_HEAD_INIT(&PyType_Type)
838 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000839 "macfs.FSRef", /*tp_name*/
Jack Jansen4e566ab2001-07-08 22:07:23 +0000840 sizeof(mfsrobject), /*tp_basicsize*/
841 0, /*tp_itemsize*/
842 /* methods */
843 (destructor)mfsr_dealloc, /*tp_dealloc*/
844 (printfunc)0, /*tp_print*/
845 (getattrfunc)mfsr_getattr, /*tp_getattr*/
846 (setattrfunc)0, /*tp_setattr*/
847 (cmpfunc)mfsr_compare, /*tp_compare*/
848 (reprfunc)0, /*tp_repr*/
849 0, /*tp_as_number*/
850 0, /*tp_as_sequence*/
851 0, /*tp_as_mapping*/
852 (hashfunc)0, /*tp_hash*/
853};
854
855/* End of code for FSRef objects */
Jack Jansencbed91b2001-08-03 13:31:36 +0000856#endif /* !TARGET_API_MAC_OS8 */
Jack Jansen4e566ab2001-07-08 22:07:23 +0000857/* -------------------------------------------------------- */
858
859static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000860mfs_ResolveAliasFile(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000861{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000862 FSSpec fss;
863 Boolean chain = 1, isfolder, wasaliased;
864 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000865
Jack Jansenf5c20571997-01-30 15:48:07 +0000866 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000867 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000868 err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
869 if ( err ) {
870 PyErr_Mac(ErrorObject, err);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000871 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000872 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000873 return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000874}
875
Jack Jansen74a1e632000-07-14 22:37:27 +0000876#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000877static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000878mfs_StandardGetFile(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000879{
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000880 SFTypeList list;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000881 short numtypes;
882 StandardFileReply reply;
883
884 list[0] = list[1] = list[2] = list[3] = 0;
885 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000886 if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
Jack Jansen17ba43f1995-01-26 16:22:07 +0000887 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
888 PyMac_GetOSType, &list[3]) )
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000889 return NULL;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000890 while ( numtypes < 4 && list[numtypes] ) {
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000891 numtypes++;
892 }
Jack Jansenc2632861995-06-03 21:15:50 +0000893 if ( numtypes == 0 )
894 numtypes = -1;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000895 StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000896 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000897}
898
Jack Jansenf5c20571997-01-30 15:48:07 +0000899static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000900mfs_PromptGetFile(PyObject *self, PyObject *args)
Jack Jansend5d5f461995-08-14 12:22:56 +0000901{
902 SFTypeList list;
903 short numtypes;
904 StandardFileReply reply;
905 char *prompt = NULL;
906
907 list[0] = list[1] = list[2] = list[3] = 0;
908 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000909 if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
Jack Jansend5d5f461995-08-14 12:22:56 +0000910 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
911 PyMac_GetOSType, &list[3]) )
912 return NULL;
913 while ( numtypes < 4 && list[numtypes] ) {
914 numtypes++;
915 }
916 if ( numtypes == 0 )
917 numtypes = -1;
918 PyMac_PromptGetFile(numtypes, list, &reply, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000919 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansend5d5f461995-08-14 12:22:56 +0000920}
921
Jack Jansenf5c20571997-01-30 15:48:07 +0000922static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000923mfs_StandardPutFile(PyObject *self, PyObject *args)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000924{
925 Str255 prompt, dft;
926 StandardFileReply reply;
927
928 dft[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000929 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
Jack Jansen17ba43f1995-01-26 16:22:07 +0000930 return NULL;
931 StandardPutFile(prompt, dft, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000932 return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000933}
934
Jack Jansend99d2831996-07-22 15:26:01 +0000935/*
936** Set initial directory for file dialogs */
Jack Jansenf5c20571997-01-30 15:48:07 +0000937static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000938mfs_SetFolder(PyObject *self, PyObject *args)
Jack Jansend99d2831996-07-22 15:26:01 +0000939{
940 FSSpec spec;
941 FSSpec ospec;
942 short orefnum;
943 long oparid;
944
945 /* Get old values */
946 orefnum = -LMGetSFSaveDisk();
947 oparid = LMGetCurDirStore();
948 (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec);
949
950 /* Go to working directory by default */
951 (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
Jack Jansenf5c20571997-01-30 15:48:07 +0000952 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
Jack Jansend99d2831996-07-22 15:26:01 +0000953 return NULL;
954 /* Set standard-file working directory */
955 LMSetSFSaveDisk(-spec.vRefNum);
956 LMSetCurDirStore(spec.parID);
Jack Jansenf5c20571997-01-30 15:48:07 +0000957 return (PyObject *)newmfssobject(&ospec);
Jack Jansend99d2831996-07-22 15:26:01 +0000958}
Jack Jansene79dc762000-06-02 21:35:07 +0000959#endif
Jack Jansend99d2831996-07-22 15:26:01 +0000960
Jack Jansenf5c20571997-01-30 15:48:07 +0000961static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000962mfs_FSSpec(PyObject *self, PyObject *args)
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000963{
964 FSSpec fss;
965
Jack Jansenf5c20571997-01-30 15:48:07 +0000966 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000967 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000968 return (PyObject *)newmfssobject(&fss);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000969}
970
Jack Jansenf5c20571997-01-30 15:48:07 +0000971static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000972mfs_FSRef(PyObject *self, PyObject *args)
Jack Jansen4e566ab2001-07-08 22:07:23 +0000973{
Jack Jansencbed91b2001-08-03 13:31:36 +0000974#if TARGET_API_MAC_OS8
975 PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform");
976 return 0;
977#else
Jack Jansen4e566ab2001-07-08 22:07:23 +0000978 FSRef fsr;
979
980 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &fsr))
981 return NULL;
982 return (PyObject *)newmfsrobject(&fsr);
Jack Jansencbed91b2001-08-03 13:31:36 +0000983#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +0000984}
985
986static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +0000987mfs_RawFSSpec(PyObject *self, PyObject *args)
Jack Jansenc889b761995-02-13 12:00:46 +0000988{
989 FSSpec *fssp;
990 int size;
991
Jack Janseneeccca91997-05-07 15:46:31 +0000992 if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000993 return NULL;
994 if ( size != sizeof(FSSpec) ) {
995 PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
996 return NULL;
997 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000998 return (PyObject *)newmfssobject(fssp);
Jack Jansenc889b761995-02-13 12:00:46 +0000999}
1000
Jack Jansenf5c20571997-01-30 15:48:07 +00001001static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001002mfs_RawAlias(PyObject *self, PyObject *args)
Jack Jansenc889b761995-02-13 12:00:46 +00001003{
1004 char *dataptr;
1005 Handle h;
1006 int size;
1007
Jack Janseneeccca91997-05-07 15:46:31 +00001008 if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
Jack Jansenc889b761995-02-13 12:00:46 +00001009 return NULL;
1010 h = NewHandle(size);
1011 if ( h == NULL ) {
1012 PyErr_NoMemory();
1013 return NULL;
1014 }
1015 HLock(h);
1016 memcpy((char *)*h, dataptr, size);
1017 HUnlock(h);
Jack Jansenf5c20571997-01-30 15:48:07 +00001018 return (PyObject *)newmfsaobject((AliasHandle)h);
Jack Jansenc889b761995-02-13 12:00:46 +00001019}
1020
Jack Jansen74a1e632000-07-14 22:37:27 +00001021#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +00001022static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001023mfs_GetDirectory(PyObject *self, PyObject *args)
Jack Jansen81f51c71995-02-20 15:45:25 +00001024{
1025 FSSpec fsdir;
1026 int ok;
Jack Jansend5d5f461995-08-14 12:22:56 +00001027 char *prompt = NULL;
Jack Jansen81f51c71995-02-20 15:45:25 +00001028
Jack Jansenf5c20571997-01-30 15:48:07 +00001029 if (!PyArg_ParseTuple(args, "|s", &prompt) )
Jack Jansen81f51c71995-02-20 15:45:25 +00001030 return NULL;
1031
Jack Jansend5d5f461995-08-14 12:22:56 +00001032 ok = PyMac_GetDirectory(&fsdir, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +00001033 return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
Jack Jansen81f51c71995-02-20 15:45:25 +00001034}
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001035#endif
Jack Jansen81f51c71995-02-20 15:45:25 +00001036
Jack Jansenf5c20571997-01-30 15:48:07 +00001037static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001038mfs_FindFolder(PyObject *self, PyObject *args)
Jack Jansen2c673621995-06-18 20:05:14 +00001039{
1040 OSErr err;
1041 short where;
1042 OSType which;
1043 int create;
1044 short refnum;
1045 long dirid;
1046
Jack Jansenabd703d2001-03-15 14:38:10 +00001047 if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
Jack Jansen2c673621995-06-18 20:05:14 +00001048 return NULL;
1049 err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
1050 if ( err ) {
1051 PyErr_Mac(ErrorObject, err);
1052 return NULL;
1053 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001054 return Py_BuildValue("(ii)", refnum, dirid);
Jack Jansen2c673621995-06-18 20:05:14 +00001055}
1056
Jack Jansenf5c20571997-01-30 15:48:07 +00001057static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001058mfs_FindApplication(PyObject *self, PyObject *args)
Jack Jansen924ca851996-09-20 15:25:16 +00001059{
1060 OSErr err;
1061 OSType which;
1062 FSSpec fss;
1063
Jack Jansenf5c20571997-01-30 15:48:07 +00001064 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
Jack Jansen924ca851996-09-20 15:25:16 +00001065 return NULL;
1066 err = FindApplicationFromCreator(which, &fss);
1067 if ( err ) {
1068 PyErr_Mac(ErrorObject, err);
1069 return NULL;
1070 }
Jack Jansenf5c20571997-01-30 15:48:07 +00001071 return (PyObject *)newmfssobject(&fss);
Jack Jansen924ca851996-09-20 15:25:16 +00001072}
1073
Jack Jansenf5c20571997-01-30 15:48:07 +00001074static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001075mfs_FInfo(PyObject *self, PyObject *args)
Jack Jansen3d185931995-08-07 14:04:10 +00001076{
Jack Jansenf5c20571997-01-30 15:48:07 +00001077 return (PyObject *)newmfsiobject();
Jack Jansen3d185931995-08-07 14:04:10 +00001078}
1079
Jack Jansend9936481997-06-16 14:31:38 +00001080static PyObject *
Jack Jansendeefbe52001-08-08 13:46:49 +00001081mfs_NewAliasMinimalFromFullPath(PyObject *self, PyObject *args)
Jack Jansend9936481997-06-16 14:31:38 +00001082{
1083 OSErr err;
1084 char *fullpath;
1085 int fullpathlen;
1086 AliasHandle alias;
1087 Str32 zonename;
1088 Str31 servername;
1089
1090 if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) )
1091 return NULL;
1092 zonename[0] = 0;
1093 servername[0] = 0;
1094 err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,
1095 servername, &alias);
1096 if ( err ) {
1097 PyErr_Mac(ErrorObject, err);
1098 return NULL;
1099 }
1100 return (PyObject *)newmfsaobject(alias);
1101}
1102
1103
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001104/* List of methods defined in the module */
1105
Jack Jansenf5c20571997-01-30 15:48:07 +00001106static struct PyMethodDef mfs_methods[] = {
Jack Jansen17ba43f1995-01-26 16:22:07 +00001107 {"ResolveAliasFile", mfs_ResolveAliasFile, 1},
Jack Jansen74a1e632000-07-14 22:37:27 +00001108#if !TARGET_API_MAC_CARBON
Jack Jansen17ba43f1995-01-26 16:22:07 +00001109 {"StandardGetFile", mfs_StandardGetFile, 1},
Jack Jansend5d5f461995-08-14 12:22:56 +00001110 {"PromptGetFile", mfs_PromptGetFile, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +00001111 {"StandardPutFile", mfs_StandardPutFile, 1},
Jack Jansen81f51c71995-02-20 15:45:25 +00001112 {"GetDirectory", mfs_GetDirectory, 1},
Jack Jansend99d2831996-07-22 15:26:01 +00001113 {"SetFolder", mfs_SetFolder, 1},
Jack Jansene79dc762000-06-02 21:35:07 +00001114#endif
Jack Jansen17ba43f1995-01-26 16:22:07 +00001115 {"FSSpec", mfs_FSSpec, 1},
Jack Jansen4e566ab2001-07-08 22:07:23 +00001116 {"FSRef", mfs_FSRef, 1},
Jack Jansenc889b761995-02-13 12:00:46 +00001117 {"RawFSSpec", mfs_RawFSSpec, 1},
1118 {"RawAlias", mfs_RawAlias, 1},
Jack Jansen2c673621995-06-18 20:05:14 +00001119 {"FindFolder", mfs_FindFolder, 1},
Jack Jansen924ca851996-09-20 15:25:16 +00001120 {"FindApplication", mfs_FindApplication, 1},
Jack Jansen3d185931995-08-07 14:04:10 +00001121 {"FInfo", mfs_FInfo, 1},
Jack Jansend9936481997-06-16 14:31:38 +00001122 {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1},
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001123
1124 {NULL, NULL} /* sentinel */
1125};
1126
Jack Jansen4e566ab2001-07-08 22:07:23 +00001127/*
1128** Convert a Python object to an FSSpec.
1129** The object may either be a full pathname, an FSSpec, an FSRef or a triple
1130** (vrefnum, dirid, path).
1131*/
1132int
1133PyMac_GetFSRef(PyObject *v, FSRef *fsr)
1134{
Jack Jansencbed91b2001-08-03 13:31:36 +00001135#if TARGET_API_MAC_OS8
Jack Jansen2bf52da2001-11-06 15:57:26 +00001136 PyErr_SetString(PyExc_TypeError, "FSRef objects not supported on this platform");
Jack Jansencbed91b2001-08-03 13:31:36 +00001137 return 0;
1138#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001139 /* If it's an FSRef we're also okay. */
1140 if (_mfs_GetFSRefFromFSRef(v, fsr))
1141 return 1;
1142 /* first check whether it already is an FSSpec */
1143 if ( _mfs_GetFSRefFromFSSpec(v, fsr) )
1144 return 1;
1145 if ( PyString_Check(v) ) {
Jack Jansena5bca572001-08-03 15:39:27 +00001146#if TARGET_API_MAC_OSX
1147 OSStatus err;
1148 if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
1149 PyErr_Mac(ErrorObject, err);
1150 return 0;
1151 }
1152 return 1;
1153#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001154 PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform");
1155 return 0;
Jack Jansena5bca572001-08-03 15:39:27 +00001156#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001157 }
1158 PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname");
1159 return 0;
Jack Jansencbed91b2001-08-03 13:31:36 +00001160#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001161}
1162
1163/* Convert FSSpec to PyObject */
1164PyObject *PyMac_BuildFSRef(FSRef *v)
1165{
Jack Jansencbed91b2001-08-03 13:31:36 +00001166#if TARGET_API_MAC_OS8
1167 return NULL;
1168#else
Jack Jansen4e566ab2001-07-08 22:07:23 +00001169 return (PyObject *)newmfsrobject(v);
Jack Jansencbed91b2001-08-03 13:31:36 +00001170#endif
Jack Jansen4e566ab2001-07-08 22:07:23 +00001171}
1172
1173/*
1174** Convert a Python object to an FSRef.
1175** The object may either be a full pathname (OSX only), an FSSpec or an FSRef.
1176*/
1177int
1178PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
1179{
1180 Str255 path;
1181 short refnum;
1182 long parid;
1183 OSErr err;
1184
1185 /* first check whether it already is an FSSpec */
1186 if ( _mfs_GetFSSpecFromFSSpec(v, fs) )
1187 return 1;
1188 /* If it's an FSRef we're also okay. */
1189 if (_mfs_GetFSSpecFromFSRef(v, fs))
1190 return 1;
1191 if ( PyString_Check(v) ) {
1192 /* It's a pathname */
1193 if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
1194 return 0;
1195 refnum = 0; /* XXXX Should get CurWD here?? */
1196 parid = 0;
1197 } else {
1198 if( !PyArg_Parse(v, "(hlO&); FSSpec should be FSSpec, FSRef, fullpath or (vrefnum,dirid,path)",
1199 &refnum, &parid, PyMac_GetStr255, &path)) {
1200 return 0;
1201 }
1202 }
1203 err = FSMakeFSSpec(refnum, parid, path, fs);
1204 if ( err && err != fnfErr ) {
1205 PyMac_Error(err);
1206 return 0;
1207 }
1208 return 1;
1209}
1210
1211/* Convert FSSpec to PyObject */
1212PyObject *PyMac_BuildFSSpec(FSSpec *v)
1213{
1214 return (PyObject *)newmfssobject(v);
1215}
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001216
Just van Rossumab57c7d2001-10-31 22:55:08 +00001217
1218/*
1219** Import the macfsn module, which will override the Standard File
1220** calls in the macfs builtin module by Navigation Services versions,
1221** if available on this machine.
1222*/
1223static void
1224PyMac_InstallNavServicesForSF(void)
1225{
Jack Jansen01a94622001-11-01 14:00:19 +00001226#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +00001227 if ( !PyMac_options.nonavservice ) {
Jack Jansen01a94622001-11-01 14:00:19 +00001228#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +00001229 PyObject *m = PyImport_ImportModule("macfsn");
1230
1231 if ( m == NULL ) {
1232 PySys_WriteStderr("'import macfsn' failed; ");
1233 if (Py_VerboseFlag) {
1234 PySys_WriteStderr("traceback:\n");
1235 PyErr_Print();
1236 }
1237 else {
1238 PySys_WriteStderr("use -v for traceback\n");
1239 }
1240 PyErr_Clear();
1241 }
Jack Jansen01a94622001-11-01 14:00:19 +00001242#ifndef TARGET_API_MAC_OSX
Just van Rossumab57c7d2001-10-31 22:55:08 +00001243 }
Jack Jansen01a94622001-11-01 14:00:19 +00001244#endif
Just van Rossumab57c7d2001-10-31 22:55:08 +00001245}
1246
1247
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001248/* Initialization function for the module (*must* be called initmacfs) */
1249
1250void
Jack Jansendeefbe52001-08-08 13:46:49 +00001251initmacfs(void)
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001252{
Jack Jansenf5c20571997-01-30 15:48:07 +00001253 PyObject *m, *d;
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001254
Jack Jansen45900492001-08-06 15:32:30 +00001255 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
Jack Jansenfabd00f2001-09-01 23:39:58 +00001256 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
1257 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
1258 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
Jack Jansena5bca572001-08-03 15:39:27 +00001259
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001260 /* Create the module and add the functions */
Jack Jansenf5c20571997-01-30 15:48:07 +00001261 m = Py_InitModule("macfs", mfs_methods);
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001262
1263 /* Add some symbolic constants to the module */
Jack Jansenf5c20571997-01-30 15:48:07 +00001264 d = PyModule_GetDict(m);
Jack Jansen4377a1a2000-01-24 10:37:59 +00001265 ErrorObject = PyMac_GetOSErrException();
Jack Jansenf5c20571997-01-30 15:48:07 +00001266 PyDict_SetItemString(d, "error", ErrorObject);
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001267
Jack Jansena755e681997-09-20 17:40:22 +00001268 Mfsatype.ob_type = &PyType_Type;
1269 Py_INCREF(&Mfsatype);
1270 PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype);
1271 Mfsstype.ob_type = &PyType_Type;
1272 Py_INCREF(&Mfsstype);
1273 PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype);
1274 Mfsitype.ob_type = &PyType_Type;
1275 Py_INCREF(&Mfsitype);
1276 PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
Just van Rossumab57c7d2001-10-31 22:55:08 +00001277
1278 PyMac_InstallNavServicesForSF();
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001279}