Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | #include "allobjects.h" |
| 26 | #include "modsupport.h" /* For getargs() etc. */ |
| 27 | #include "macglue.h" |
| 28 | |
Guido van Rossum | becdbec | 1995-02-14 01:27:24 +0000 | [diff] [blame] | 29 | #include <Memory.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 30 | #include <Files.h> |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 31 | #include <Folders.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 32 | #include <StandardFile.h> |
| 33 | #include <Aliases.h> |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 34 | #include <LowMem.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 35 | |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 36 | #include "getapplbycreator.h" |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | a42960c | 1995-01-19 00:03:47 +0000 | [diff] [blame] | 38 | #ifdef THINK_C |
| 39 | #define FileFilterUPP FileFilterProcPtr |
| 40 | #endif |
| 41 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 42 | static object *ErrorObject; |
| 43 | |
| 44 | /* ----------------------------------------------------- */ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 45 | /* Declarations for objects of type Alias */ |
| 46 | |
| 47 | typedef struct { |
| 48 | OB_HEAD |
| 49 | AliasHandle alias; |
| 50 | } mfsaobject; |
| 51 | |
| 52 | staticforward typeobject Mfsatype; |
| 53 | |
| 54 | #define is_mfsaobject(v) ((v)->ob_type == &Mfsatype) |
| 55 | |
| 56 | /* ---------------------------------------------------------------- */ |
| 57 | /* Declarations for objects of type FSSpec */ |
| 58 | |
| 59 | typedef struct { |
| 60 | OB_HEAD |
| 61 | FSSpec fsspec; |
| 62 | } mfssobject; |
| 63 | |
| 64 | staticforward typeobject Mfsstype; |
| 65 | |
| 66 | #define is_mfssobject(v) ((v)->ob_type == &Mfsstype) |
| 67 | |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 68 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 69 | /* ---------------------------------------------------------------- */ |
| 70 | /* Declarations for objects of type FInfo */ |
| 71 | |
| 72 | typedef struct { |
| 73 | OB_HEAD |
| 74 | FInfo finfo; |
| 75 | } mfsiobject; |
| 76 | |
| 77 | staticforward typeobject Mfsitype; |
| 78 | |
| 79 | #define is_mfsiobject(v) ((v)->ob_type == &Mfsitype) |
| 80 | |
| 81 | |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 82 | mfssobject *newmfssobject(FSSpec *fss); /* Forward */ |
| 83 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 84 | /* ---------------------------------------------------------------- */ |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 85 | |
| 86 | static object * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 87 | mfsa_Resolve(self, args) |
| 88 | mfsaobject *self; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 89 | object *args; |
| 90 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 91 | FSSpec from, *fromp, result; |
| 92 | Boolean changed; |
| 93 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 94 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 95 | from.name[0] = 0; |
| 96 | if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &from)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 97 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 98 | if (from.name[0] ) |
| 99 | fromp = &from; |
| 100 | else |
| 101 | fromp = NULL; |
| 102 | err = ResolveAlias(fromp, self->alias, &result, &changed); |
| 103 | if ( err ) { |
| 104 | PyErr_Mac(ErrorObject, err); |
| 105 | return NULL; |
| 106 | } |
| 107 | return mkvalue("(Oi)", newmfssobject(&result), (int)changed); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static object * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 111 | mfsa_GetInfo(self, args) |
| 112 | mfsaobject *self; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 113 | object *args; |
| 114 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 115 | Str63 value; |
| 116 | int i; |
| 117 | OSErr err; |
| 118 | |
| 119 | if (!newgetargs(args, "i", &i)) |
| 120 | return NULL; |
| 121 | err = GetAliasInfo(self->alias, (AliasInfoType)i, value); |
| 122 | if ( err ) { |
| 123 | PyErr_Mac(ErrorObject, err); |
| 124 | return 0; |
| 125 | } |
| 126 | return newsizedstringobject((char *)&value[1], value[0]); |
| 127 | } |
| 128 | |
| 129 | static object * |
| 130 | mfsa_Update(self, args) |
| 131 | mfsaobject *self; |
| 132 | object *args; |
| 133 | { |
| 134 | FSSpec target, fromfile, *fromfilep; |
| 135 | OSErr err; |
| 136 | Boolean changed; |
| 137 | |
| 138 | fromfile.name[0] = 0; |
| 139 | if (!newgetargs(args, "O&|O&", PyMac_GetFSSpec, &target, |
| 140 | PyMac_GetFSSpec, &fromfile)) |
| 141 | return NULL; |
| 142 | if ( fromfile.name[0] ) |
| 143 | fromfilep = &fromfile; |
| 144 | else |
| 145 | fromfilep = NULL; |
| 146 | err = UpdateAlias(fromfilep, &target, self->alias, &changed); |
| 147 | if ( err ) { |
| 148 | PyErr_Mac(ErrorObject, err); |
| 149 | return 0; |
| 150 | } |
| 151 | return mkvalue("i", (int)changed); |
| 152 | } |
| 153 | |
| 154 | static struct methodlist mfsa_methods[] = { |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 155 | {"Resolve", (method)mfsa_Resolve, 1}, |
| 156 | {"GetInfo", (method)mfsa_GetInfo, 1}, |
| 157 | {"Update", (method)mfsa_Update, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 158 | |
| 159 | {NULL, NULL} /* sentinel */ |
| 160 | }; |
| 161 | |
| 162 | /* ---------- */ |
| 163 | |
| 164 | static object * |
| 165 | mfsa_getattr(self, name) |
| 166 | mfsaobject *self; |
| 167 | char *name; |
| 168 | { |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 169 | if ( strcmp(name, "data") == 0 ) { |
| 170 | int size; |
| 171 | PyObject *rv; |
| 172 | |
| 173 | size = GetHandleSize((Handle)self->alias); |
| 174 | HLock((Handle)self->alias); |
| 175 | rv = PyString_FromStringAndSize(*(Handle)self->alias, size); |
| 176 | HUnlock((Handle)self->alias); |
| 177 | return rv; |
| 178 | } |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 179 | return findmethod(mfsa_methods, (object *)self, name); |
| 180 | } |
| 181 | |
| 182 | mfsaobject * |
| 183 | newmfsaobject(alias) |
| 184 | AliasHandle alias; |
| 185 | { |
| 186 | mfsaobject *self; |
| 187 | |
| 188 | self = NEWOBJ(mfsaobject, &Mfsatype); |
| 189 | if (self == NULL) |
| 190 | return NULL; |
| 191 | self->alias = alias; |
| 192 | return self; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | static void |
| 197 | mfsa_dealloc(self) |
| 198 | mfsaobject *self; |
| 199 | { |
| 200 | #if 0 |
| 201 | if ( self->alias ) { |
| 202 | should we do something here? |
| 203 | } |
| 204 | #endif |
| 205 | |
| 206 | DEL(self); |
| 207 | } |
| 208 | |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 209 | statichere typeobject Mfsatype = { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 210 | OB_HEAD_INIT(&Typetype) |
| 211 | 0, /*ob_size*/ |
| 212 | "Alias", /*tp_name*/ |
| 213 | sizeof(mfsaobject), /*tp_basicsize*/ |
| 214 | 0, /*tp_itemsize*/ |
| 215 | /* methods */ |
| 216 | (destructor)mfsa_dealloc, /*tp_dealloc*/ |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 217 | (printfunc)0, /*tp_print*/ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 218 | (getattrfunc)mfsa_getattr, /*tp_getattr*/ |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 219 | (setattrfunc)0, /*tp_setattr*/ |
| 220 | (cmpfunc)0, /*tp_compare*/ |
| 221 | (reprfunc)0, /*tp_repr*/ |
| 222 | 0, /*tp_as_number*/ |
| 223 | 0, /*tp_as_sequence*/ |
| 224 | 0, /*tp_as_mapping*/ |
| 225 | (hashfunc)0, /*tp_hash*/ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | /* End of code for Alias objects */ |
| 229 | /* -------------------------------------------------------- */ |
| 230 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 231 | /* ---------------------------------------------------------------- */ |
| 232 | |
| 233 | static struct methodlist mfsi_methods[] = { |
| 234 | |
| 235 | {NULL, NULL} /* sentinel */ |
| 236 | }; |
| 237 | |
| 238 | /* ---------- */ |
| 239 | |
| 240 | static mfsiobject * |
| 241 | newmfsiobject() |
| 242 | { |
| 243 | mfsiobject *self; |
| 244 | |
| 245 | self = NEWOBJ(mfsiobject, &Mfsitype); |
| 246 | if (self == NULL) |
| 247 | return NULL; |
| 248 | memset((char *)&self->finfo, '\0', sizeof(self->finfo)); |
| 249 | return self; |
| 250 | } |
| 251 | |
| 252 | static void |
| 253 | mfsi_dealloc(self) |
| 254 | mfsiobject *self; |
| 255 | { |
| 256 | DEL(self); |
| 257 | } |
| 258 | |
| 259 | static object * |
| 260 | mfsi_getattr(self, name) |
| 261 | mfsiobject *self; |
| 262 | char *name; |
| 263 | { |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 264 | if ( strcmp(name, "Type") == 0 ) |
| 265 | return PyMac_BuildOSType(self->finfo.fdType); |
| 266 | else if ( strcmp(name, "Creator") == 0 ) |
| 267 | return PyMac_BuildOSType(self->finfo.fdCreator); |
| 268 | else if ( strcmp(name, "Flags") == 0 ) |
| 269 | return Py_BuildValue("i", (int)self->finfo.fdFlags); |
| 270 | else if ( strcmp(name, "Location") == 0 ) |
| 271 | return PyMac_BuildPoint(self->finfo.fdLocation); |
| 272 | else if ( strcmp(name, "Fldr") == 0 ) |
| 273 | return Py_BuildValue("i", (int)self->finfo.fdFldr); |
| 274 | else |
| 275 | return findmethod(mfsi_methods, (object *)self, name); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | static int |
| 280 | mfsi_setattr(self, name, v) |
| 281 | mfsiobject *self; |
| 282 | char *name; |
| 283 | object *v; |
| 284 | { |
| 285 | int rv; |
| 286 | int i; |
| 287 | |
| 288 | if ( v == NULL ) { |
| 289 | err_setstr(AttributeError, "Cannot delete attribute"); |
| 290 | return -1; |
| 291 | } |
| 292 | if ( strcmp(name, "Type") == 0 ) |
| 293 | rv = PyMac_GetOSType(v, &self->finfo.fdType); |
| 294 | else if ( strcmp(name, "Creator") == 0 ) |
| 295 | rv = PyMac_GetOSType(v, &self->finfo.fdCreator); |
| 296 | else if ( strcmp(name, "Flags") == 0 ) { |
| 297 | rv = PyArg_Parse(v, "i", &i); |
| 298 | self->finfo.fdFlags = (short)i; |
| 299 | } else if ( strcmp(name, "Location") == 0 ) |
| 300 | rv = PyMac_GetPoint(v, &self->finfo.fdLocation); |
| 301 | else if ( strcmp(name, "Fldr") == 0 ) { |
| 302 | rv = PyArg_Parse(v, "i", &i); |
| 303 | self->finfo.fdFldr = (short)i; |
| 304 | } else { |
| 305 | err_setstr(AttributeError, "No such attribute"); |
| 306 | return -1; |
| 307 | } |
| 308 | if (rv) |
| 309 | return 0; |
| 310 | return -1; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | static typeobject Mfsitype = { |
| 315 | OB_HEAD_INIT(&Typetype) |
| 316 | 0, /*ob_size*/ |
| 317 | "FInfo object", /*tp_name*/ |
| 318 | sizeof(mfsiobject), /*tp_basicsize*/ |
| 319 | 0, /*tp_itemsize*/ |
| 320 | /* methods */ |
| 321 | (destructor)mfsi_dealloc, /*tp_dealloc*/ |
| 322 | (printfunc)0, /*tp_print*/ |
| 323 | (getattrfunc)mfsi_getattr, /*tp_getattr*/ |
| 324 | (setattrfunc)mfsi_setattr, /*tp_setattr*/ |
| 325 | (cmpfunc)0, /*tp_compare*/ |
| 326 | (reprfunc)0, /*tp_repr*/ |
| 327 | 0, /*tp_as_number*/ |
| 328 | 0, /*tp_as_sequence*/ |
| 329 | 0, /*tp_as_mapping*/ |
| 330 | (hashfunc)0, /*tp_hash*/ |
| 331 | }; |
| 332 | |
| 333 | /* End of code for FInfo object objects */ |
| 334 | /* -------------------------------------------------------- */ |
| 335 | |
| 336 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 337 | /* |
| 338 | ** Helper routine for other modules: return an FSSpec * if the |
| 339 | ** object is a python fsspec object, else NULL |
| 340 | */ |
| 341 | FSSpec * |
| 342 | mfs_GetFSSpecFSSpec(self) |
| 343 | object *self; |
| 344 | { |
| 345 | if ( is_mfssobject(self) ) |
| 346 | return &((mfssobject *)self)->fsspec; |
| 347 | return NULL; |
| 348 | } |
| 349 | |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 350 | /* |
| 351 | ** Two generally useful routines |
| 352 | */ |
| 353 | static OSErr |
| 354 | PyMac_GetFileDates(fss, crdat, mddat, bkdat) |
| 355 | FSSpec *fss; |
| 356 | unsigned long *crdat, *mddat, *bkdat; |
| 357 | { |
| 358 | CInfoPBRec pb; |
| 359 | OSErr error; |
| 360 | |
| 361 | pb.dirInfo.ioNamePtr = fss->name; |
| 362 | pb.dirInfo.ioFDirIndex = 0; |
| 363 | pb.dirInfo.ioVRefNum = fss->vRefNum; |
| 364 | pb.dirInfo.ioDrDirID = fss->parID; |
| 365 | error = PBGetCatInfoSync(&pb); |
| 366 | if ( error ) return error; |
| 367 | *crdat = pb.hFileInfo.ioFlCrDat; |
| 368 | *mddat = pb.hFileInfo.ioFlMdDat; |
| 369 | *bkdat = pb.hFileInfo.ioFlBkDat; |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static OSErr |
| 374 | PyMac_SetFileDates(fss, crdat, mddat, bkdat) |
| 375 | FSSpec *fss; |
| 376 | unsigned long crdat, mddat, bkdat; |
| 377 | { |
| 378 | CInfoPBRec pb; |
| 379 | OSErr error; |
| 380 | |
| 381 | pb.dirInfo.ioNamePtr = fss->name; |
| 382 | pb.dirInfo.ioFDirIndex = 0; |
| 383 | pb.dirInfo.ioVRefNum = fss->vRefNum; |
| 384 | pb.dirInfo.ioDrDirID = fss->parID; |
| 385 | error = PBGetCatInfoSync(&pb); |
| 386 | if ( error ) return error; |
| 387 | pb.dirInfo.ioNamePtr = fss->name; |
| 388 | pb.dirInfo.ioFDirIndex = 0; |
| 389 | pb.dirInfo.ioVRefNum = fss->vRefNum; |
| 390 | pb.dirInfo.ioDrDirID = fss->parID; |
| 391 | pb.hFileInfo.ioFlCrDat = crdat; |
| 392 | pb.hFileInfo.ioFlMdDat = mddat; |
| 393 | pb.hFileInfo.ioFlBkDat = bkdat; |
| 394 | error = PBSetCatInfoSync(&pb); |
| 395 | return error; |
| 396 | } |
| 397 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 398 | static object * |
| 399 | mfss_as_pathname(self, args) |
| 400 | mfssobject *self; |
| 401 | object *args; |
| 402 | { |
| 403 | char strbuf[257]; |
| 404 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 405 | |
| 406 | if (!newgetargs(args, "")) |
| 407 | return NULL; |
Jack Jansen | 84fb1fa | 1996-11-09 18:46:57 +0000 | [diff] [blame^] | 408 | err = PyMac_GetFullPath(&self->fsspec, strbuf); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 409 | if ( err ) { |
| 410 | PyErr_Mac(ErrorObject, err); |
| 411 | return NULL; |
| 412 | } |
| 413 | return newstringobject(strbuf); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static object * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 417 | mfss_as_tuple(self, args) |
| 418 | mfssobject *self; |
| 419 | object *args; |
| 420 | { |
| 421 | if (!newgetargs(args, "")) |
| 422 | return NULL; |
| 423 | return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID, |
| 424 | &self->fsspec.name[1], self->fsspec.name[0]); |
| 425 | } |
| 426 | |
| 427 | static object * |
| 428 | mfss_NewAlias(self, args) |
| 429 | mfssobject *self; |
| 430 | object *args; |
| 431 | { |
| 432 | FSSpec src, *srcp; |
| 433 | OSErr err; |
| 434 | AliasHandle alias; |
| 435 | |
| 436 | src.name[0] = 0; |
| 437 | if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &src)) |
| 438 | return NULL; |
| 439 | if ( src.name[0] ) |
| 440 | srcp = &src; |
| 441 | else |
| 442 | srcp = NULL; |
| 443 | err = NewAlias(srcp, &self->fsspec, &alias); |
| 444 | if ( err ) { |
| 445 | PyErr_Mac(ErrorObject, err); |
| 446 | return NULL; |
| 447 | } |
| 448 | |
| 449 | return (object *)newmfsaobject(alias); |
| 450 | } |
| 451 | |
| 452 | static object * |
| 453 | mfss_NewAliasMinimal(self, args) |
| 454 | mfssobject *self; |
| 455 | object *args; |
| 456 | { |
| 457 | OSErr err; |
| 458 | AliasHandle alias; |
| 459 | |
| 460 | if (!newgetargs(args, "")) |
| 461 | return NULL; |
| 462 | err = NewAliasMinimal(&self->fsspec, &alias); |
| 463 | if ( err ) { |
| 464 | PyErr_Mac(ErrorObject, err); |
| 465 | return NULL; |
| 466 | } |
| 467 | return (object *)newmfsaobject(alias); |
| 468 | } |
| 469 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 470 | /* XXXX These routines should be replaced by a wrapper to the *FInfo routines */ |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 471 | static object * |
| 472 | mfss_GetCreatorType(self, args) |
| 473 | mfssobject *self; |
| 474 | object *args; |
| 475 | { |
| 476 | OSErr err; |
| 477 | FInfo info; |
| 478 | |
| 479 | if (!newgetargs(args, "")) |
| 480 | return NULL; |
| 481 | err = FSpGetFInfo(&self->fsspec, &info); |
| 482 | if ( err ) { |
| 483 | PyErr_Mac(ErrorObject, err); |
| 484 | return NULL; |
| 485 | } |
| 486 | return Py_BuildValue("(O&O&)", |
| 487 | PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType); |
| 488 | } |
| 489 | |
| 490 | static object * |
| 491 | mfss_SetCreatorType(self, args) |
| 492 | mfssobject *self; |
| 493 | object *args; |
| 494 | { |
| 495 | OSErr err; |
| 496 | OSType creator, type; |
| 497 | FInfo info; |
| 498 | |
| 499 | if (!newgetargs(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) |
| 500 | return NULL; |
| 501 | err = FSpGetFInfo(&self->fsspec, &info); |
| 502 | if ( err ) { |
| 503 | PyErr_Mac(ErrorObject, err); |
| 504 | return NULL; |
| 505 | } |
| 506 | info.fdType = type; |
| 507 | info.fdCreator = creator; |
| 508 | err = FSpSetFInfo(&self->fsspec, &info); |
| 509 | if ( err ) { |
| 510 | PyErr_Mac(ErrorObject, err); |
| 511 | return NULL; |
| 512 | } |
| 513 | INCREF(None); |
| 514 | return None; |
| 515 | } |
| 516 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 517 | static object * |
| 518 | mfss_GetFInfo(self, args) |
| 519 | mfssobject *self; |
| 520 | object *args; |
| 521 | { |
| 522 | OSErr err; |
| 523 | mfsiobject *fip; |
| 524 | |
| 525 | |
| 526 | if (!newgetargs(args, "")) |
| 527 | return NULL; |
| 528 | if ( (fip=newmfsiobject()) == NULL ) |
| 529 | return NULL; |
| 530 | err = FSpGetFInfo(&self->fsspec, &fip->finfo); |
| 531 | if ( err ) { |
| 532 | PyErr_Mac(ErrorObject, err); |
| 533 | DECREF(fip); |
| 534 | return NULL; |
| 535 | } |
| 536 | return (object *)fip; |
| 537 | } |
| 538 | |
| 539 | static object * |
| 540 | mfss_SetFInfo(self, args) |
| 541 | mfssobject *self; |
| 542 | object *args; |
| 543 | { |
| 544 | OSErr err; |
| 545 | mfsiobject *fip; |
| 546 | |
| 547 | if (!newgetargs(args, "O!", &Mfsitype, &fip)) |
| 548 | return NULL; |
| 549 | err = FSpSetFInfo(&self->fsspec, &fip->finfo); |
| 550 | if ( err ) { |
| 551 | PyErr_Mac(ErrorObject, err); |
| 552 | return NULL; |
| 553 | } |
| 554 | INCREF(None); |
| 555 | return None; |
| 556 | } |
| 557 | |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 558 | static object * |
| 559 | mfss_GetDates(self, args) |
| 560 | mfssobject *self; |
| 561 | object *args; |
| 562 | { |
| 563 | OSErr err; |
| 564 | unsigned long crdat, mddat, bkdat; |
| 565 | |
| 566 | if (!newgetargs(args, "")) |
| 567 | return NULL; |
| 568 | err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat); |
| 569 | if ( err ) { |
| 570 | PyErr_Mac(ErrorObject, err); |
| 571 | return NULL; |
| 572 | } |
| 573 | return mkvalue("ddd", (double)crdat, (double)mddat, (double)bkdat); |
| 574 | } |
| 575 | |
| 576 | static object * |
| 577 | mfss_SetDates(self, args) |
| 578 | mfssobject *self; |
| 579 | object *args; |
| 580 | { |
| 581 | OSErr err; |
| 582 | double crdat, mddat, bkdat; |
| 583 | |
| 584 | if (!newgetargs(args, "ddd", &crdat, &mddat, &bkdat)) |
| 585 | return NULL; |
| 586 | err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat, |
| 587 | (unsigned long)mddat, (unsigned long)bkdat); |
| 588 | if ( err ) { |
| 589 | PyErr_Mac(ErrorObject, err); |
| 590 | return NULL; |
| 591 | } |
| 592 | INCREF(None); |
| 593 | return None; |
| 594 | } |
| 595 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 596 | static struct methodlist mfss_methods[] = { |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 597 | {"as_pathname", (method)mfss_as_pathname, 1}, |
| 598 | {"as_tuple", (method)mfss_as_tuple, 1}, |
| 599 | {"NewAlias", (method)mfss_NewAlias, 1}, |
| 600 | {"NewAliasMinimal", (method)mfss_NewAliasMinimal, 1}, |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 601 | {"GetCreatorType", (method)mfss_GetCreatorType, 1}, |
| 602 | {"SetCreatorType", (method)mfss_SetCreatorType, 1}, |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 603 | {"GetFInfo", (method)mfss_GetFInfo, 1}, |
| 604 | {"SetFInfo", (method)mfss_SetFInfo, 1}, |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 605 | {"GetDates", (method)mfss_GetDates, 1}, |
| 606 | {"SetDates", (method)mfss_SetDates, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 607 | |
| 608 | {NULL, NULL} /* sentinel */ |
| 609 | }; |
| 610 | |
| 611 | /* ---------- */ |
| 612 | |
| 613 | static object * |
| 614 | mfss_getattr(self, name) |
| 615 | mfssobject *self; |
| 616 | char *name; |
| 617 | { |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 618 | if ( strcmp(name, "data") == 0) |
| 619 | return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec)); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 620 | return findmethod(mfss_methods, (object *)self, name); |
| 621 | } |
| 622 | |
| 623 | mfssobject * |
| 624 | newmfssobject(fss) |
| 625 | FSSpec *fss; |
| 626 | { |
| 627 | mfssobject *self; |
| 628 | |
| 629 | self = NEWOBJ(mfssobject, &Mfsstype); |
| 630 | if (self == NULL) |
| 631 | return NULL; |
| 632 | self->fsspec = *fss; |
| 633 | return self; |
| 634 | } |
| 635 | |
| 636 | static void |
| 637 | mfss_dealloc(self) |
| 638 | mfssobject *self; |
| 639 | { |
| 640 | DEL(self); |
| 641 | } |
| 642 | |
| 643 | static object * |
| 644 | mfss_repr(self) |
| 645 | mfssobject *self; |
| 646 | { |
| 647 | char buf[512]; |
| 648 | |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 649 | sprintf(buf, "FSSpec((%d, %d, '%.*s'))", |
| 650 | self->fsspec.vRefNum, |
| 651 | self->fsspec.parID, |
| 652 | self->fsspec.name[0], self->fsspec.name+1); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 653 | return newstringobject(buf); |
| 654 | } |
| 655 | |
| 656 | static int |
| 657 | mfss_compare(v, w) |
| 658 | mfssobject *v, *w; |
| 659 | { |
| 660 | int minlen; |
| 661 | int res; |
| 662 | |
| 663 | if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1; |
| 664 | if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1; |
| 665 | if ( v->fsspec.parID < w->fsspec.parID ) return -1; |
| 666 | if ( v->fsspec.parID > w->fsspec.parID ) return 1; |
| 667 | minlen = v->fsspec.name[0]; |
| 668 | if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0]; |
| 669 | res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen); |
| 670 | if ( res ) return res; |
| 671 | if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1; |
| 672 | if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1; |
| 673 | return res; |
| 674 | } |
| 675 | |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 676 | statichere typeobject Mfsstype = { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 677 | OB_HEAD_INIT(&Typetype) |
| 678 | 0, /*ob_size*/ |
| 679 | "FSSpec", /*tp_name*/ |
| 680 | sizeof(mfssobject), /*tp_basicsize*/ |
| 681 | 0, /*tp_itemsize*/ |
| 682 | /* methods */ |
| 683 | (destructor)mfss_dealloc, /*tp_dealloc*/ |
| 684 | (printfunc)0, /*tp_print*/ |
| 685 | (getattrfunc)mfss_getattr, /*tp_getattr*/ |
| 686 | (setattrfunc)0, /*tp_setattr*/ |
| 687 | (cmpfunc)mfss_compare, /*tp_compare*/ |
| 688 | (reprfunc)mfss_repr, /*tp_repr*/ |
| 689 | 0, /*tp_as_number*/ |
| 690 | 0, /*tp_as_sequence*/ |
| 691 | 0, /*tp_as_mapping*/ |
| 692 | (hashfunc)0, /*tp_hash*/ |
| 693 | }; |
| 694 | |
| 695 | /* End of code for FSSpec objects */ |
| 696 | /* -------------------------------------------------------- */ |
| 697 | |
| 698 | static object * |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 699 | mfs_ResolveAliasFile(self, args) |
| 700 | object *self; /* Not used */ |
| 701 | object *args; |
| 702 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 703 | FSSpec fss; |
| 704 | Boolean chain = 1, isfolder, wasaliased; |
| 705 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 706 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 707 | if (!newgetargs(args, "O&|i", PyMac_GetFSSpec, &fss, &chain)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 708 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 709 | err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased); |
| 710 | if ( err ) { |
| 711 | PyErr_Mac(ErrorObject, err); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 712 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 713 | } |
| 714 | return mkvalue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static object * |
| 718 | mfs_StandardGetFile(self, args) |
| 719 | object *self; /* Not used */ |
| 720 | object *args; |
| 721 | { |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 722 | SFTypeList list; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 723 | short numtypes; |
| 724 | StandardFileReply reply; |
| 725 | |
| 726 | list[0] = list[1] = list[2] = list[3] = 0; |
| 727 | numtypes = 0; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 728 | if (!newgetargs(args, "|O&O&O&O&", PyMac_GetOSType, &list[0], |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 729 | PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], |
| 730 | PyMac_GetOSType, &list[3]) ) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 731 | return NULL; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 732 | while ( numtypes < 4 && list[numtypes] ) { |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 733 | numtypes++; |
| 734 | } |
Jack Jansen | c263286 | 1995-06-03 21:15:50 +0000 | [diff] [blame] | 735 | if ( numtypes == 0 ) |
| 736 | numtypes = -1; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 737 | StandardGetFile((FileFilterUPP)0, numtypes, list, &reply); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 738 | return mkvalue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static object * |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 742 | mfs_PromptGetFile(self, args) |
| 743 | object *self; /* Not used */ |
| 744 | object *args; |
| 745 | { |
| 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; |
| 753 | if (!newgetargs(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0], |
| 754 | 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); |
| 763 | return mkvalue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); |
| 764 | } |
| 765 | |
| 766 | static object * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 767 | mfs_StandardPutFile(self, args) |
| 768 | object *self; /* Not used */ |
| 769 | object *args; |
| 770 | { |
| 771 | Str255 prompt, dft; |
| 772 | StandardFileReply reply; |
| 773 | |
| 774 | dft[0] = 0; |
| 775 | if (!newgetargs(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) ) |
| 776 | return NULL; |
| 777 | StandardPutFile(prompt, dft, &reply); |
| 778 | return mkvalue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood); |
| 779 | } |
| 780 | |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 781 | /* |
| 782 | ** Set initial directory for file dialogs */ |
| 783 | static object * |
| 784 | mfs_SetFolder(self, args) |
| 785 | object *self; |
| 786 | object *args; |
| 787 | { |
| 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); |
| 800 | if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &spec)) |
| 801 | return NULL; |
| 802 | /* Set standard-file working directory */ |
| 803 | LMSetSFSaveDisk(-spec.vRefNum); |
| 804 | LMSetCurDirStore(spec.parID); |
| 805 | return (object *)newmfssobject(&ospec); |
| 806 | } |
| 807 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 808 | static object * |
| 809 | mfs_FSSpec(self, args) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 810 | object *self; /* Not used */ |
| 811 | object *args; |
| 812 | { |
| 813 | FSSpec fss; |
| 814 | |
Guido van Rossum | 9aa3d13 | 1995-01-21 13:46:04 +0000 | [diff] [blame] | 815 | if (!newgetargs(args, "O&", PyMac_GetFSSpec, &fss)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 816 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 817 | return (object *)newmfssobject(&fss); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 820 | static object * |
| 821 | mfs_RawFSSpec(self, args) |
| 822 | object *self; /* Not used */ |
| 823 | object *args; |
| 824 | { |
| 825 | FSSpec *fssp; |
| 826 | int size; |
| 827 | |
| 828 | if (!newgetargs(args, "s#", &fssp, &size)) |
| 829 | return NULL; |
| 830 | if ( size != sizeof(FSSpec) ) { |
| 831 | PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record"); |
| 832 | return NULL; |
| 833 | } |
| 834 | return (object *)newmfssobject(fssp); |
| 835 | } |
| 836 | |
| 837 | static object * |
| 838 | mfs_RawAlias(self, args) |
| 839 | object *self; /* Not used */ |
| 840 | object *args; |
| 841 | { |
| 842 | char *dataptr; |
| 843 | Handle h; |
| 844 | int size; |
| 845 | |
| 846 | if (!newgetargs(args, "s#", &dataptr, &size)) |
| 847 | return NULL; |
| 848 | h = NewHandle(size); |
| 849 | if ( h == NULL ) { |
| 850 | PyErr_NoMemory(); |
| 851 | return NULL; |
| 852 | } |
| 853 | HLock(h); |
| 854 | memcpy((char *)*h, dataptr, size); |
| 855 | HUnlock(h); |
| 856 | return (object *)newmfsaobject((AliasHandle)h); |
| 857 | } |
| 858 | |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 859 | static object * |
| 860 | mfs_GetDirectory(self, args) |
| 861 | object *self; /* Not used */ |
| 862 | object *args; |
| 863 | { |
| 864 | FSSpec fsdir; |
| 865 | int ok; |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 866 | char *prompt = NULL; |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 867 | |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 868 | if (!newgetargs(args, "|s", &prompt) ) |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 869 | return NULL; |
| 870 | |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 871 | ok = PyMac_GetDirectory(&fsdir, prompt); |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 872 | return mkvalue("(Oi)", newmfssobject(&fsdir), ok); |
| 873 | } |
| 874 | |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 875 | static object * |
| 876 | mfs_FindFolder(self, args) |
| 877 | object *self; /* Not used */ |
| 878 | object *args; |
| 879 | { |
| 880 | OSErr err; |
| 881 | short where; |
| 882 | OSType which; |
| 883 | int create; |
| 884 | short refnum; |
| 885 | long dirid; |
| 886 | |
| 887 | if (!newgetargs(args, "hO&i", &where, PyMac_GetOSType, &which, &create) ) |
| 888 | return NULL; |
| 889 | err = FindFolder(where, which, (Boolean)create, &refnum, &dirid); |
| 890 | if ( err ) { |
| 891 | PyErr_Mac(ErrorObject, err); |
| 892 | return NULL; |
| 893 | } |
| 894 | return mkvalue("(ii)", refnum, dirid); |
| 895 | } |
| 896 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 897 | static object * |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 898 | mfs_FindApplication(self, args) |
| 899 | object *self; /* Not used */ |
| 900 | object *args; |
| 901 | { |
| 902 | OSErr err; |
| 903 | OSType which; |
| 904 | FSSpec fss; |
| 905 | |
| 906 | if (!newgetargs(args, "O&", PyMac_GetOSType, &which) ) |
| 907 | return NULL; |
| 908 | err = FindApplicationFromCreator(which, &fss); |
| 909 | if ( err ) { |
| 910 | PyErr_Mac(ErrorObject, err); |
| 911 | return NULL; |
| 912 | } |
| 913 | return (object *)newmfssobject(&fss); |
| 914 | } |
| 915 | |
| 916 | static object * |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 917 | mfs_FInfo(self, args) |
| 918 | object *self; |
| 919 | object *args; |
| 920 | { |
| 921 | return (object *)newmfsiobject(); |
| 922 | } |
| 923 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 924 | /* List of methods defined in the module */ |
| 925 | |
| 926 | static struct methodlist mfs_methods[] = { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 927 | {"ResolveAliasFile", mfs_ResolveAliasFile, 1}, |
| 928 | {"StandardGetFile", mfs_StandardGetFile, 1}, |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 929 | {"PromptGetFile", mfs_PromptGetFile, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 930 | {"StandardPutFile", mfs_StandardPutFile, 1}, |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 931 | {"GetDirectory", mfs_GetDirectory, 1}, |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 932 | {"SetFolder", mfs_SetFolder, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 933 | {"FSSpec", mfs_FSSpec, 1}, |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 934 | {"RawFSSpec", mfs_RawFSSpec, 1}, |
| 935 | {"RawAlias", mfs_RawAlias, 1}, |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 936 | {"FindFolder", mfs_FindFolder, 1}, |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 937 | {"FindApplication", mfs_FindApplication, 1}, |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 938 | {"FInfo", mfs_FInfo, 1}, |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 939 | |
| 940 | {NULL, NULL} /* sentinel */ |
| 941 | }; |
| 942 | |
| 943 | |
| 944 | /* Initialization function for the module (*must* be called initmacfs) */ |
| 945 | |
| 946 | void |
| 947 | initmacfs() |
| 948 | { |
| 949 | object *m, *d; |
| 950 | |
| 951 | /* Create the module and add the functions */ |
| 952 | m = initmodule("macfs", mfs_methods); |
| 953 | |
| 954 | /* Add some symbolic constants to the module */ |
| 955 | d = getmoduledict(m); |
| 956 | ErrorObject = newstringobject("macfs.error"); |
| 957 | dictinsert(d, "error", ErrorObject); |
| 958 | |
| 959 | /* XXXX Add constants here */ |
| 960 | |
| 961 | /* Check for errors */ |
| 962 | if (err_occurred()) |
| 963 | fatal("can't initialize module macfs"); |
| 964 | } |