blob: 13dde93f99eb8383347526248d1ebc16f513d4e7 [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
Guido van Rossuma42960c1995-01-19 00:03:47 +000037#ifdef THINK_C
38#define FileFilterUPP FileFilterProcPtr
39#endif
40
Jack Jansenf5c20571997-01-30 15:48:07 +000041static PyObject *ErrorObject;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000042
43/* ----------------------------------------------------- */
Jack Jansen17ba43f1995-01-26 16:22:07 +000044/* Declarations for objects of type Alias */
45
46typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000047 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000048 AliasHandle alias;
49} mfsaobject;
50
Jack Jansenf5c20571997-01-30 15:48:07 +000051staticforward PyTypeObject Mfsatype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000052
53#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
54
55/* ---------------------------------------------------------------- */
56/* Declarations for objects of type FSSpec */
57
58typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000059 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000060 FSSpec fsspec;
61} mfssobject;
62
Jack Jansenf5c20571997-01-30 15:48:07 +000063staticforward PyTypeObject Mfsstype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000064
65#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
66
Guido van Rossumefd97671995-01-26 22:56:16 +000067
Jack Jansen3d185931995-08-07 14:04:10 +000068/* ---------------------------------------------------------------- */
69/* Declarations for objects of type FInfo */
70
71typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000072 PyObject_HEAD
Jack Jansen3d185931995-08-07 14:04:10 +000073 FInfo finfo;
74} mfsiobject;
75
Jack Jansenf5c20571997-01-30 15:48:07 +000076staticforward PyTypeObject Mfsitype;
Jack Jansen3d185931995-08-07 14:04:10 +000077
78#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
79
80
Guido van Rossumefd97671995-01-26 22:56:16 +000081mfssobject *newmfssobject(FSSpec *fss); /* Forward */
82
Jack Jansen17ba43f1995-01-26 16:22:07 +000083/* ---------------------------------------------------------------- */
Jack Jansen84fa5ec1995-01-18 14:04:40 +000084
Jack Jansenf5c20571997-01-30 15:48:07 +000085static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +000086mfsa_Resolve(self, args)
87 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +000088 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000089{
Jack Jansen17ba43f1995-01-26 16:22:07 +000090 FSSpec from, *fromp, result;
91 Boolean changed;
92 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000093
Jack Jansen17ba43f1995-01-26 16:22:07 +000094 from.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +000095 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
Jack Jansen84fa5ec1995-01-18 14:04:40 +000096 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +000097 if (from.name[0] )
98 fromp = &from;
99 else
100 fromp = NULL;
101 err = ResolveAlias(fromp, self->alias, &result, &changed);
Jack Jansend9936481997-06-16 14:31:38 +0000102 if ( err && err != fnfErr ) {
Jack Jansen17ba43f1995-01-26 16:22:07 +0000103 PyErr_Mac(ErrorObject, err);
104 return NULL;
105 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000106 return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000107}
108
Jack Jansenf5c20571997-01-30 15:48:07 +0000109static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000110mfsa_GetInfo(self, args)
111 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000112 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000113{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000114 Str63 value;
115 int i;
116 OSErr err;
117
Jack Jansenf5c20571997-01-30 15:48:07 +0000118 if (!PyArg_ParseTuple(args, "i", &i))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000119 return NULL;
120 err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
121 if ( err ) {
122 PyErr_Mac(ErrorObject, err);
123 return 0;
124 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000125 return PyString_FromStringAndSize((char *)&value[1], value[0]);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000126}
127
Jack Jansenf5c20571997-01-30 15:48:07 +0000128static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000129mfsa_Update(self, args)
130 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000131 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000132{
133 FSSpec target, fromfile, *fromfilep;
134 OSErr err;
135 Boolean changed;
136
137 fromfile.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000138 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target,
Jack Jansen17ba43f1995-01-26 16:22:07 +0000139 PyMac_GetFSSpec, &fromfile))
140 return NULL;
141 if ( fromfile.name[0] )
142 fromfilep = &fromfile;
143 else
144 fromfilep = NULL;
145 err = UpdateAlias(fromfilep, &target, self->alias, &changed);
146 if ( err ) {
147 PyErr_Mac(ErrorObject, err);
148 return 0;
149 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000150 return Py_BuildValue("i", (int)changed);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000151}
152
Jack Jansenf5c20571997-01-30 15:48:07 +0000153static struct PyMethodDef mfsa_methods[] = {
154 {"Resolve", (PyCFunction)mfsa_Resolve, 1},
155 {"GetInfo", (PyCFunction)mfsa_GetInfo, 1},
156 {"Update", (PyCFunction)mfsa_Update, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000157
158 {NULL, NULL} /* sentinel */
159};
160
161/* ---------- */
162
Jack Jansenf5c20571997-01-30 15:48:07 +0000163static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000164mfsa_getattr(self, name)
165 mfsaobject *self;
166 char *name;
167{
Jack Jansenc889b761995-02-13 12:00:46 +0000168 if ( strcmp(name, "data") == 0 ) {
169 int size;
170 PyObject *rv;
171
172 size = GetHandleSize((Handle)self->alias);
173 HLock((Handle)self->alias);
174 rv = PyString_FromStringAndSize(*(Handle)self->alias, size);
175 HUnlock((Handle)self->alias);
176 return rv;
177 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000178 return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000179}
180
181mfsaobject *
182newmfsaobject(alias)
183 AliasHandle alias;
184{
185 mfsaobject *self;
186
Jack Jansenf5c20571997-01-30 15:48:07 +0000187 self = PyObject_NEW(mfsaobject, &Mfsatype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000188 if (self == NULL)
189 return NULL;
190 self->alias = alias;
191 return self;
192}
193
194
195static void
196mfsa_dealloc(self)
197 mfsaobject *self;
198{
199#if 0
200 if ( self->alias ) {
201 should we do something here?
202 }
203#endif
204
Jack Jansenf5c20571997-01-30 15:48:07 +0000205 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000206}
207
Jack Jansenf5c20571997-01-30 15:48:07 +0000208statichere PyTypeObject Mfsatype = {
209 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000210 0, /*ob_size*/
211 "Alias", /*tp_name*/
212 sizeof(mfsaobject), /*tp_basicsize*/
213 0, /*tp_itemsize*/
214 /* methods */
215 (destructor)mfsa_dealloc, /*tp_dealloc*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000216 (printfunc)0, /*tp_print*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000217 (getattrfunc)mfsa_getattr, /*tp_getattr*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000218 (setattrfunc)0, /*tp_setattr*/
219 (cmpfunc)0, /*tp_compare*/
220 (reprfunc)0, /*tp_repr*/
221 0, /*tp_as_number*/
222 0, /*tp_as_sequence*/
223 0, /*tp_as_mapping*/
224 (hashfunc)0, /*tp_hash*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000225};
226
227/* End of code for Alias objects */
228/* -------------------------------------------------------- */
229
Jack Jansen3d185931995-08-07 14:04:10 +0000230/* ---------------------------------------------------------------- */
231
Jack Jansenf5c20571997-01-30 15:48:07 +0000232static struct PyMethodDef mfsi_methods[] = {
Jack Jansen3d185931995-08-07 14:04:10 +0000233
234 {NULL, NULL} /* sentinel */
235};
236
237/* ---------- */
238
239static mfsiobject *
240newmfsiobject()
241{
242 mfsiobject *self;
243
Jack Jansenf5c20571997-01-30 15:48:07 +0000244 self = PyObject_NEW(mfsiobject, &Mfsitype);
Jack Jansen3d185931995-08-07 14:04:10 +0000245 if (self == NULL)
246 return NULL;
247 memset((char *)&self->finfo, '\0', sizeof(self->finfo));
248 return self;
249}
250
251static void
252mfsi_dealloc(self)
253 mfsiobject *self;
254{
Jack Jansenf5c20571997-01-30 15:48:07 +0000255 PyMem_DEL(self);
Jack Jansen3d185931995-08-07 14:04:10 +0000256}
257
Jack Jansenf5c20571997-01-30 15:48:07 +0000258static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000259mfsi_getattr(self, name)
260 mfsiobject *self;
261 char *name;
262{
Jack Jansen3d185931995-08-07 14:04:10 +0000263 if ( strcmp(name, "Type") == 0 )
264 return PyMac_BuildOSType(self->finfo.fdType);
265 else if ( strcmp(name, "Creator") == 0 )
266 return PyMac_BuildOSType(self->finfo.fdCreator);
267 else if ( strcmp(name, "Flags") == 0 )
268 return Py_BuildValue("i", (int)self->finfo.fdFlags);
269 else if ( strcmp(name, "Location") == 0 )
270 return PyMac_BuildPoint(self->finfo.fdLocation);
271 else if ( strcmp(name, "Fldr") == 0 )
272 return Py_BuildValue("i", (int)self->finfo.fdFldr);
273 else
Jack Jansenf5c20571997-01-30 15:48:07 +0000274 return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
Jack Jansen3d185931995-08-07 14:04:10 +0000275}
276
277
278static int
279mfsi_setattr(self, name, v)
280 mfsiobject *self;
281 char *name;
Jack Jansenf5c20571997-01-30 15:48:07 +0000282 PyObject *v;
Jack Jansen3d185931995-08-07 14:04:10 +0000283{
284 int rv;
285 int i;
286
287 if ( v == NULL ) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000288 PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000289 return -1;
290 }
291 if ( strcmp(name, "Type") == 0 )
292 rv = PyMac_GetOSType(v, &self->finfo.fdType);
293 else if ( strcmp(name, "Creator") == 0 )
294 rv = PyMac_GetOSType(v, &self->finfo.fdCreator);
295 else if ( strcmp(name, "Flags") == 0 ) {
296 rv = PyArg_Parse(v, "i", &i);
297 self->finfo.fdFlags = (short)i;
298 } else if ( strcmp(name, "Location") == 0 )
299 rv = PyMac_GetPoint(v, &self->finfo.fdLocation);
300 else if ( strcmp(name, "Fldr") == 0 ) {
301 rv = PyArg_Parse(v, "i", &i);
302 self->finfo.fdFldr = (short)i;
303 } else {
Jack Jansenf5c20571997-01-30 15:48:07 +0000304 PyErr_SetString(PyExc_AttributeError, "No such attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000305 return -1;
306 }
307 if (rv)
308 return 0;
309 return -1;
310}
311
312
Jack Jansenf5c20571997-01-30 15:48:07 +0000313static PyTypeObject Mfsitype = {
314 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen3d185931995-08-07 14:04:10 +0000315 0, /*ob_size*/
Jack Jansena755e681997-09-20 17:40:22 +0000316 "FInfo", /*tp_name*/
Jack Jansen3d185931995-08-07 14:04:10 +0000317 sizeof(mfsiobject), /*tp_basicsize*/
318 0, /*tp_itemsize*/
319 /* methods */
320 (destructor)mfsi_dealloc, /*tp_dealloc*/
321 (printfunc)0, /*tp_print*/
322 (getattrfunc)mfsi_getattr, /*tp_getattr*/
323 (setattrfunc)mfsi_setattr, /*tp_setattr*/
324 (cmpfunc)0, /*tp_compare*/
325 (reprfunc)0, /*tp_repr*/
326 0, /*tp_as_number*/
327 0, /*tp_as_sequence*/
328 0, /*tp_as_mapping*/
329 (hashfunc)0, /*tp_hash*/
330};
331
332/* End of code for FInfo object objects */
333/* -------------------------------------------------------- */
334
335
Jack Jansen17ba43f1995-01-26 16:22:07 +0000336/*
337** Helper routine for other modules: return an FSSpec * if the
338** object is a python fsspec object, else NULL
339*/
340FSSpec *
341mfs_GetFSSpecFSSpec(self)
Jack Jansenf5c20571997-01-30 15:48:07 +0000342 PyObject *self;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000343{
344 if ( is_mfssobject(self) )
345 return &((mfssobject *)self)->fsspec;
346 return NULL;
347}
348
Jack Jansen0bdf9791996-09-15 22:11:25 +0000349/*
350** Two generally useful routines
351*/
352static OSErr
353PyMac_GetFileDates(fss, crdat, mddat, bkdat)
354 FSSpec *fss;
355 unsigned long *crdat, *mddat, *bkdat;
356{
357 CInfoPBRec pb;
358 OSErr error;
359
360 pb.dirInfo.ioNamePtr = fss->name;
361 pb.dirInfo.ioFDirIndex = 0;
362 pb.dirInfo.ioVRefNum = fss->vRefNum;
363 pb.dirInfo.ioDrDirID = fss->parID;
364 error = PBGetCatInfoSync(&pb);
365 if ( error ) return error;
366 *crdat = pb.hFileInfo.ioFlCrDat;
367 *mddat = pb.hFileInfo.ioFlMdDat;
368 *bkdat = pb.hFileInfo.ioFlBkDat;
369 return 0;
370}
371
372static OSErr
373PyMac_SetFileDates(fss, crdat, mddat, bkdat)
374 FSSpec *fss;
375 unsigned long crdat, mddat, bkdat;
376{
377 CInfoPBRec pb;
378 OSErr error;
379
380 pb.dirInfo.ioNamePtr = fss->name;
381 pb.dirInfo.ioFDirIndex = 0;
382 pb.dirInfo.ioVRefNum = fss->vRefNum;
383 pb.dirInfo.ioDrDirID = fss->parID;
384 error = PBGetCatInfoSync(&pb);
385 if ( error ) return error;
386 pb.dirInfo.ioNamePtr = fss->name;
387 pb.dirInfo.ioFDirIndex = 0;
388 pb.dirInfo.ioVRefNum = fss->vRefNum;
389 pb.dirInfo.ioDrDirID = fss->parID;
390 pb.hFileInfo.ioFlCrDat = crdat;
391 pb.hFileInfo.ioFlMdDat = mddat;
392 pb.hFileInfo.ioFlBkDat = bkdat;
393 error = PBSetCatInfoSync(&pb);
394 return error;
395}
396
Jack Jansenf5c20571997-01-30 15:48:07 +0000397static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000398mfss_as_pathname(self, args)
399 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000400 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000401{
402 char strbuf[257];
403 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000404
Jack Jansenf5c20571997-01-30 15:48:07 +0000405 if (!PyArg_ParseTuple(args, ""))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000406 return NULL;
Jack Jansen84fb1fa1996-11-09 18:46:57 +0000407 err = PyMac_GetFullPath(&self->fsspec, strbuf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000408 if ( err ) {
409 PyErr_Mac(ErrorObject, err);
410 return NULL;
411 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000412 return PyString_FromString(strbuf);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000413}
414
Jack Jansenf5c20571997-01-30 15:48:07 +0000415static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000416mfss_as_tuple(self, args)
417 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000418 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000419{
Jack Jansenf5c20571997-01-30 15:48:07 +0000420 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000421 return NULL;
422 return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
423 &self->fsspec.name[1], self->fsspec.name[0]);
424}
425
Jack Jansenf5c20571997-01-30 15:48:07 +0000426static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000427mfss_NewAlias(self, args)
428 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000429 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000430{
431 FSSpec src, *srcp;
432 OSErr err;
433 AliasHandle alias;
434
435 src.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000436 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000437 return NULL;
438 if ( src.name[0] )
439 srcp = &src;
440 else
441 srcp = NULL;
442 err = NewAlias(srcp, &self->fsspec, &alias);
443 if ( err ) {
444 PyErr_Mac(ErrorObject, err);
445 return NULL;
446 }
447
Jack Jansenf5c20571997-01-30 15:48:07 +0000448 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000449}
450
Jack Jansenf5c20571997-01-30 15:48:07 +0000451static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000452mfss_NewAliasMinimal(self, args)
453 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000454 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000455{
456 OSErr err;
457 AliasHandle alias;
458
Jack Jansenf5c20571997-01-30 15:48:07 +0000459 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000460 return NULL;
461 err = NewAliasMinimal(&self->fsspec, &alias);
462 if ( err ) {
463 PyErr_Mac(ErrorObject, err);
464 return NULL;
465 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000466 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000467}
468
Jack Jansen3d185931995-08-07 14:04:10 +0000469/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
Jack Jansenf5c20571997-01-30 15:48:07 +0000470static PyObject *
Jack Jansen8828fcf1995-02-02 14:23:52 +0000471mfss_GetCreatorType(self, args)
472 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000473 PyObject *args;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000474{
475 OSErr err;
476 FInfo info;
477
Jack Jansenf5c20571997-01-30 15:48:07 +0000478 if (!PyArg_ParseTuple(args, ""))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000479 return NULL;
480 err = FSpGetFInfo(&self->fsspec, &info);
481 if ( err ) {
482 PyErr_Mac(ErrorObject, err);
483 return NULL;
484 }
485 return Py_BuildValue("(O&O&)",
486 PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
487}
488
Jack Jansenf5c20571997-01-30 15:48:07 +0000489static PyObject *
Jack Jansen8828fcf1995-02-02 14:23:52 +0000490mfss_SetCreatorType(self, args)
491 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000492 PyObject *args;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000493{
494 OSErr err;
495 OSType creator, type;
496 FInfo info;
497
Jack Jansenf5c20571997-01-30 15:48:07 +0000498 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000499 return NULL;
500 err = FSpGetFInfo(&self->fsspec, &info);
501 if ( err ) {
502 PyErr_Mac(ErrorObject, err);
503 return NULL;
504 }
505 info.fdType = type;
506 info.fdCreator = creator;
507 err = FSpSetFInfo(&self->fsspec, &info);
508 if ( err ) {
509 PyErr_Mac(ErrorObject, err);
510 return NULL;
511 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000512 Py_INCREF(Py_None);
513 return Py_None;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000514}
515
Jack Jansenf5c20571997-01-30 15:48:07 +0000516static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000517mfss_GetFInfo(self, args)
518 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000519 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000520{
521 OSErr err;
522 mfsiobject *fip;
523
524
Jack Jansenf5c20571997-01-30 15:48:07 +0000525 if (!PyArg_ParseTuple(args, ""))
Jack Jansen3d185931995-08-07 14:04:10 +0000526 return NULL;
527 if ( (fip=newmfsiobject()) == NULL )
528 return NULL;
529 err = FSpGetFInfo(&self->fsspec, &fip->finfo);
530 if ( err ) {
531 PyErr_Mac(ErrorObject, err);
Jack Jansenf5c20571997-01-30 15:48:07 +0000532 Py_DECREF(fip);
Jack Jansen3d185931995-08-07 14:04:10 +0000533 return NULL;
534 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000535 return (PyObject *)fip;
Jack Jansen3d185931995-08-07 14:04:10 +0000536}
537
Jack Jansenf5c20571997-01-30 15:48:07 +0000538static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000539mfss_SetFInfo(self, args)
540 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000541 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000542{
543 OSErr err;
544 mfsiobject *fip;
545
Jack Jansenf5c20571997-01-30 15:48:07 +0000546 if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
Jack Jansen3d185931995-08-07 14:04:10 +0000547 return NULL;
548 err = FSpSetFInfo(&self->fsspec, &fip->finfo);
549 if ( err ) {
550 PyErr_Mac(ErrorObject, err);
551 return NULL;
552 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000553 Py_INCREF(Py_None);
554 return Py_None;
Jack Jansen3d185931995-08-07 14:04:10 +0000555}
556
Jack Jansenf5c20571997-01-30 15:48:07 +0000557static PyObject *
Jack Jansen0bdf9791996-09-15 22:11:25 +0000558mfss_GetDates(self, args)
559 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000560 PyObject *args;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000561{
562 OSErr err;
563 unsigned long crdat, mddat, bkdat;
564
Jack Jansenf5c20571997-01-30 15:48:07 +0000565 if (!PyArg_ParseTuple(args, ""))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000566 return NULL;
567 err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
568 if ( err ) {
569 PyErr_Mac(ErrorObject, err);
570 return NULL;
571 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000572 return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
Jack Jansen0bdf9791996-09-15 22:11:25 +0000573}
574
Jack Jansenf5c20571997-01-30 15:48:07 +0000575static PyObject *
Jack Jansen0bdf9791996-09-15 22:11:25 +0000576mfss_SetDates(self, args)
577 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000578 PyObject *args;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000579{
580 OSErr err;
581 double crdat, mddat, bkdat;
582
Jack Jansenf5c20571997-01-30 15:48:07 +0000583 if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000584 return NULL;
585 err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
586 (unsigned long)mddat, (unsigned long)bkdat);
587 if ( err ) {
588 PyErr_Mac(ErrorObject, err);
589 return NULL;
590 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000591 Py_INCREF(Py_None);
592 return Py_None;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000593}
594
Jack Jansenf5c20571997-01-30 15:48:07 +0000595static struct PyMethodDef mfss_methods[] = {
596 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
597 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
598 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
599 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
600 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
601 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
602 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
603 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
604 {"GetDates", (PyCFunction)mfss_GetDates, 1},
605 {"SetDates", (PyCFunction)mfss_SetDates, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000606
607 {NULL, NULL} /* sentinel */
608};
609
610/* ---------- */
611
Jack Jansenf5c20571997-01-30 15:48:07 +0000612static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000613mfss_getattr(self, name)
614 mfssobject *self;
615 char *name;
616{
Jack Jansenc889b761995-02-13 12:00:46 +0000617 if ( strcmp(name, "data") == 0)
618 return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
Jack Jansenf5c20571997-01-30 15:48:07 +0000619 return Py_FindMethod(mfss_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000620}
621
622mfssobject *
623newmfssobject(fss)
624 FSSpec *fss;
625{
626 mfssobject *self;
627
Jack Jansenf5c20571997-01-30 15:48:07 +0000628 self = PyObject_NEW(mfssobject, &Mfsstype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000629 if (self == NULL)
630 return NULL;
631 self->fsspec = *fss;
632 return self;
633}
634
635static void
636mfss_dealloc(self)
637 mfssobject *self;
638{
Jack Jansenf5c20571997-01-30 15:48:07 +0000639 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000640}
641
Jack Jansenf5c20571997-01-30 15:48:07 +0000642static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000643mfss_repr(self)
644 mfssobject *self;
645{
646 char buf[512];
647
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000648 sprintf(buf, "FSSpec((%d, %d, '%.*s'))",
649 self->fsspec.vRefNum,
650 self->fsspec.parID,
651 self->fsspec.name[0], self->fsspec.name+1);
Jack Jansenf5c20571997-01-30 15:48:07 +0000652 return PyString_FromString(buf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000653}
654
655static int
656mfss_compare(v, w)
657 mfssobject *v, *w;
658{
659 int minlen;
660 int res;
661
662 if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1;
663 if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1;
664 if ( v->fsspec.parID < w->fsspec.parID ) return -1;
665 if ( v->fsspec.parID > w->fsspec.parID ) return 1;
666 minlen = v->fsspec.name[0];
667 if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0];
668 res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen);
669 if ( res ) return res;
670 if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1;
671 if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1;
672 return res;
673}
674
Jack Jansenf5c20571997-01-30 15:48:07 +0000675statichere PyTypeObject Mfsstype = {
676 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000677 0, /*ob_size*/
678 "FSSpec", /*tp_name*/
679 sizeof(mfssobject), /*tp_basicsize*/
680 0, /*tp_itemsize*/
681 /* methods */
682 (destructor)mfss_dealloc, /*tp_dealloc*/
683 (printfunc)0, /*tp_print*/
684 (getattrfunc)mfss_getattr, /*tp_getattr*/
685 (setattrfunc)0, /*tp_setattr*/
686 (cmpfunc)mfss_compare, /*tp_compare*/
687 (reprfunc)mfss_repr, /*tp_repr*/
688 0, /*tp_as_number*/
689 0, /*tp_as_sequence*/
690 0, /*tp_as_mapping*/
691 (hashfunc)0, /*tp_hash*/
692};
693
694/* End of code for FSSpec objects */
695/* -------------------------------------------------------- */
696
Jack Jansenf5c20571997-01-30 15:48:07 +0000697static PyObject *
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000698mfs_ResolveAliasFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000699 PyObject *self; /* Not used */
700 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000701{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000702 FSSpec fss;
703 Boolean chain = 1, isfolder, wasaliased;
704 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000705
Jack Jansenf5c20571997-01-30 15:48:07 +0000706 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000707 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000708 err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
709 if ( err ) {
710 PyErr_Mac(ErrorObject, err);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000711 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000712 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000713 return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000714}
715
Jack Jansene79dc762000-06-02 21:35:07 +0000716#ifndef TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000717static PyObject *
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000718mfs_StandardGetFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000719 PyObject *self; /* Not used */
720 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000721{
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000722 SFTypeList list;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000723 short numtypes;
724 StandardFileReply reply;
725
726 list[0] = list[1] = list[2] = list[3] = 0;
727 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000728 if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
Jack Jansen17ba43f1995-01-26 16:22:07 +0000729 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
730 PyMac_GetOSType, &list[3]) )
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000731 return NULL;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000732 while ( numtypes < 4 && list[numtypes] ) {
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000733 numtypes++;
734 }
Jack Jansenc2632861995-06-03 21:15:50 +0000735 if ( numtypes == 0 )
736 numtypes = -1;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000737 StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000738 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000739}
740
Jack Jansenf5c20571997-01-30 15:48:07 +0000741static PyObject *
Jack Jansend5d5f461995-08-14 12:22:56 +0000742mfs_PromptGetFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000743 PyObject *self; /* Not used */
744 PyObject *args;
Jack Jansend5d5f461995-08-14 12:22:56 +0000745{
746 SFTypeList list;
747 short numtypes;
748 StandardFileReply reply;
749 char *prompt = NULL;
750
751 list[0] = list[1] = list[2] = list[3] = 0;
752 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000753 if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
Jack Jansend5d5f461995-08-14 12:22:56 +0000754 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
755 PyMac_GetOSType, &list[3]) )
756 return NULL;
757 while ( numtypes < 4 && list[numtypes] ) {
758 numtypes++;
759 }
760 if ( numtypes == 0 )
761 numtypes = -1;
762 PyMac_PromptGetFile(numtypes, list, &reply, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000763 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansend5d5f461995-08-14 12:22:56 +0000764}
765
Jack Jansenf5c20571997-01-30 15:48:07 +0000766static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000767mfs_StandardPutFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000768 PyObject *self; /* Not used */
769 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000770{
771 Str255 prompt, dft;
772 StandardFileReply reply;
773
774 dft[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000775 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
Jack Jansen17ba43f1995-01-26 16:22:07 +0000776 return NULL;
777 StandardPutFile(prompt, dft, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000778 return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000779}
780
Jack Jansend99d2831996-07-22 15:26:01 +0000781/*
782** Set initial directory for file dialogs */
Jack Jansenf5c20571997-01-30 15:48:07 +0000783static PyObject *
Jack Jansend99d2831996-07-22 15:26:01 +0000784mfs_SetFolder(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000785 PyObject *self;
786 PyObject *args;
Jack Jansend99d2831996-07-22 15:26:01 +0000787{
788 FSSpec spec;
789 FSSpec ospec;
790 short orefnum;
791 long oparid;
792
793 /* Get old values */
794 orefnum = -LMGetSFSaveDisk();
795 oparid = LMGetCurDirStore();
796 (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec);
797
798 /* Go to working directory by default */
799 (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
Jack Jansenf5c20571997-01-30 15:48:07 +0000800 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
Jack Jansend99d2831996-07-22 15:26:01 +0000801 return NULL;
802 /* Set standard-file working directory */
803 LMSetSFSaveDisk(-spec.vRefNum);
804 LMSetCurDirStore(spec.parID);
Jack Jansenf5c20571997-01-30 15:48:07 +0000805 return (PyObject *)newmfssobject(&ospec);
Jack Jansend99d2831996-07-22 15:26:01 +0000806}
Jack Jansene79dc762000-06-02 21:35:07 +0000807#endif
Jack Jansend99d2831996-07-22 15:26:01 +0000808
Jack Jansenf5c20571997-01-30 15:48:07 +0000809static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000810mfs_FSSpec(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000811 PyObject *self; /* Not used */
812 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000813{
814 FSSpec fss;
815
Jack Jansenf5c20571997-01-30 15:48:07 +0000816 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000817 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000818 return (PyObject *)newmfssobject(&fss);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000819}
820
Jack Jansenf5c20571997-01-30 15:48:07 +0000821static PyObject *
Jack Jansenc889b761995-02-13 12:00:46 +0000822mfs_RawFSSpec(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000823 PyObject *self; /* Not used */
824 PyObject *args;
Jack Jansenc889b761995-02-13 12:00:46 +0000825{
826 FSSpec *fssp;
827 int size;
828
Jack Janseneeccca91997-05-07 15:46:31 +0000829 if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000830 return NULL;
831 if ( size != sizeof(FSSpec) ) {
832 PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
833 return NULL;
834 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000835 return (PyObject *)newmfssobject(fssp);
Jack Jansenc889b761995-02-13 12:00:46 +0000836}
837
Jack Jansenf5c20571997-01-30 15:48:07 +0000838static PyObject *
Jack Jansenc889b761995-02-13 12:00:46 +0000839mfs_RawAlias(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000840 PyObject *self; /* Not used */
841 PyObject *args;
Jack Jansenc889b761995-02-13 12:00:46 +0000842{
843 char *dataptr;
844 Handle h;
845 int size;
846
Jack Janseneeccca91997-05-07 15:46:31 +0000847 if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000848 return NULL;
849 h = NewHandle(size);
850 if ( h == NULL ) {
851 PyErr_NoMemory();
852 return NULL;
853 }
854 HLock(h);
855 memcpy((char *)*h, dataptr, size);
856 HUnlock(h);
Jack Jansenf5c20571997-01-30 15:48:07 +0000857 return (PyObject *)newmfsaobject((AliasHandle)h);
Jack Jansenc889b761995-02-13 12:00:46 +0000858}
859
Jack Jansenf5c20571997-01-30 15:48:07 +0000860static PyObject *
Jack Jansen81f51c71995-02-20 15:45:25 +0000861mfs_GetDirectory(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000862 PyObject *self; /* Not used */
863 PyObject *args;
Jack Jansen81f51c71995-02-20 15:45:25 +0000864{
865 FSSpec fsdir;
866 int ok;
Jack Jansend5d5f461995-08-14 12:22:56 +0000867 char *prompt = NULL;
Jack Jansen81f51c71995-02-20 15:45:25 +0000868
Jack Jansenf5c20571997-01-30 15:48:07 +0000869 if (!PyArg_ParseTuple(args, "|s", &prompt) )
Jack Jansen81f51c71995-02-20 15:45:25 +0000870 return NULL;
871
Jack Jansend5d5f461995-08-14 12:22:56 +0000872 ok = PyMac_GetDirectory(&fsdir, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000873 return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
Jack Jansen81f51c71995-02-20 15:45:25 +0000874}
875
Jack Jansenf5c20571997-01-30 15:48:07 +0000876static PyObject *
Jack Jansen2c673621995-06-18 20:05:14 +0000877mfs_FindFolder(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000878 PyObject *self; /* Not used */
879 PyObject *args;
Jack Jansen2c673621995-06-18 20:05:14 +0000880{
881 OSErr err;
882 short where;
883 OSType which;
884 int create;
885 short refnum;
886 long dirid;
887
Jack Jansenf5c20571997-01-30 15:48:07 +0000888 if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
Jack Jansen2c673621995-06-18 20:05:14 +0000889 return NULL;
890 err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
891 if ( err ) {
892 PyErr_Mac(ErrorObject, err);
893 return NULL;
894 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000895 return Py_BuildValue("(ii)", refnum, dirid);
Jack Jansen2c673621995-06-18 20:05:14 +0000896}
897
Jack Jansenf5c20571997-01-30 15:48:07 +0000898static PyObject *
Jack Jansen924ca851996-09-20 15:25:16 +0000899mfs_FindApplication(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000900 PyObject *self; /* Not used */
901 PyObject *args;
Jack Jansen924ca851996-09-20 15:25:16 +0000902{
903 OSErr err;
904 OSType which;
905 FSSpec fss;
906
Jack Jansenf5c20571997-01-30 15:48:07 +0000907 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
Jack Jansen924ca851996-09-20 15:25:16 +0000908 return NULL;
909 err = FindApplicationFromCreator(which, &fss);
910 if ( err ) {
911 PyErr_Mac(ErrorObject, err);
912 return NULL;
913 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000914 return (PyObject *)newmfssobject(&fss);
Jack Jansen924ca851996-09-20 15:25:16 +0000915}
916
Jack Jansenf5c20571997-01-30 15:48:07 +0000917static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000918mfs_FInfo(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000919 PyObject *self;
920 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000921{
Jack Jansenf5c20571997-01-30 15:48:07 +0000922 return (PyObject *)newmfsiobject();
Jack Jansen3d185931995-08-07 14:04:10 +0000923}
924
Jack Jansend9936481997-06-16 14:31:38 +0000925static PyObject *
926mfs_NewAliasMinimalFromFullPath(self, args)
927 PyObject *self; /* Not used */
928 PyObject *args;
929{
930 OSErr err;
931 char *fullpath;
932 int fullpathlen;
933 AliasHandle alias;
934 Str32 zonename;
935 Str31 servername;
936
937 if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) )
938 return NULL;
939 zonename[0] = 0;
940 servername[0] = 0;
941 err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,
942 servername, &alias);
943 if ( err ) {
944 PyErr_Mac(ErrorObject, err);
945 return NULL;
946 }
947 return (PyObject *)newmfsaobject(alias);
948}
949
950
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000951/* List of methods defined in the module */
952
Jack Jansenf5c20571997-01-30 15:48:07 +0000953static struct PyMethodDef mfs_methods[] = {
Jack Jansen17ba43f1995-01-26 16:22:07 +0000954 {"ResolveAliasFile", mfs_ResolveAliasFile, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000955#ifndef TARGET_API_MAC_CARBON
Jack Jansen17ba43f1995-01-26 16:22:07 +0000956 {"StandardGetFile", mfs_StandardGetFile, 1},
Jack Jansend5d5f461995-08-14 12:22:56 +0000957 {"PromptGetFile", mfs_PromptGetFile, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000958 {"StandardPutFile", mfs_StandardPutFile, 1},
Jack Jansen81f51c71995-02-20 15:45:25 +0000959 {"GetDirectory", mfs_GetDirectory, 1},
Jack Jansend99d2831996-07-22 15:26:01 +0000960 {"SetFolder", mfs_SetFolder, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000961#endif
Jack Jansen17ba43f1995-01-26 16:22:07 +0000962 {"FSSpec", mfs_FSSpec, 1},
Jack Jansenc889b761995-02-13 12:00:46 +0000963 {"RawFSSpec", mfs_RawFSSpec, 1},
964 {"RawAlias", mfs_RawAlias, 1},
Jack Jansen2c673621995-06-18 20:05:14 +0000965 {"FindFolder", mfs_FindFolder, 1},
Jack Jansen924ca851996-09-20 15:25:16 +0000966 {"FindApplication", mfs_FindApplication, 1},
Jack Jansen3d185931995-08-07 14:04:10 +0000967 {"FInfo", mfs_FInfo, 1},
Jack Jansend9936481997-06-16 14:31:38 +0000968 {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1},
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000969
970 {NULL, NULL} /* sentinel */
971};
972
973
974/* Initialization function for the module (*must* be called initmacfs) */
975
976void
977initmacfs()
978{
Jack Jansenf5c20571997-01-30 15:48:07 +0000979 PyObject *m, *d;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000980
981 /* Create the module and add the functions */
Jack Jansenf5c20571997-01-30 15:48:07 +0000982 m = Py_InitModule("macfs", mfs_methods);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000983
984 /* Add some symbolic constants to the module */
Jack Jansenf5c20571997-01-30 15:48:07 +0000985 d = PyModule_GetDict(m);
Jack Jansen4377a1a2000-01-24 10:37:59 +0000986 ErrorObject = PyMac_GetOSErrException();
Jack Jansenf5c20571997-01-30 15:48:07 +0000987 PyDict_SetItemString(d, "error", ErrorObject);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000988
Jack Jansena755e681997-09-20 17:40:22 +0000989 Mfsatype.ob_type = &PyType_Type;
990 Py_INCREF(&Mfsatype);
991 PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype);
992 Mfsstype.ob_type = &PyType_Type;
993 Py_INCREF(&Mfsstype);
994 PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype);
995 Mfsitype.ob_type = &PyType_Type;
996 Py_INCREF(&Mfsitype);
997 PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000998 /* XXXX Add constants here */
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000999}