blob: ca8b767e3ff7f104d03460072f22874b0f87d3e8 [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 Jansen9ae898b2000-07-11 21:16:03 +000037/* Should this be in macglue.h? */
38extern FSSpec *mfs_GetFSSpecFSSpec(PyObject *);
39
Jack Jansenf5c20571997-01-30 15:48:07 +000040static PyObject *ErrorObject;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000041
42/* ----------------------------------------------------- */
Jack Jansen17ba43f1995-01-26 16:22:07 +000043/* Declarations for objects of type Alias */
44
45typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000046 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000047 AliasHandle alias;
48} mfsaobject;
49
Jack Jansenf5c20571997-01-30 15:48:07 +000050staticforward PyTypeObject Mfsatype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000051
52#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
53
54/* ---------------------------------------------------------------- */
55/* Declarations for objects of type FSSpec */
56
57typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000058 PyObject_HEAD
Jack Jansen17ba43f1995-01-26 16:22:07 +000059 FSSpec fsspec;
60} mfssobject;
61
Jack Jansenf5c20571997-01-30 15:48:07 +000062staticforward PyTypeObject Mfsstype;
Jack Jansen17ba43f1995-01-26 16:22:07 +000063
64#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
65
Guido van Rossumefd97671995-01-26 22:56:16 +000066
Jack Jansen3d185931995-08-07 14:04:10 +000067/* ---------------------------------------------------------------- */
68/* Declarations for objects of type FInfo */
69
70typedef struct {
Jack Jansenf5c20571997-01-30 15:48:07 +000071 PyObject_HEAD
Jack Jansen3d185931995-08-07 14:04:10 +000072 FInfo finfo;
73} mfsiobject;
74
Jack Jansenf5c20571997-01-30 15:48:07 +000075staticforward PyTypeObject Mfsitype;
Jack Jansen3d185931995-08-07 14:04:10 +000076
77#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
78
79
Guido van Rossumefd97671995-01-26 22:56:16 +000080mfssobject *newmfssobject(FSSpec *fss); /* Forward */
81
Jack Jansen17ba43f1995-01-26 16:22:07 +000082/* ---------------------------------------------------------------- */
Jack Jansen84fa5ec1995-01-18 14:04:40 +000083
Jack Jansenf5c20571997-01-30 15:48:07 +000084static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +000085mfsa_Resolve(self, args)
86 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +000087 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000088{
Jack Jansen17ba43f1995-01-26 16:22:07 +000089 FSSpec from, *fromp, result;
90 Boolean changed;
91 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000092
Jack Jansen17ba43f1995-01-26 16:22:07 +000093 from.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +000094 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
Jack Jansen84fa5ec1995-01-18 14:04:40 +000095 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +000096 if (from.name[0] )
97 fromp = &from;
98 else
99 fromp = NULL;
100 err = ResolveAlias(fromp, self->alias, &result, &changed);
Jack Jansend9936481997-06-16 14:31:38 +0000101 if ( err && err != fnfErr ) {
Jack Jansen17ba43f1995-01-26 16:22:07 +0000102 PyErr_Mac(ErrorObject, err);
103 return NULL;
104 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000105 return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000106}
107
Jack Jansenf5c20571997-01-30 15:48:07 +0000108static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000109mfsa_GetInfo(self, args)
110 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000111 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000112{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000113 Str63 value;
114 int i;
115 OSErr err;
116
Jack Jansenf5c20571997-01-30 15:48:07 +0000117 if (!PyArg_ParseTuple(args, "i", &i))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000118 return NULL;
119 err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
120 if ( err ) {
121 PyErr_Mac(ErrorObject, err);
122 return 0;
123 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000124 return PyString_FromStringAndSize((char *)&value[1], value[0]);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000125}
126
Jack Jansenf5c20571997-01-30 15:48:07 +0000127static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000128mfsa_Update(self, args)
129 mfsaobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000130 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000131{
132 FSSpec target, fromfile, *fromfilep;
133 OSErr err;
134 Boolean changed;
135
136 fromfile.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000137 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target,
Jack Jansen17ba43f1995-01-26 16:22:07 +0000138 PyMac_GetFSSpec, &fromfile))
139 return NULL;
140 if ( fromfile.name[0] )
141 fromfilep = &fromfile;
142 else
143 fromfilep = NULL;
144 err = UpdateAlias(fromfilep, &target, self->alias, &changed);
145 if ( err ) {
146 PyErr_Mac(ErrorObject, err);
147 return 0;
148 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000149 return Py_BuildValue("i", (int)changed);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000150}
151
Jack Jansenf5c20571997-01-30 15:48:07 +0000152static struct PyMethodDef mfsa_methods[] = {
153 {"Resolve", (PyCFunction)mfsa_Resolve, 1},
154 {"GetInfo", (PyCFunction)mfsa_GetInfo, 1},
155 {"Update", (PyCFunction)mfsa_Update, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000156
157 {NULL, NULL} /* sentinel */
158};
159
160/* ---------- */
161
Jack Jansenf5c20571997-01-30 15:48:07 +0000162static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000163mfsa_getattr(self, name)
164 mfsaobject *self;
165 char *name;
166{
Jack Jansenc889b761995-02-13 12:00:46 +0000167 if ( strcmp(name, "data") == 0 ) {
168 int size;
169 PyObject *rv;
170
171 size = GetHandleSize((Handle)self->alias);
172 HLock((Handle)self->alias);
173 rv = PyString_FromStringAndSize(*(Handle)self->alias, size);
174 HUnlock((Handle)self->alias);
175 return rv;
176 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000177 return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000178}
179
Jack Jansen9ae898b2000-07-11 21:16:03 +0000180static mfsaobject *
181newmfsaobject(AliasHandle alias)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000182{
183 mfsaobject *self;
184
Jack Jansenf5c20571997-01-30 15:48:07 +0000185 self = PyObject_NEW(mfsaobject, &Mfsatype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000186 if (self == NULL)
187 return NULL;
188 self->alias = alias;
189 return self;
190}
191
192
193static void
194mfsa_dealloc(self)
195 mfsaobject *self;
196{
197#if 0
198 if ( self->alias ) {
199 should we do something here?
200 }
201#endif
202
Jack Jansenf5c20571997-01-30 15:48:07 +0000203 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000204}
205
Jack Jansenf5c20571997-01-30 15:48:07 +0000206statichere PyTypeObject Mfsatype = {
207 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000208 0, /*ob_size*/
209 "Alias", /*tp_name*/
210 sizeof(mfsaobject), /*tp_basicsize*/
211 0, /*tp_itemsize*/
212 /* methods */
213 (destructor)mfsa_dealloc, /*tp_dealloc*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000214 (printfunc)0, /*tp_print*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000215 (getattrfunc)mfsa_getattr, /*tp_getattr*/
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000216 (setattrfunc)0, /*tp_setattr*/
217 (cmpfunc)0, /*tp_compare*/
218 (reprfunc)0, /*tp_repr*/
219 0, /*tp_as_number*/
220 0, /*tp_as_sequence*/
221 0, /*tp_as_mapping*/
222 (hashfunc)0, /*tp_hash*/
Jack Jansen17ba43f1995-01-26 16:22:07 +0000223};
224
225/* End of code for Alias objects */
226/* -------------------------------------------------------- */
227
Jack Jansen3d185931995-08-07 14:04:10 +0000228/* ---------------------------------------------------------------- */
229
Jack Jansenf5c20571997-01-30 15:48:07 +0000230static struct PyMethodDef mfsi_methods[] = {
Jack Jansen3d185931995-08-07 14:04:10 +0000231
232 {NULL, NULL} /* sentinel */
233};
234
235/* ---------- */
236
237static mfsiobject *
238newmfsiobject()
239{
240 mfsiobject *self;
241
Jack Jansenf5c20571997-01-30 15:48:07 +0000242 self = PyObject_NEW(mfsiobject, &Mfsitype);
Jack Jansen3d185931995-08-07 14:04:10 +0000243 if (self == NULL)
244 return NULL;
245 memset((char *)&self->finfo, '\0', sizeof(self->finfo));
246 return self;
247}
248
249static void
250mfsi_dealloc(self)
251 mfsiobject *self;
252{
Jack Jansenf5c20571997-01-30 15:48:07 +0000253 PyMem_DEL(self);
Jack Jansen3d185931995-08-07 14:04:10 +0000254}
255
Jack Jansenf5c20571997-01-30 15:48:07 +0000256static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000257mfsi_getattr(self, name)
258 mfsiobject *self;
259 char *name;
260{
Jack Jansen3d185931995-08-07 14:04:10 +0000261 if ( strcmp(name, "Type") == 0 )
262 return PyMac_BuildOSType(self->finfo.fdType);
263 else if ( strcmp(name, "Creator") == 0 )
264 return PyMac_BuildOSType(self->finfo.fdCreator);
265 else if ( strcmp(name, "Flags") == 0 )
266 return Py_BuildValue("i", (int)self->finfo.fdFlags);
267 else if ( strcmp(name, "Location") == 0 )
268 return PyMac_BuildPoint(self->finfo.fdLocation);
269 else if ( strcmp(name, "Fldr") == 0 )
270 return Py_BuildValue("i", (int)self->finfo.fdFldr);
271 else
Jack Jansenf5c20571997-01-30 15:48:07 +0000272 return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
Jack Jansen3d185931995-08-07 14:04:10 +0000273}
274
275
276static int
277mfsi_setattr(self, name, v)
278 mfsiobject *self;
279 char *name;
Jack Jansenf5c20571997-01-30 15:48:07 +0000280 PyObject *v;
Jack Jansen3d185931995-08-07 14:04:10 +0000281{
282 int rv;
283 int i;
284
285 if ( v == NULL ) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000286 PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000287 return -1;
288 }
289 if ( strcmp(name, "Type") == 0 )
290 rv = PyMac_GetOSType(v, &self->finfo.fdType);
291 else if ( strcmp(name, "Creator") == 0 )
292 rv = PyMac_GetOSType(v, &self->finfo.fdCreator);
293 else if ( strcmp(name, "Flags") == 0 ) {
294 rv = PyArg_Parse(v, "i", &i);
295 self->finfo.fdFlags = (short)i;
296 } else if ( strcmp(name, "Location") == 0 )
297 rv = PyMac_GetPoint(v, &self->finfo.fdLocation);
298 else if ( strcmp(name, "Fldr") == 0 ) {
299 rv = PyArg_Parse(v, "i", &i);
300 self->finfo.fdFldr = (short)i;
301 } else {
Jack Jansenf5c20571997-01-30 15:48:07 +0000302 PyErr_SetString(PyExc_AttributeError, "No such attribute");
Jack Jansen3d185931995-08-07 14:04:10 +0000303 return -1;
304 }
305 if (rv)
306 return 0;
307 return -1;
308}
309
310
Jack Jansenf5c20571997-01-30 15:48:07 +0000311static PyTypeObject Mfsitype = {
312 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen3d185931995-08-07 14:04:10 +0000313 0, /*ob_size*/
Jack Jansena755e681997-09-20 17:40:22 +0000314 "FInfo", /*tp_name*/
Jack Jansen3d185931995-08-07 14:04:10 +0000315 sizeof(mfsiobject), /*tp_basicsize*/
316 0, /*tp_itemsize*/
317 /* methods */
318 (destructor)mfsi_dealloc, /*tp_dealloc*/
319 (printfunc)0, /*tp_print*/
320 (getattrfunc)mfsi_getattr, /*tp_getattr*/
321 (setattrfunc)mfsi_setattr, /*tp_setattr*/
322 (cmpfunc)0, /*tp_compare*/
323 (reprfunc)0, /*tp_repr*/
324 0, /*tp_as_number*/
325 0, /*tp_as_sequence*/
326 0, /*tp_as_mapping*/
327 (hashfunc)0, /*tp_hash*/
328};
329
330/* End of code for FInfo object objects */
331/* -------------------------------------------------------- */
332
333
Jack Jansen17ba43f1995-01-26 16:22:07 +0000334/*
335** Helper routine for other modules: return an FSSpec * if the
336** object is a python fsspec object, else NULL
337*/
338FSSpec *
Jack Jansen9ae898b2000-07-11 21:16:03 +0000339mfs_GetFSSpecFSSpec(PyObject *self)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000340{
341 if ( is_mfssobject(self) )
342 return &((mfssobject *)self)->fsspec;
343 return NULL;
344}
345
Jack Jansen0bdf9791996-09-15 22:11:25 +0000346/*
347** Two generally useful routines
348*/
349static OSErr
350PyMac_GetFileDates(fss, crdat, mddat, bkdat)
351 FSSpec *fss;
352 unsigned long *crdat, *mddat, *bkdat;
353{
354 CInfoPBRec pb;
355 OSErr error;
356
357 pb.dirInfo.ioNamePtr = fss->name;
358 pb.dirInfo.ioFDirIndex = 0;
359 pb.dirInfo.ioVRefNum = fss->vRefNum;
360 pb.dirInfo.ioDrDirID = fss->parID;
361 error = PBGetCatInfoSync(&pb);
362 if ( error ) return error;
363 *crdat = pb.hFileInfo.ioFlCrDat;
364 *mddat = pb.hFileInfo.ioFlMdDat;
365 *bkdat = pb.hFileInfo.ioFlBkDat;
366 return 0;
367}
368
369static OSErr
370PyMac_SetFileDates(fss, crdat, mddat, bkdat)
371 FSSpec *fss;
372 unsigned long crdat, mddat, bkdat;
373{
374 CInfoPBRec pb;
375 OSErr error;
376
377 pb.dirInfo.ioNamePtr = fss->name;
378 pb.dirInfo.ioFDirIndex = 0;
379 pb.dirInfo.ioVRefNum = fss->vRefNum;
380 pb.dirInfo.ioDrDirID = fss->parID;
381 error = PBGetCatInfoSync(&pb);
382 if ( error ) return error;
383 pb.dirInfo.ioNamePtr = fss->name;
384 pb.dirInfo.ioFDirIndex = 0;
385 pb.dirInfo.ioVRefNum = fss->vRefNum;
386 pb.dirInfo.ioDrDirID = fss->parID;
387 pb.hFileInfo.ioFlCrDat = crdat;
388 pb.hFileInfo.ioFlMdDat = mddat;
389 pb.hFileInfo.ioFlBkDat = bkdat;
390 error = PBSetCatInfoSync(&pb);
391 return error;
392}
393
Jack Jansenf5c20571997-01-30 15:48:07 +0000394static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000395mfss_as_pathname(self, args)
396 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000397 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000398{
399 char strbuf[257];
400 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000401
Jack Jansenf5c20571997-01-30 15:48:07 +0000402 if (!PyArg_ParseTuple(args, ""))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000403 return NULL;
Jack Jansen84fb1fa1996-11-09 18:46:57 +0000404 err = PyMac_GetFullPath(&self->fsspec, strbuf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000405 if ( err ) {
406 PyErr_Mac(ErrorObject, err);
407 return NULL;
408 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000409 return PyString_FromString(strbuf);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000410}
411
Jack Jansenf5c20571997-01-30 15:48:07 +0000412static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000413mfss_as_tuple(self, args)
414 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000415 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000416{
Jack Jansenf5c20571997-01-30 15:48:07 +0000417 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000418 return NULL;
419 return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
420 &self->fsspec.name[1], self->fsspec.name[0]);
421}
422
Jack Jansenf5c20571997-01-30 15:48:07 +0000423static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000424mfss_NewAlias(self, args)
425 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000426 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000427{
428 FSSpec src, *srcp;
429 OSErr err;
430 AliasHandle alias;
431
432 src.name[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000433 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000434 return NULL;
435 if ( src.name[0] )
436 srcp = &src;
437 else
438 srcp = NULL;
439 err = NewAlias(srcp, &self->fsspec, &alias);
440 if ( err ) {
441 PyErr_Mac(ErrorObject, err);
442 return NULL;
443 }
444
Jack Jansenf5c20571997-01-30 15:48:07 +0000445 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000446}
447
Jack Jansenf5c20571997-01-30 15:48:07 +0000448static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000449mfss_NewAliasMinimal(self, args)
450 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000451 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000452{
453 OSErr err;
454 AliasHandle alias;
455
Jack Jansenf5c20571997-01-30 15:48:07 +0000456 if (!PyArg_ParseTuple(args, ""))
Jack Jansen17ba43f1995-01-26 16:22:07 +0000457 return NULL;
458 err = NewAliasMinimal(&self->fsspec, &alias);
459 if ( err ) {
460 PyErr_Mac(ErrorObject, err);
461 return NULL;
462 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000463 return (PyObject *)newmfsaobject(alias);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000464}
465
Jack Jansen3d185931995-08-07 14:04:10 +0000466/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
Jack Jansenf5c20571997-01-30 15:48:07 +0000467static PyObject *
Jack Jansen8828fcf1995-02-02 14:23:52 +0000468mfss_GetCreatorType(self, args)
469 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000470 PyObject *args;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000471{
472 OSErr err;
473 FInfo info;
474
Jack Jansenf5c20571997-01-30 15:48:07 +0000475 if (!PyArg_ParseTuple(args, ""))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000476 return NULL;
477 err = FSpGetFInfo(&self->fsspec, &info);
478 if ( err ) {
479 PyErr_Mac(ErrorObject, err);
480 return NULL;
481 }
482 return Py_BuildValue("(O&O&)",
483 PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
484}
485
Jack Jansenf5c20571997-01-30 15:48:07 +0000486static PyObject *
Jack Jansen8828fcf1995-02-02 14:23:52 +0000487mfss_SetCreatorType(self, args)
488 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000489 PyObject *args;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000490{
491 OSErr err;
492 OSType creator, type;
493 FInfo info;
494
Jack Jansenf5c20571997-01-30 15:48:07 +0000495 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
Jack Jansen8828fcf1995-02-02 14:23:52 +0000496 return NULL;
497 err = FSpGetFInfo(&self->fsspec, &info);
498 if ( err ) {
499 PyErr_Mac(ErrorObject, err);
500 return NULL;
501 }
502 info.fdType = type;
503 info.fdCreator = creator;
504 err = FSpSetFInfo(&self->fsspec, &info);
505 if ( err ) {
506 PyErr_Mac(ErrorObject, err);
507 return NULL;
508 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000509 Py_INCREF(Py_None);
510 return Py_None;
Jack Jansen8828fcf1995-02-02 14:23:52 +0000511}
512
Jack Jansenf5c20571997-01-30 15:48:07 +0000513static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000514mfss_GetFInfo(self, args)
515 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000516 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000517{
518 OSErr err;
519 mfsiobject *fip;
520
521
Jack Jansenf5c20571997-01-30 15:48:07 +0000522 if (!PyArg_ParseTuple(args, ""))
Jack Jansen3d185931995-08-07 14:04:10 +0000523 return NULL;
524 if ( (fip=newmfsiobject()) == NULL )
525 return NULL;
526 err = FSpGetFInfo(&self->fsspec, &fip->finfo);
527 if ( err ) {
528 PyErr_Mac(ErrorObject, err);
Jack Jansenf5c20571997-01-30 15:48:07 +0000529 Py_DECREF(fip);
Jack Jansen3d185931995-08-07 14:04:10 +0000530 return NULL;
531 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000532 return (PyObject *)fip;
Jack Jansen3d185931995-08-07 14:04:10 +0000533}
534
Jack Jansenf5c20571997-01-30 15:48:07 +0000535static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000536mfss_SetFInfo(self, args)
537 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000538 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000539{
540 OSErr err;
541 mfsiobject *fip;
542
Jack Jansenf5c20571997-01-30 15:48:07 +0000543 if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
Jack Jansen3d185931995-08-07 14:04:10 +0000544 return NULL;
545 err = FSpSetFInfo(&self->fsspec, &fip->finfo);
546 if ( err ) {
547 PyErr_Mac(ErrorObject, err);
548 return NULL;
549 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000550 Py_INCREF(Py_None);
551 return Py_None;
Jack Jansen3d185931995-08-07 14:04:10 +0000552}
553
Jack Jansenf5c20571997-01-30 15:48:07 +0000554static PyObject *
Jack Jansen0bdf9791996-09-15 22:11:25 +0000555mfss_GetDates(self, args)
556 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000557 PyObject *args;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000558{
559 OSErr err;
560 unsigned long crdat, mddat, bkdat;
561
Jack Jansenf5c20571997-01-30 15:48:07 +0000562 if (!PyArg_ParseTuple(args, ""))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000563 return NULL;
564 err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
565 if ( err ) {
566 PyErr_Mac(ErrorObject, err);
567 return NULL;
568 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000569 return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
Jack Jansen0bdf9791996-09-15 22:11:25 +0000570}
571
Jack Jansenf5c20571997-01-30 15:48:07 +0000572static PyObject *
Jack Jansen0bdf9791996-09-15 22:11:25 +0000573mfss_SetDates(self, args)
574 mfssobject *self;
Jack Jansenf5c20571997-01-30 15:48:07 +0000575 PyObject *args;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000576{
577 OSErr err;
578 double crdat, mddat, bkdat;
579
Jack Jansenf5c20571997-01-30 15:48:07 +0000580 if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
Jack Jansen0bdf9791996-09-15 22:11:25 +0000581 return NULL;
582 err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
583 (unsigned long)mddat, (unsigned long)bkdat);
584 if ( err ) {
585 PyErr_Mac(ErrorObject, err);
586 return NULL;
587 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000588 Py_INCREF(Py_None);
589 return Py_None;
Jack Jansen0bdf9791996-09-15 22:11:25 +0000590}
591
Jack Jansenf5c20571997-01-30 15:48:07 +0000592static struct PyMethodDef mfss_methods[] = {
593 {"as_pathname", (PyCFunction)mfss_as_pathname, 1},
594 {"as_tuple", (PyCFunction)mfss_as_tuple, 1},
595 {"NewAlias", (PyCFunction)mfss_NewAlias, 1},
596 {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
597 {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
598 {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
599 {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
600 {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
601 {"GetDates", (PyCFunction)mfss_GetDates, 1},
602 {"SetDates", (PyCFunction)mfss_SetDates, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000603
604 {NULL, NULL} /* sentinel */
605};
606
607/* ---------- */
608
Jack Jansenf5c20571997-01-30 15:48:07 +0000609static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000610mfss_getattr(self, name)
611 mfssobject *self;
612 char *name;
613{
Jack Jansenc889b761995-02-13 12:00:46 +0000614 if ( strcmp(name, "data") == 0)
615 return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
Jack Jansenf5c20571997-01-30 15:48:07 +0000616 return Py_FindMethod(mfss_methods, (PyObject *)self, name);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000617}
618
619mfssobject *
620newmfssobject(fss)
621 FSSpec *fss;
622{
623 mfssobject *self;
624
Jack Jansenf5c20571997-01-30 15:48:07 +0000625 self = PyObject_NEW(mfssobject, &Mfsstype);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000626 if (self == NULL)
627 return NULL;
628 self->fsspec = *fss;
629 return self;
630}
631
632static void
633mfss_dealloc(self)
634 mfssobject *self;
635{
Jack Jansenf5c20571997-01-30 15:48:07 +0000636 PyMem_DEL(self);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000637}
638
Jack Jansenf5c20571997-01-30 15:48:07 +0000639static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000640mfss_repr(self)
641 mfssobject *self;
642{
643 char buf[512];
644
Guido van Rossumf45b53b1995-02-20 23:43:29 +0000645 sprintf(buf, "FSSpec((%d, %d, '%.*s'))",
646 self->fsspec.vRefNum,
647 self->fsspec.parID,
648 self->fsspec.name[0], self->fsspec.name+1);
Jack Jansenf5c20571997-01-30 15:48:07 +0000649 return PyString_FromString(buf);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000650}
651
652static int
653mfss_compare(v, w)
654 mfssobject *v, *w;
655{
656 int minlen;
657 int res;
658
659 if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1;
660 if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1;
661 if ( v->fsspec.parID < w->fsspec.parID ) return -1;
662 if ( v->fsspec.parID > w->fsspec.parID ) return 1;
663 minlen = v->fsspec.name[0];
664 if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0];
665 res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen);
666 if ( res ) return res;
667 if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1;
668 if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1;
669 return res;
670}
671
Jack Jansenf5c20571997-01-30 15:48:07 +0000672statichere PyTypeObject Mfsstype = {
673 PyObject_HEAD_INIT(&PyType_Type)
Jack Jansen17ba43f1995-01-26 16:22:07 +0000674 0, /*ob_size*/
675 "FSSpec", /*tp_name*/
676 sizeof(mfssobject), /*tp_basicsize*/
677 0, /*tp_itemsize*/
678 /* methods */
679 (destructor)mfss_dealloc, /*tp_dealloc*/
680 (printfunc)0, /*tp_print*/
681 (getattrfunc)mfss_getattr, /*tp_getattr*/
682 (setattrfunc)0, /*tp_setattr*/
683 (cmpfunc)mfss_compare, /*tp_compare*/
684 (reprfunc)mfss_repr, /*tp_repr*/
685 0, /*tp_as_number*/
686 0, /*tp_as_sequence*/
687 0, /*tp_as_mapping*/
688 (hashfunc)0, /*tp_hash*/
689};
690
691/* End of code for FSSpec objects */
692/* -------------------------------------------------------- */
693
Jack Jansenf5c20571997-01-30 15:48:07 +0000694static PyObject *
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000695mfs_ResolveAliasFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000696 PyObject *self; /* Not used */
697 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000698{
Jack Jansen17ba43f1995-01-26 16:22:07 +0000699 FSSpec fss;
700 Boolean chain = 1, isfolder, wasaliased;
701 OSErr err;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000702
Jack Jansenf5c20571997-01-30 15:48:07 +0000703 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000704 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000705 err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
706 if ( err ) {
707 PyErr_Mac(ErrorObject, err);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000708 return NULL;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000709 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000710 return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000711}
712
Jack Jansen74a1e632000-07-14 22:37:27 +0000713#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000714static PyObject *
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000715mfs_StandardGetFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000716 PyObject *self; /* Not used */
717 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000718{
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000719 SFTypeList list;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000720 short numtypes;
721 StandardFileReply reply;
722
723 list[0] = list[1] = list[2] = list[3] = 0;
724 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000725 if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
Jack Jansen17ba43f1995-01-26 16:22:07 +0000726 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
727 PyMac_GetOSType, &list[3]) )
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000728 return NULL;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000729 while ( numtypes < 4 && list[numtypes] ) {
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000730 numtypes++;
731 }
Jack Jansenc2632861995-06-03 21:15:50 +0000732 if ( numtypes == 0 )
733 numtypes = -1;
Guido van Rossumb2f524a1995-01-30 08:56:06 +0000734 StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000735 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000736}
737
Jack Jansenf5c20571997-01-30 15:48:07 +0000738static PyObject *
Jack Jansend5d5f461995-08-14 12:22:56 +0000739mfs_PromptGetFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000740 PyObject *self; /* Not used */
741 PyObject *args;
Jack Jansend5d5f461995-08-14 12:22:56 +0000742{
743 SFTypeList list;
744 short numtypes;
745 StandardFileReply reply;
746 char *prompt = NULL;
747
748 list[0] = list[1] = list[2] = list[3] = 0;
749 numtypes = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000750 if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
Jack Jansend5d5f461995-08-14 12:22:56 +0000751 PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
752 PyMac_GetOSType, &list[3]) )
753 return NULL;
754 while ( numtypes < 4 && list[numtypes] ) {
755 numtypes++;
756 }
757 if ( numtypes == 0 )
758 numtypes = -1;
759 PyMac_PromptGetFile(numtypes, list, &reply, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000760 return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansend5d5f461995-08-14 12:22:56 +0000761}
762
Jack Jansenf5c20571997-01-30 15:48:07 +0000763static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000764mfs_StandardPutFile(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000765 PyObject *self; /* Not used */
766 PyObject *args;
Jack Jansen17ba43f1995-01-26 16:22:07 +0000767{
768 Str255 prompt, dft;
769 StandardFileReply reply;
770
771 dft[0] = 0;
Jack Jansenf5c20571997-01-30 15:48:07 +0000772 if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
Jack Jansen17ba43f1995-01-26 16:22:07 +0000773 return NULL;
774 StandardPutFile(prompt, dft, &reply);
Jack Jansenf5c20571997-01-30 15:48:07 +0000775 return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
Jack Jansen17ba43f1995-01-26 16:22:07 +0000776}
777
Jack Jansend99d2831996-07-22 15:26:01 +0000778/*
779** Set initial directory for file dialogs */
Jack Jansenf5c20571997-01-30 15:48:07 +0000780static PyObject *
Jack Jansend99d2831996-07-22 15:26:01 +0000781mfs_SetFolder(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000782 PyObject *self;
783 PyObject *args;
Jack Jansend99d2831996-07-22 15:26:01 +0000784{
785 FSSpec spec;
786 FSSpec ospec;
787 short orefnum;
788 long oparid;
789
790 /* Get old values */
791 orefnum = -LMGetSFSaveDisk();
792 oparid = LMGetCurDirStore();
793 (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec);
794
795 /* Go to working directory by default */
796 (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
Jack Jansenf5c20571997-01-30 15:48:07 +0000797 if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
Jack Jansend99d2831996-07-22 15:26:01 +0000798 return NULL;
799 /* Set standard-file working directory */
800 LMSetSFSaveDisk(-spec.vRefNum);
801 LMSetCurDirStore(spec.parID);
Jack Jansenf5c20571997-01-30 15:48:07 +0000802 return (PyObject *)newmfssobject(&ospec);
Jack Jansend99d2831996-07-22 15:26:01 +0000803}
Jack Jansene79dc762000-06-02 21:35:07 +0000804#endif
Jack Jansend99d2831996-07-22 15:26:01 +0000805
Jack Jansenf5c20571997-01-30 15:48:07 +0000806static PyObject *
Jack Jansen17ba43f1995-01-26 16:22:07 +0000807mfs_FSSpec(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000808 PyObject *self; /* Not used */
809 PyObject *args;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000810{
811 FSSpec fss;
812
Jack Jansenf5c20571997-01-30 15:48:07 +0000813 if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000814 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000815 return (PyObject *)newmfssobject(&fss);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000816}
817
Jack Jansenf5c20571997-01-30 15:48:07 +0000818static PyObject *
Jack Jansenc889b761995-02-13 12:00:46 +0000819mfs_RawFSSpec(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000820 PyObject *self; /* Not used */
821 PyObject *args;
Jack Jansenc889b761995-02-13 12:00:46 +0000822{
823 FSSpec *fssp;
824 int size;
825
Jack Janseneeccca91997-05-07 15:46:31 +0000826 if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000827 return NULL;
828 if ( size != sizeof(FSSpec) ) {
829 PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
830 return NULL;
831 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000832 return (PyObject *)newmfssobject(fssp);
Jack Jansenc889b761995-02-13 12:00:46 +0000833}
834
Jack Jansenf5c20571997-01-30 15:48:07 +0000835static PyObject *
Jack Jansenc889b761995-02-13 12:00:46 +0000836mfs_RawAlias(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000837 PyObject *self; /* Not used */
838 PyObject *args;
Jack Jansenc889b761995-02-13 12:00:46 +0000839{
840 char *dataptr;
841 Handle h;
842 int size;
843
Jack Janseneeccca91997-05-07 15:46:31 +0000844 if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
Jack Jansenc889b761995-02-13 12:00:46 +0000845 return NULL;
846 h = NewHandle(size);
847 if ( h == NULL ) {
848 PyErr_NoMemory();
849 return NULL;
850 }
851 HLock(h);
852 memcpy((char *)*h, dataptr, size);
853 HUnlock(h);
Jack Jansenf5c20571997-01-30 15:48:07 +0000854 return (PyObject *)newmfsaobject((AliasHandle)h);
Jack Jansenc889b761995-02-13 12:00:46 +0000855}
856
Jack Jansen74a1e632000-07-14 22:37:27 +0000857#if !TARGET_API_MAC_CARBON
Jack Jansenf5c20571997-01-30 15:48:07 +0000858static PyObject *
Jack Jansen81f51c71995-02-20 15:45:25 +0000859mfs_GetDirectory(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000860 PyObject *self; /* Not used */
861 PyObject *args;
Jack Jansen81f51c71995-02-20 15:45:25 +0000862{
863 FSSpec fsdir;
864 int ok;
Jack Jansend5d5f461995-08-14 12:22:56 +0000865 char *prompt = NULL;
Jack Jansen81f51c71995-02-20 15:45:25 +0000866
Jack Jansenf5c20571997-01-30 15:48:07 +0000867 if (!PyArg_ParseTuple(args, "|s", &prompt) )
Jack Jansen81f51c71995-02-20 15:45:25 +0000868 return NULL;
869
Jack Jansend5d5f461995-08-14 12:22:56 +0000870 ok = PyMac_GetDirectory(&fsdir, prompt);
Jack Jansenf5c20571997-01-30 15:48:07 +0000871 return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
Jack Jansen81f51c71995-02-20 15:45:25 +0000872}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000873#endif
Jack Jansen81f51c71995-02-20 15:45:25 +0000874
Jack Jansenf5c20571997-01-30 15:48:07 +0000875static PyObject *
Jack Jansen2c673621995-06-18 20:05:14 +0000876mfs_FindFolder(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000877 PyObject *self; /* Not used */
878 PyObject *args;
Jack Jansen2c673621995-06-18 20:05:14 +0000879{
880 OSErr err;
881 short where;
882 OSType which;
883 int create;
884 short refnum;
885 long dirid;
886
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000887 if (!PyArg_ParseTuple(args, "HO&i", &where, PyMac_GetOSType, &which, &create) )
Jack Jansen2c673621995-06-18 20:05:14 +0000888 return NULL;
889 err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
890 if ( err ) {
891 PyErr_Mac(ErrorObject, err);
892 return NULL;
893 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000894 return Py_BuildValue("(ii)", refnum, dirid);
Jack Jansen2c673621995-06-18 20:05:14 +0000895}
896
Jack Jansenf5c20571997-01-30 15:48:07 +0000897static PyObject *
Jack Jansen924ca851996-09-20 15:25:16 +0000898mfs_FindApplication(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000899 PyObject *self; /* Not used */
900 PyObject *args;
Jack Jansen924ca851996-09-20 15:25:16 +0000901{
902 OSErr err;
903 OSType which;
904 FSSpec fss;
905
Jack Jansenf5c20571997-01-30 15:48:07 +0000906 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
Jack Jansen924ca851996-09-20 15:25:16 +0000907 return NULL;
908 err = FindApplicationFromCreator(which, &fss);
909 if ( err ) {
910 PyErr_Mac(ErrorObject, err);
911 return NULL;
912 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000913 return (PyObject *)newmfssobject(&fss);
Jack Jansen924ca851996-09-20 15:25:16 +0000914}
915
Jack Jansenf5c20571997-01-30 15:48:07 +0000916static PyObject *
Jack Jansen3d185931995-08-07 14:04:10 +0000917mfs_FInfo(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000918 PyObject *self;
919 PyObject *args;
Jack Jansen3d185931995-08-07 14:04:10 +0000920{
Jack Jansenf5c20571997-01-30 15:48:07 +0000921 return (PyObject *)newmfsiobject();
Jack Jansen3d185931995-08-07 14:04:10 +0000922}
923
Jack Jansend9936481997-06-16 14:31:38 +0000924static PyObject *
925mfs_NewAliasMinimalFromFullPath(self, args)
926 PyObject *self; /* Not used */
927 PyObject *args;
928{
929 OSErr err;
930 char *fullpath;
931 int fullpathlen;
932 AliasHandle alias;
933 Str32 zonename;
934 Str31 servername;
935
936 if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) )
937 return NULL;
938 zonename[0] = 0;
939 servername[0] = 0;
940 err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename,
941 servername, &alias);
942 if ( err ) {
943 PyErr_Mac(ErrorObject, err);
944 return NULL;
945 }
946 return (PyObject *)newmfsaobject(alias);
947}
948
949
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000950/* List of methods defined in the module */
951
Jack Jansenf5c20571997-01-30 15:48:07 +0000952static struct PyMethodDef mfs_methods[] = {
Jack Jansen17ba43f1995-01-26 16:22:07 +0000953 {"ResolveAliasFile", mfs_ResolveAliasFile, 1},
Jack Jansen74a1e632000-07-14 22:37:27 +0000954#if !TARGET_API_MAC_CARBON
Jack Jansen17ba43f1995-01-26 16:22:07 +0000955 {"StandardGetFile", mfs_StandardGetFile, 1},
Jack Jansend5d5f461995-08-14 12:22:56 +0000956 {"PromptGetFile", mfs_PromptGetFile, 1},
Jack Jansen17ba43f1995-01-26 16:22:07 +0000957 {"StandardPutFile", mfs_StandardPutFile, 1},
Jack Jansen81f51c71995-02-20 15:45:25 +0000958 {"GetDirectory", mfs_GetDirectory, 1},
Jack Jansend99d2831996-07-22 15:26:01 +0000959 {"SetFolder", mfs_SetFolder, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000960#endif
Jack Jansen17ba43f1995-01-26 16:22:07 +0000961 {"FSSpec", mfs_FSSpec, 1},
Jack Jansenc889b761995-02-13 12:00:46 +0000962 {"RawFSSpec", mfs_RawFSSpec, 1},
963 {"RawAlias", mfs_RawAlias, 1},
Jack Jansen2c673621995-06-18 20:05:14 +0000964 {"FindFolder", mfs_FindFolder, 1},
Jack Jansen924ca851996-09-20 15:25:16 +0000965 {"FindApplication", mfs_FindApplication, 1},
Jack Jansen3d185931995-08-07 14:04:10 +0000966 {"FInfo", mfs_FInfo, 1},
Jack Jansend9936481997-06-16 14:31:38 +0000967 {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1},
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000968
969 {NULL, NULL} /* sentinel */
970};
971
972
973/* Initialization function for the module (*must* be called initmacfs) */
974
975void
976initmacfs()
977{
Jack Jansenf5c20571997-01-30 15:48:07 +0000978 PyObject *m, *d;
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000979
980 /* Create the module and add the functions */
Jack Jansenf5c20571997-01-30 15:48:07 +0000981 m = Py_InitModule("macfs", mfs_methods);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000982
983 /* Add some symbolic constants to the module */
Jack Jansenf5c20571997-01-30 15:48:07 +0000984 d = PyModule_GetDict(m);
Jack Jansen4377a1a2000-01-24 10:37:59 +0000985 ErrorObject = PyMac_GetOSErrException();
Jack Jansenf5c20571997-01-30 15:48:07 +0000986 PyDict_SetItemString(d, "error", ErrorObject);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000987
Jack Jansena755e681997-09-20 17:40:22 +0000988 Mfsatype.ob_type = &PyType_Type;
989 Py_INCREF(&Mfsatype);
990 PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype);
991 Mfsstype.ob_type = &PyType_Type;
992 Py_INCREF(&Mfsstype);
993 PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype);
994 Mfsitype.ob_type = &PyType_Type;
995 Py_INCREF(&Mfsitype);
996 PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000997 /* XXXX Add constants here */
Jack Jansen84fa5ec1995-01-18 14:04:40 +0000998}