blob: 8021aa18618c37c81ca4ce4d98eb48a28fe728f7 [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"
27
Guido van Rossumbecdbec1995-02-14 01:27:24 +000028#include <Memory.h>
Jack Jansen84fa5ec1995-01-18 14:04:40 +000029#include <Files.h>
Jack Jansen2c673621995-06-18 20:05:14 +000030#include <Folders.h>
Jack Jansen84fa5ec1995-01-18 14:04:40 +000031#include <StandardFile.h>
32#include <Aliases.h>
Jack Jansend99d2831996-07-22 15:26:01 +000033#include <LowMem.h>
Jack Jansen84fa5ec1995-01-18 14:04:40 +000034
Jack Jansen924ca851996-09-20 15:25:16 +000035#include "getapplbycreator.h"
Jack Jansen84fa5ec1995-01-18 14:04:40 +000036
Jack Jansenf5c20571997-01-30 15:48:07 +000037static PyObject *ErrorObject;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000038
39/* ----------------------------------------------------- */
Jack Jansen17ba43f1995-01-26 16:22:07 +000040/* Declarations for objects of type Alias */
41
42typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000043 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000044 AliasHandle alias;
45} mfsaobject;
46
Jack Jansenf5c20571997-01-30 15:48:07 +000047staticforward PyTypeObject Mfsatype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000048
49#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
50
51/* ---------------------------------------------------------------- */
52/* Declarations for objects of type FSSpec */
53
54typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000055 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000056 FSSpec fsspec;
57} mfssobject;
58
Jack Jansenf5c20571997-01-30 15:48:07 +000059staticforward PyTypeObject Mfsstype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000060
61#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
62
Guido van Rossumefd97671995-01-26 22:56:16 +000063
Jack Jansen3d185931995-08-07 14:04:10 +000064/* ---------------------------------------------------------------- */
65/* Declarations for objects of type FInfo */
66
67typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000068 PyObject_HEAD
Jack Jansen3d185931995-08-07 14:04:10 +000069 FInfo finfo;
70} mfsiobject;
71
Jack Jansenf5c20571997-01-30 15:48:07 +000072staticforward PyTypeObject Mfsitype;
Jack Jansen3d185931995-08-07 14:04:10 +000073
74#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
75
76
Guido van Rossumefd97671995-01-26 22:56:16 +000077mfssobject *newmfssobject(FSSpec *fss); /* Forward */
78
Jack Jansen17ba43f1995-01-26 16:22:07 +000079/* ---------------------------------------------------------------- */
Jack Jansen84fa5ec1995-01-18 14:04:40 +000080
Jack Jansenf5c20571997-01-30 15:48:07 +000081static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +000082mfsa_Resolve(self, args)
83 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +000084 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000085{
Jack Jansen17ba43f1995-01-26 16:22:07 +000086 FSSpec from, *fromp, result;
87 Boolean changed;
88 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000089
Jack Jansen17ba43f1995-01-26 16:22:07 +000090 from.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +000091 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
Jack Jansen84fa5ec1995-01-18 14:04:40 +000092 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +000093 if (from.name[0] )
94 fromp = &from;
95 else
96 fromp = NULL;
97 err = ResolveAlias(fromp, self->alias, &result, &changed);
Jack Jansend9936481997-06-16 14:31:38 +000098 if ( err && err != fnfErr ) {
Jack Jansen17ba43f1995-01-26 16:22:07 +000099 PyErr_Mac(ErrorObject, err);
100 return NULL;
101 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000102 return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000103}
104
Jack Jansenf5c20571997-01-30 15:48:07 +0000105static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000106mfsa_GetInfo(self, args)
107 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000108 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000109{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000110 Str63 value;
111 int i;
112 OSErr err;
113
Jack Jansenf5c20571997-01-30 15:48:07 +0000114 if (!PyArg_ParseTuple(args, "i", &i))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000115 return NULL;
116 err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
117 if ( err ) {
118 PyErr_Mac(ErrorObject, err);
119 return 0;
120 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000121 return PyString_FromStringAndSize((char *)&value[1], value[0]);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000122}
123
Jack Jansenf5c20571997-01-30 15:48:07 +0000124static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000125mfsa_Update(self, args)
126 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000127 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000128{
129 FSSpec target, fromfile, *fromfilep;
130 OSErr err;
131 Boolean changed;
132
133 fromfile.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000134 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target,
Jack Jansen17ba43f1995-01-26 16:22:07 +0000135 PyMac_GetFSSpec, &fromfile))
136 return NULL;
137 if ( fromfile.name[0] )
138 fromfilep = &fromfile;
139 else
140 fromfilep = NULL;
141 err = UpdateAlias(fromfilep, &target, self->alias, &changed);
142 if ( err ) {
143 PyErr_Mac(ErrorObject, err);
144 return 0;
145 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000146 return Py_BuildValue("i", (int)changed);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000147}
148
Jack Jansenf5c20571997-01-30 15:48:07 +0000149static struct PyMethodDef mfsa_methods[] = {
150 {"Resolve", (PyCFunction)mfsa_Resolve, 1},
151 {"GetInfo", (PyCFunction)mfsa_GetInfo, 1},
152 {"Update", (PyCFunction)mfsa_Update, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000153
154 {NULL, NULL} /* sentinel */
155};
156
157/* ---------- */
158
Jack Jansenf5c20571997-01-30 15:48:07 +0000159static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000160mfsa_getattr(self, name)
161 mfsaobject *self;
162 char *name;
163{
Jack Jansenc889b761995-02-13 12:00:46 +0000164 if ( strcmp(name, "data") == 0 ) {
165 int size;
166 PyObject *rv;
167
168 size = GetHandleSize((Handle)self->alias);
169 HLock((Handle)self->alias);
170 rv = PyString_FromStringAndSize(*(Handle)self->alias, size);
171 HUnlock((Handle)self->alias);
172 return rv;
173 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000174 return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000175}
176
177mfsaobject *
178newmfsaobject(alias)
179 AliasHandle alias;
180{
181 mfsaobject *self;
182
Jack Jansenf5c20571997-01-30 15:48:07 +0000183 self = PyObject_NEW(mfsaobject, &Mfsatype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000184 if (self == NULL)
185 return NULL;
186 self->alias = alias;
187 return self;
188}
189
190
191static void
192mfsa_dealloc(self)
193 mfsaobject *self;
194{
195#if 0
196 if ( self->alias ) {
197 should we do something here?
198 }
199#endif
200
Jack Jansenf5c20571997-01-30 15:48:07 +0000201 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000202}
203
Jack Jansenf5c20571997-01-30 15:48:07 +0000204statichere PyTypeObject Mfsatype = {
205 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000206 0, /*ob_size*/
207 "Alias", /*tp_name*/
208 sizeof(mfsaobject), /*tp_basicsize*/
209 0, /*tp_itemsize*/
210 /* methods */
211 (destructor)mfsa_dealloc, /*tp_dealloc*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000212 (printfunc)0, /*tp_print*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000213 (getattrfunc)mfsa_getattr, /*tp_getattr*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000214 (setattrfunc)0, /*tp_setattr*/
215 (cmpfunc)0, /*tp_compare*/
216 (reprfunc)0, /*tp_repr*/
217 0, /*tp_as_number*/
218 0, /*tp_as_sequence*/
219 0, /*tp_as_mapping*/
220 (hashfunc)0, /*tp_hash*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000221};
222
223/* End of code for Alias objects */
224/* -------------------------------------------------------- */
225
Jack Jansen3d185931995-08-07 14:04:10 +0000226/* ---------------------------------------------------------------- */
227
Jack Jansenf5c20571997-01-30 15:48:07 +0000228static struct PyMethodDef mfsi_methods[] = {
Jack Jansen3d185931995-08-07 14:04:10 +0000229
230 {NULL, NULL} /* sentinel */
231};
232
233/* ---------- */
234
235static mfsiobject *
236newmfsiobject()
237{
238 mfsiobject *self;
239
Jack Jansenf5c20571997-01-30 15:48:07 +0000240 self = PyObject_NEW(mfsiobject, &Mfsitype);
Jack Jansen3d185931995-08-07 14:04:10 +0000241 if (self == NULL)
242 return NULL;
243 memset((char *)&self->finfo, '\0', sizeof(self->finfo));
244 return self;
245}
246
247static void
248mfsi_dealloc(self)
249 mfsiobject *self;
250{
Jack Jansenf5c20571997-01-30 15:48:07 +0000251 PyMem_DEL(self);
Jack Jansen3d185931995-08-07 14:04:10 +0000252}
253
Jack Jansenf5c20571997-01-30 15:48:07 +0000254static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000255mfsi_getattr(self, name)
256 mfsiobject *self;
257 char *name;
258{
Jack Jansen3d185931995-08-07 14:04:10 +0000259 if ( strcmp(name, "Type") == 0 )
260 return PyMac_BuildOSType(self->finfo.fdType);
261 else if ( strcmp(name, "Creator") == 0 )
262 return PyMac_BuildOSType(self->finfo.fdCreator);
263 else if ( strcmp(name, "Flags") == 0 )
264 return Py_BuildValue("i", (int)self->finfo.fdFlags);
265 else if ( strcmp(name, "Location") == 0 )
266 return PyMac_BuildPoint(self->finfo.fdLocation);
267 else if ( strcmp(name, "Fldr") == 0 )
268 return Py_BuildValue("i", (int)self->finfo.fdFldr);
269 else
Jack Jansenf5c20571997-01-30 15:48:07 +0000270 return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
Jack Jansen3d185931995-08-07 14:04:10 +0000271}
272
273
274static int
275mfsi_setattr(self, name, v)
276 mfsiobject *self;
277 char *name;
Jack Jansenf5c20571997-01-30 15:48:07 +0000278 PyObject *v;
Jack Jansen3d185931995-08-07 14:04:10 +0000279{
280 int rv;
281 int i;
282
283 if ( v == NULL ) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000284 PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000285 return -1;
286 }
287 if ( strcmp(name, "Type") == 0 )
288 rv = PyMac_GetOSType(v, &self->finfo.fdType);
289 else if ( strcmp(name, "Creator") == 0 )
290 rv = PyMac_GetOSType(v, &self->finfo.fdCreator);
291 else if ( strcmp(name, "Flags") == 0 ) {
292 rv = PyArg_Parse(v, "i", &i);
293 self->finfo.fdFlags = (short)i;
294 } else if ( strcmp(name, "Location") == 0 )
295 rv = PyMac_GetPoint(v, &self->finfo.fdLocation);
296 else if ( strcmp(name, "Fldr") == 0 ) {
297 rv = PyArg_Parse(v, "i", &i);
298 self->finfo.fdFldr = (short)i;
299 } else {
Jack Jansenf5c20571997-01-30 15:48:07 +0000300 PyErr_SetString(PyExc_AttributeError, "No such attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000301 return -1;
302 }
303 if (rv)
304 return 0;
305 return -1;
306}
307
308
Jack Jansenf5c20571997-01-30 15:48:07 +0000309static PyTypeObject Mfsitype = {
310 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen3d185931995-08-07 14:04:10 +0000311 0, /*ob_size*/
Jack Jansena755e681997-09-20 17:40:22 +0000312 "FInfo", /*tp_name*/
Jack Jansen3d185931995-08-07 14:04:10 +0000313 sizeof(mfsiobject), /*tp_basicsize*/
314 0, /*tp_itemsize*/
315 /* methods */
316 (destructor)mfsi_dealloc, /*tp_dealloc*/
317 (printfunc)0, /*tp_print*/
318 (getattrfunc)mfsi_getattr, /*tp_getattr*/
319 (setattrfunc)mfsi_setattr, /*tp_setattr*/
320 (cmpfunc)0, /*tp_compare*/
321 (reprfunc)0, /*tp_repr*/
322 0, /*tp_as_number*/
323 0, /*tp_as_sequence*/
324 0, /*tp_as_mapping*/
325 (hashfunc)0, /*tp_hash*/
326};
327
328/* End of code for FInfo object objects */
329/* -------------------------------------------------------- */
330
331
Jack Jansen17ba43f1995-01-26 16:22:07 +0000332/*
333** Helper routine for other modules: return an FSSpec * if the
334** object is a python fsspec object, else NULL
335*/
336FSSpec *
337mfs_GetFSSpecFSSpec(self)
Jack Jansenf5c20571997-01-30 15:48:07 +0000338 PyObject *self;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000339{
340 if ( is_mfssobject(self) )
341 return &((mfssobject *)self)->fsspec;
342 return NULL;
343}
344
Jack Jansen0bdf9791996-09-15 22:11:25 +0000345/*
346** Two generally useful routines
347*/
348static OSErr
349PyMac_GetFileDates(fss, crdat, mddat, bkdat)
350 FSSpec *fss;
351 unsigned long *crdat, *mddat, *bkdat;
352{
353 CInfoPBRec pb;
354 OSErr error;
355
356 pb.dirInfo.ioNamePtr = fss->name;
357 pb.dirInfo.ioFDirIndex = 0;
358 pb.dirInfo.ioVRefNum = fss->vRefNum;
359 pb.dirInfo.ioDrDirID = fss->parID;
360 error = PBGetCatInfoSync(&pb);
361 if ( error ) return error;
362 *crdat = pb.hFileInfo.ioFlCrDat;
363 *mddat = pb.hFileInfo.ioFlMdDat;
364 *bkdat = pb.hFileInfo.ioFlBkDat;
365 return 0;
366}
367
368static OSErr
369PyMac_SetFileDates(fss, crdat, mddat, bkdat)
370 FSSpec *fss;
371 unsigned long crdat, mddat, bkdat;
372{
373 CInfoPBRec pb;
374 OSErr error;
375
376 pb.dirInfo.ioNamePtr = fss->name;
377 pb.dirInfo.ioFDirIndex = 0;
378 pb.dirInfo.ioVRefNum = fss->vRefNum;
379 pb.dirInfo.ioDrDirID = fss->parID;
380 error = PBGetCatInfoSync(&pb);
381 if ( error ) return error;
382 pb.dirInfo.ioNamePtr = fss->name;
383 pb.dirInfo.ioFDirIndex = 0;
384 pb.dirInfo.ioVRefNum = fss->vRefNum;
385 pb.dirInfo.ioDrDirID = fss->parID;
386 pb.hFileInfo.ioFlCrDat = crdat;
387 pb.hFileInfo.ioFlMdDat = mddat;
388 pb.hFileInfo.ioFlBkDat = bkdat;
389 error = PBSetCatInfoSync(&pb);
390 return error;
391}
392
Jack Jansenf5c20571997-01-30 15:48:07 +0000393static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000394mfss_as_pathname(self, args)
395 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000396 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000397{
398 char strbuf[257];
399 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000400
Jack Jansenf5c20571997-01-30 15:48:07 +0000401 if (!PyArg_ParseTuple(args, ""))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000402 return NULL;
Jack Jansen84fb1fa1996-11-09 18:46:57 +0000403 err = PyMac_GetFullPath(&self->fsspec, strbuf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000404 if ( err ) {
405 PyErr_Mac(ErrorObject, err);
406 return NULL;
407 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000408 return PyString_FromString(strbuf);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000409}
410
Jack Jansenf5c20571997-01-30 15:48:07 +0000411static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000412mfss_as_tuple(self, args)
413 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000414 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000415{
Jack Jansenf5c20571997-01-30 15:48:07 +0000416 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000417 return NULL;
418 return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
419 &self->fsspec.name[1], self->fsspec.name[0]);
420}
421
Jack Jansenf5c20571997-01-30 15:48:07 +0000422static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000423mfss_NewAlias(self, args)
424 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000425 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000426{
427 FSSpec src, *srcp;
428 OSErr err;
429 AliasHandle alias;
430
431 src.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000432 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000433 return NULL;
434 if ( src.name[0] )
435 srcp = &src;
436 else
437 srcp = NULL;
438 err = NewAlias(srcp, &self->fsspec, &alias);
439 if ( err ) {
440 PyErr_Mac(ErrorObject, err);
441 return NULL;
442 }
443
Jack Jansenf5c20571997-01-30 15:48:07 +0000444 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000445}
446
Jack Jansenf5c20571997-01-30 15:48:07 +0000447static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000448mfss_NewAliasMinimal(self, args)
449 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000450 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000451{
452 OSErr err;
453 AliasHandle alias;
454
Jack Jansenf5c20571997-01-30 15:48:07 +0000455 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000456 return NULL;
457 err = NewAliasMinimal(&self->fsspec, &alias);
458 if ( err ) {
459 PyErr_Mac(ErrorObject, err);
460 return NULL;
461 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000462 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000463}
464
Jack Jansen3d185931995-08-07 14:04:10 +0000465/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
Jack Jansenf5c20571997-01-30 15:48:07 +0000466static PyObject *
Jack Jansen8828fcf1995-02-02 14:23:52 +0000467mfss_GetCreatorType(self, args)
468 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000469 PyObject *args;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000470{
471 OSErr err;
472 FInfo info;
473
Jack Jansenf5c20571997-01-30 15:48:07 +0000474 if (!PyArg_ParseTuple(args, ""))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000475 return NULL;
476 err = FSpGetFInfo(&self->fsspec, &info);
477 if ( err ) {
478 PyErr_Mac(ErrorObject, err);
479 return NULL;
480 }
481 return Py_BuildValue("(O&O&)",
482 PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
483}
484
Jack Jansenf5c20571997-01-30 15:48:07 +0000485static PyObject *
Jack Jansen8828fcf1995-02-02 14:23:52 +0000486mfss_SetCreatorType(self, args)
487 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000488 PyObject *args;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000489{
490 OSErr err;
491 OSType creator, type;
492 FInfo info;
493
Jack Jansenf5c20571997-01-30 15:48:07 +0000494 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000495 return NULL;
496 err = FSpGetFInfo(&self->fsspec, &info);
497 if ( err ) {
498 PyErr_Mac(ErrorObject, err);
499 return NULL;
500 }
501 info.fdType = type;
502 info.fdCreator = creator;
503 err = FSpSetFInfo(&self->fsspec, &info);
504 if ( err ) {
505 PyErr_Mac(ErrorObject, err);
506 return NULL;
507 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000508 Py_INCREF(Py_None);
509 return Py_None;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000510}
511
Jack Jansenf5c20571997-01-30 15:48:07 +0000512static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000513mfss_GetFInfo(self, args)
514 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000515 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000516{
517 OSErr err;
518 mfsiobject *fip;
519
520
Jack Jansenf5c20571997-01-30 15:48:07 +0000521 if (!PyArg_ParseTuple(args, ""))
Jack Jansen3d185931995-08-07 14:04:10 +0000522 return NULL;
523 if ( (fip=newmfsiobject()) == NULL )
524 return NULL;
525 err = FSpGetFInfo(&self->fsspec, &fip->finfo);
526 if ( err ) {
527 PyErr_Mac(ErrorObject, err);
Jack Jansenf5c20571997-01-30 15:48:07 +0000528 Py_DECREF(fip);
Jack Jansen3d185931995-08-07 14:04:10 +0000529 return NULL;
530 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000531 return (PyObject *)fip;
Jack Jansen3d185931995-08-07 14:04:10 +0000532}
533
Jack Jansenf5c20571997-01-30 15:48:07 +0000534static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000535mfss_SetFInfo(self, args)
536 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000537 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000538{
539 OSErr err;
540 mfsiobject *fip;
541
Jack Jansenf5c20571997-01-30 15:48:07 +0000542 if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
Jack Jansen3d185931995-08-07 14:04:10 +0000543 return NULL;
544 err = FSpSetFInfo(&self->fsspec, &fip->finfo);
545 if ( err ) {
546 PyErr_Mac(ErrorObject, err);
547 return NULL;
548 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000549 Py_INCREF(Py_None);
550 return Py_None;
Jack Jansen3d185931995-08-07 14:04:10 +0000551}
552
Jack Jansenf5c20571997-01-30 15:48:07 +0000553static PyObject *
Jack Jansen0bdf9791996-09-15 22:11:25 +0000554mfss_GetDates(self, args)
555 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000556 PyObject *args;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000557{
558 OSErr err;
559 unsigned long crdat, mddat, bkdat;
560
Jack Jansenf5c20571997-01-30 15:48:07 +0000561 if (!PyArg_ParseTuple(args, ""))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000562 return NULL;
563 err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
564 if ( err ) {
565 PyErr_Mac(ErrorObject, err);
566 return NULL;
567 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000568 return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
Jack Jansen0bdf9791996-09-15 22:11:25 +0000569}
570
Jack Jansenf5c20571997-01-30 15:48:07 +0000571static PyObject *
Jack Jansen0bdf9791996-09-15 22:11:25 +0000572mfss_SetDates(self, args)
573 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000574 PyObject *args;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000575{
576 OSErr err;
577 double crdat, mddat, bkdat;
578
Jack Jansenf5c20571997-01-30 15:48:07 +0000579 if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000580 return NULL;
581 err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
582 (unsigned long)mddat, (unsigned long)bkdat);
583 if ( err ) {
584 PyErr_Mac(ErrorObject, err);
585 return NULL;
586 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000587 Py_INCREF(Py_None);
588 return Py_None;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000589}
590
Jack Jansenf5c20571997-01-30 15:48:07 +0000591static struct PyMethodDef mfss_methods[] = {
592 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
593 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
594 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
595 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
596 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
597 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
598 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
599 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
600 {"GetDates", (PyCFunction)mfss_GetDates, 1},
601 {"SetDates", (PyCFunction)mfss_SetDates, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000602
603 {NULL, NULL} /* sentinel */
604};
605
606/* ---------- */
607
Jack Jansenf5c20571997-01-30 15:48:07 +0000608static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000609mfss_getattr(self, name)
610 mfssobject *self;
611 char *name;
612{
Jack Jansenc889b761995-02-13 12:00:46 +0000613 if ( strcmp(name, "data") == 0)
614 return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
Jack Jansenf5c20571997-01-30 15:48:07 +0000615 return Py_FindMethod(mfss_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000616}
617
618mfssobject *
619newmfssobject(fss)
620 FSSpec *fss;
621{
622 mfssobject *self;
623
Jack Jansenf5c20571997-01-30 15:48:07 +0000624 self = PyObject_NEW(mfssobject, &Mfsstype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000625 if (self == NULL)
626 return NULL;
627 self->fsspec = *fss;
628 return self;
629}
630
631static void
632mfss_dealloc(self)
633 mfssobject *self;
634{
Jack Jansenf5c20571997-01-30 15:48:07 +0000635 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000636}
637
Jack Jansenf5c20571997-01-30 15:48:07 +0000638static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000639mfss_repr(self)
640 mfssobject *self;
641{
642 char buf[512];
643
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000644 sprintf(buf, "FSSpec((%d, %d, '%.*s'))",
645 self->fsspec.vRefNum,
646 self->fsspec.parID,
647 self->fsspec.name[0], self->fsspec.name+1);
Jack Jansenf5c20571997-01-30 15:48:07 +0000648 return PyString_FromString(buf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000649}
650
651static int
652mfss_compare(v, w)
653 mfssobject *v, *w;
654{
655 int minlen;
656 int res;
657
658 if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1;
659 if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1;
660 if ( v->fsspec.parID < w->fsspec.parID ) return -1;
661 if ( v->fsspec.parID > w->fsspec.parID ) return 1;
662 minlen = v->fsspec.name[0];
663 if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0];
664 res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen);
665 if ( res ) return res;
666 if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1;
667 if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1;
668 return res;
669}
670
Jack Jansenf5c20571997-01-30 15:48:07 +0000671statichere PyTypeObject Mfsstype = {
672 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000673 0, /*ob_size*/
674 "FSSpec", /*tp_name*/
675 sizeof(mfssobject), /*tp_basicsize*/
676 0, /*tp_itemsize*/
677 /* methods */
678 (destructor)mfss_dealloc, /*tp_dealloc*/
679 (printfunc)0, /*tp_print*/
680 (getattrfunc)mfss_getattr, /*tp_getattr*/
681 (setattrfunc)0, /*tp_setattr*/
682 (cmpfunc)mfss_compare, /*tp_compare*/
683 (reprfunc)mfss_repr, /*tp_repr*/
684 0, /*tp_as_number*/
685 0, /*tp_as_sequence*/
686 0, /*tp_as_mapping*/
687 (hashfunc)0, /*tp_hash*/
688};
689
690/* End of code for FSSpec objects */
691/* -------------------------------------------------------- */
692
Jack Jansenf5c20571997-01-30 15:48:07 +0000693static PyObject *
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000694mfs_ResolveAliasFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000695 PyObject *self; /* Not used */
696 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000697{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000698 FSSpec fss;
699 Boolean chain = 1, isfolder, wasaliased;
700 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000701
Jack Jansenf5c20571997-01-30 15:48:07 +0000702 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000703 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000704 err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
705 if ( err ) {
706 PyErr_Mac(ErrorObject, err);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000707 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000708 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000709 return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000710}
711
Jack Jansene79dc762000-06-02 21:35:07 +0000712#ifndef TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000713static PyObject *
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000714mfs_StandardGetFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000715 PyObject *self; /* Not used */
716 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000717{
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000718 SFTypeList list;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000719 short numtypes;
720 StandardFileReply reply;
721
722 list[0] = list[1] = list[2] = list[3] = 0;
723 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000724 if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
Jack Jansen17ba43f1995-01-26 16:22:07 +0000725 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
726 PyMac_GetOSType, &list[3]) )
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000727 return NULL;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000728 while ( numtypes < 4 && list[numtypes] ) {
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000729 numtypes++;
730 }
Jack Jansenc2632861995-06-03 21:15:50 +0000731 if ( numtypes == 0 )
732 numtypes = -1;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000733 StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000734 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000735}
736
Jack Jansenf5c20571997-01-30 15:48:07 +0000737static PyObject *
Jack Jansend5d5f461995-08-14 12:22:56 +0000738mfs_PromptGetFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000739 PyObject *self; /* Not used */
740 PyObject *args;
Jack Jansend5d5f461995-08-14 12:22:56 +0000741{
742 SFTypeList list;
743 short numtypes;
744 StandardFileReply reply;
745 char *prompt = NULL;
746
747 list[0] = list[1] = list[2] = list[3] = 0;
748 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000749 if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
Jack Jansend5d5f461995-08-14 12:22:56 +0000750 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
751 PyMac_GetOSType, &list[3]) )
752 return NULL;
753 while ( numtypes < 4 && list[numtypes] ) {
754 numtypes++;
755 }
756 if ( numtypes == 0 )
757 numtypes = -1;
758 PyMac_PromptGetFile(numtypes, list, &reply, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000759 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansend5d5f461995-08-14 12:22:56 +0000760}
761
Jack Jansenf5c20571997-01-30 15:48:07 +0000762static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000763mfs_StandardPutFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000764 PyObject *self; /* Not used */
765 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000766{
767 Str255 prompt, dft;
768 StandardFileReply reply;
769
770 dft[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000771 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
Jack Jansen17ba43f1995-01-26 16:22:07 +0000772 return NULL;
773 StandardPutFile(prompt, dft, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000774 return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000775}
776
Jack Jansend99d2831996-07-22 15:26:01 +0000777/*
778** Set initial directory for file dialogs */
Jack Jansenf5c20571997-01-30 15:48:07 +0000779static PyObject *
Jack Jansend99d2831996-07-22 15:26:01 +0000780mfs_SetFolder(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000781 PyObject *self;
782 PyObject *args;
Jack Jansend99d2831996-07-22 15:26:01 +0000783{
784 FSSpec spec;
785 FSSpec ospec;
786 short orefnum;
787 long oparid;
788
789 /* Get old values */
790 orefnum = -LMGetSFSaveDisk();
791 oparid = LMGetCurDirStore();
792 (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec);
793
794 /* Go to working directory by default */
795 (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
Jack Jansenf5c20571997-01-30 15:48:07 +0000796 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
Jack Jansend99d2831996-07-22 15:26:01 +0000797 return NULL;
798 /* Set standard-file working directory */
799 LMSetSFSaveDisk(-spec.vRefNum);
800 LMSetCurDirStore(spec.parID);
Jack Jansenf5c20571997-01-30 15:48:07 +0000801 return (PyObject *)newmfssobject(&ospec);
Jack Jansend99d2831996-07-22 15:26:01 +0000802}
Jack Jansene79dc762000-06-02 21:35:07 +0000803#endif
Jack Jansend99d2831996-07-22 15:26:01 +0000804
Jack Jansenf5c20571997-01-30 15:48:07 +0000805static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000806mfs_FSSpec(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000807 PyObject *self; /* Not used */
808 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000809{
810 FSSpec fss;
811
Jack Jansenf5c20571997-01-30 15:48:07 +0000812 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000813 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000814 return (PyObject *)newmfssobject(&fss);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000815}
816
Jack Jansenf5c20571997-01-30 15:48:07 +0000817static PyObject *
Jack Jansenc889b761995-02-13 12:00:46 +0000818mfs_RawFSSpec(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000819 PyObject *self; /* Not used */
820 PyObject *args;
Jack Jansenc889b761995-02-13 12:00:46 +0000821{
822 FSSpec *fssp;
823 int size;
824
Jack Janseneeccca91997-05-07 15:46:31 +0000825 if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000826 return NULL;
827 if ( size != sizeof(FSSpec) ) {
828 PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
829 return NULL;
830 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000831 return (PyObject *)newmfssobject(fssp);
Jack Jansenc889b761995-02-13 12:00:46 +0000832}
833
Jack Jansenf5c20571997-01-30 15:48:07 +0000834static PyObject *
Jack Jansenc889b761995-02-13 12:00:46 +0000835mfs_RawAlias(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000836 PyObject *self; /* Not used */
837 PyObject *args;
Jack Jansenc889b761995-02-13 12:00:46 +0000838{
839 char *dataptr;
840 Handle h;
841 int size;
842
Jack Janseneeccca91997-05-07 15:46:31 +0000843 if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000844 return NULL;
845 h = NewHandle(size);
846 if ( h == NULL ) {
847 PyErr_NoMemory();
848 return NULL;
849 }
850 HLock(h);
851 memcpy((char *)*h, dataptr, size);
852 HUnlock(h);
Jack Jansenf5c20571997-01-30 15:48:07 +0000853 return (PyObject *)newmfsaobject((AliasHandle)h);
Jack Jansenc889b761995-02-13 12:00:46 +0000854}
855
Jack Jansenf5c20571997-01-30 15:48:07 +0000856static PyObject *
Jack Jansen81f51c71995-02-20 15:45:25 +0000857mfs_GetDirectory(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000858 PyObject *self; /* Not used */
859 PyObject *args;
Jack Jansen81f51c71995-02-20 15:45:25 +0000860{
861 FSSpec fsdir;
862 int ok;
Jack Jansend5d5f461995-08-14 12:22:56 +0000863 char *prompt = NULL;
Jack Jansen81f51c71995-02-20 15:45:25 +0000864
Jack Jansenf5c20571997-01-30 15:48:07 +0000865 if (!PyArg_ParseTuple(args, "|s", &prompt) )
Jack Jansen81f51c71995-02-20 15:45:25 +0000866 return NULL;
867
Jack Jansend5d5f461995-08-14 12:22:56 +0000868 ok = PyMac_GetDirectory(&fsdir, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000869 return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
Jack Jansen81f51c71995-02-20 15:45:25 +0000870}
871
Jack Jansenf5c20571997-01-30 15:48:07 +0000872static PyObject *
Jack Jansen2c673621995-06-18 20:05:14 +0000873mfs_FindFolder(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000874 PyObject *self; /* Not used */
875 PyObject *args;
Jack Jansen2c673621995-06-18 20:05:14 +0000876{
877 OSErr err;
878 short where;
879 OSType which;
880 int create;
881 short refnum;
882 long dirid;
883
Jack Jansenf5c20571997-01-30 15:48:07 +0000884 if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
Jack Jansen2c673621995-06-18 20:05:14 +0000885 return NULL;
886 err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
887 if ( err ) {
888 PyErr_Mac(ErrorObject, err);
889 return NULL;
890 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000891 return Py_BuildValue("(ii)", refnum, dirid);
Jack Jansen2c673621995-06-18 20:05:14 +0000892}
893
Jack Jansenf5c20571997-01-30 15:48:07 +0000894static PyObject *
Jack Jansen924ca851996-09-20 15:25:16 +0000895mfs_FindApplication(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000896 PyObject *self; /* Not used */
897 PyObject *args;
Jack Jansen924ca851996-09-20 15:25:16 +0000898{
899 OSErr err;
900 OSType which;
901 FSSpec fss;
902
Jack Jansenf5c20571997-01-30 15:48:07 +0000903 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
Jack Jansen924ca851996-09-20 15:25:16 +0000904 return NULL;
905 err = FindApplicationFromCreator(which, &fss);
906 if ( err ) {
907 PyErr_Mac(ErrorObject, err);
908 return NULL;
909 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000910 return (PyObject *)newmfssobject(&fss);
Jack Jansen924ca851996-09-20 15:25:16 +0000911}
912
Jack Jansenf5c20571997-01-30 15:48:07 +0000913static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000914mfs_FInfo(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000915 PyObject *self;
916 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000917{
Jack Jansenf5c20571997-01-30 15:48:07 +0000918 return (PyObject *)newmfsiobject();
Jack Jansen3d185931995-08-07 14:04:10 +0000919}
920
Jack Jansend9936481997-06-16 14:31:38 +0000921static PyObject *
922mfs_NewAliasMinimalFromFullPath(self, args)
923 PyObject *self; /* Not used */
924 PyObject *args;
925{
926 OSErr err;
927 char *fullpath;
928 int fullpathlen;
929 AliasHandle alias;
930 Str32 zonename;
931 Str31 servername;
932
933 if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) )
934 return NULL;
935 zonename[0] = 0;
936 servername[0] = 0;
937 err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,
938 servername, &alias);
939 if ( err ) {
940 PyErr_Mac(ErrorObject, err);
941 return NULL;
942 }
943 return (PyObject *)newmfsaobject(alias);
944}
945
946
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000947/* List of methods defined in the module */
948
Jack Jansenf5c20571997-01-30 15:48:07 +0000949static struct PyMethodDef mfs_methods[] = {
Jack Jansen17ba43f1995-01-26 16:22:07 +0000950 {"ResolveAliasFile", mfs_ResolveAliasFile, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000951#ifndef TARGET_API_MAC_CARBON
Jack Jansen17ba43f1995-01-26 16:22:07 +0000952 {"StandardGetFile", mfs_StandardGetFile, 1},
Jack Jansend5d5f461995-08-14 12:22:56 +0000953 {"PromptGetFile", mfs_PromptGetFile, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000954 {"StandardPutFile", mfs_StandardPutFile, 1},
Jack Jansen81f51c71995-02-20 15:45:25 +0000955 {"GetDirectory", mfs_GetDirectory, 1},
Jack Jansend99d2831996-07-22 15:26:01 +0000956 {"SetFolder", mfs_SetFolder, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000957#endif
Jack Jansen17ba43f1995-01-26 16:22:07 +0000958 {"FSSpec", mfs_FSSpec, 1},
Jack Jansenc889b761995-02-13 12:00:46 +0000959 {"RawFSSpec", mfs_RawFSSpec, 1},
960 {"RawAlias", mfs_RawAlias, 1},
Jack Jansen2c673621995-06-18 20:05:14 +0000961 {"FindFolder", mfs_FindFolder, 1},
Jack Jansen924ca851996-09-20 15:25:16 +0000962 {"FindApplication", mfs_FindApplication, 1},
Jack Jansen3d185931995-08-07 14:04:10 +0000963 {"FInfo", mfs_FInfo, 1},
Jack Jansend9936481997-06-16 14:31:38 +0000964 {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1},
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000965
966 {NULL, NULL} /* sentinel */
967};
968
969
970/* Initialization function for the module (*must* be called initmacfs) */
971
972void
973initmacfs()
974{
Jack Jansenf5c20571997-01-30 15:48:07 +0000975 PyObject *m, *d;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000976
977 /* Create the module and add the functions */
Jack Jansenf5c20571997-01-30 15:48:07 +0000978 m = Py_InitModule("macfs", mfs_methods);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000979
980 /* Add some symbolic constants to the module */
Jack Jansenf5c20571997-01-30 15:48:07 +0000981 d = PyModule_GetDict(m);
Jack Jansen4377a1a2000-01-24 10:37:59 +0000982 ErrorObject = PyMac_GetOSErrException();
Jack Jansenf5c20571997-01-30 15:48:07 +0000983 PyDict_SetItemString(d, "error", ErrorObject);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000984
Jack Jansena755e681997-09-20 17:40:22 +0000985 Mfsatype.ob_type = &PyType_Type;
986 Py_INCREF(&Mfsatype);
987 PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype);
988 Mfsstype.ob_type = &PyType_Type;
989 Py_INCREF(&Mfsstype);
990 PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype);
991 Mfsitype.ob_type = &PyType_Type;
992 Py_INCREF(&Mfsitype);
993 PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000994 /* XXXX Add constants here */
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000995}