Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 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 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 25 | #include "Python.h" |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 26 | #include "macglue.h" |
| 27 | |
Guido van Rossum | becdbec | 1995-02-14 01:27:24 +0000 | [diff] [blame] | 28 | #include <Memory.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 29 | #include <Files.h> |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 30 | #include <Folders.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 31 | #include <StandardFile.h> |
| 32 | #include <Aliases.h> |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 33 | #include <LowMem.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 34 | |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 35 | #include "getapplbycreator.h" |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | a42960c | 1995-01-19 00:03:47 +0000 | [diff] [blame] | 37 | #ifdef THINK_C |
| 38 | #define FileFilterUPP FileFilterProcPtr |
| 39 | #endif |
| 40 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 41 | static PyObject *ErrorObject; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 42 | |
| 43 | /* ----------------------------------------------------- */ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 44 | /* Declarations for objects of type Alias */ |
| 45 | |
| 46 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 47 | PyObject_HEAD |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 48 | AliasHandle alias; |
| 49 | } mfsaobject; |
| 50 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 51 | staticforward PyTypeObject Mfsatype; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 52 | |
| 53 | #define is_mfsaobject(v) ((v)->ob_type == &Mfsatype) |
| 54 | |
| 55 | /* ---------------------------------------------------------------- */ |
| 56 | /* Declarations for objects of type FSSpec */ |
| 57 | |
| 58 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 59 | PyObject_HEAD |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 60 | FSSpec fsspec; |
| 61 | } mfssobject; |
| 62 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 63 | staticforward PyTypeObject Mfsstype; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 64 | |
| 65 | #define is_mfssobject(v) ((v)->ob_type == &Mfsstype) |
| 66 | |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 67 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 68 | /* ---------------------------------------------------------------- */ |
| 69 | /* Declarations for objects of type FInfo */ |
| 70 | |
| 71 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 72 | PyObject_HEAD |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 73 | FInfo finfo; |
| 74 | } mfsiobject; |
| 75 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 76 | staticforward PyTypeObject Mfsitype; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 77 | |
| 78 | #define is_mfsiobject(v) ((v)->ob_type == &Mfsitype) |
| 79 | |
| 80 | |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 81 | mfssobject *newmfssobject(FSSpec *fss); /* Forward */ |
| 82 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 83 | /* ---------------------------------------------------------------- */ |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 84 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 85 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 86 | mfsa_Resolve(self, args) |
| 87 | mfsaobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 88 | PyObject *args; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 89 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 90 | FSSpec from, *fromp, result; |
| 91 | Boolean changed; |
| 92 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 93 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 94 | from.name[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 95 | if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 96 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 97 | if (from.name[0] ) |
| 98 | fromp = &from; |
| 99 | else |
| 100 | fromp = NULL; |
| 101 | err = ResolveAlias(fromp, self->alias, &result, &changed); |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 102 | if ( err && err != fnfErr ) { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 103 | PyErr_Mac(ErrorObject, err); |
| 104 | return NULL; |
| 105 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 106 | return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 109 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 110 | mfsa_GetInfo(self, args) |
| 111 | mfsaobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 112 | PyObject *args; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 113 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 114 | Str63 value; |
| 115 | int i; |
| 116 | OSErr err; |
| 117 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 118 | if (!PyArg_ParseTuple(args, "i", &i)) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 119 | return NULL; |
| 120 | err = GetAliasInfo(self->alias, (AliasInfoType)i, value); |
| 121 | if ( err ) { |
| 122 | PyErr_Mac(ErrorObject, err); |
| 123 | return 0; |
| 124 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 125 | return PyString_FromStringAndSize((char *)&value[1], value[0]); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 128 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 129 | mfsa_Update(self, args) |
| 130 | mfsaobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 131 | PyObject *args; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 132 | { |
| 133 | FSSpec target, fromfile, *fromfilep; |
| 134 | OSErr err; |
| 135 | Boolean changed; |
| 136 | |
| 137 | fromfile.name[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 138 | if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 139 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 150 | return Py_BuildValue("i", (int)changed); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 153 | static struct PyMethodDef mfsa_methods[] = { |
| 154 | {"Resolve", (PyCFunction)mfsa_Resolve, 1}, |
| 155 | {"GetInfo", (PyCFunction)mfsa_GetInfo, 1}, |
| 156 | {"Update", (PyCFunction)mfsa_Update, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 157 | |
| 158 | {NULL, NULL} /* sentinel */ |
| 159 | }; |
| 160 | |
| 161 | /* ---------- */ |
| 162 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 163 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 164 | mfsa_getattr(self, name) |
| 165 | mfsaobject *self; |
| 166 | char *name; |
| 167 | { |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 168 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 178 | return Py_FindMethod(mfsa_methods, (PyObject *)self, name); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | mfsaobject * |
| 182 | newmfsaobject(alias) |
| 183 | AliasHandle alias; |
| 184 | { |
| 185 | mfsaobject *self; |
| 186 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 187 | self = PyObject_NEW(mfsaobject, &Mfsatype); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 188 | if (self == NULL) |
| 189 | return NULL; |
| 190 | self->alias = alias; |
| 191 | return self; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | static void |
| 196 | mfsa_dealloc(self) |
| 197 | mfsaobject *self; |
| 198 | { |
| 199 | #if 0 |
| 200 | if ( self->alias ) { |
| 201 | should we do something here? |
| 202 | } |
| 203 | #endif |
| 204 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 205 | PyMem_DEL(self); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 208 | statichere PyTypeObject Mfsatype = { |
| 209 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 210 | 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 Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 216 | (printfunc)0, /*tp_print*/ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 217 | (getattrfunc)mfsa_getattr, /*tp_getattr*/ |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 218 | (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 Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | /* End of code for Alias objects */ |
| 228 | /* -------------------------------------------------------- */ |
| 229 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 230 | /* ---------------------------------------------------------------- */ |
| 231 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 232 | static struct PyMethodDef mfsi_methods[] = { |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 233 | |
| 234 | {NULL, NULL} /* sentinel */ |
| 235 | }; |
| 236 | |
| 237 | /* ---------- */ |
| 238 | |
| 239 | static mfsiobject * |
| 240 | newmfsiobject() |
| 241 | { |
| 242 | mfsiobject *self; |
| 243 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 244 | self = PyObject_NEW(mfsiobject, &Mfsitype); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 245 | if (self == NULL) |
| 246 | return NULL; |
| 247 | memset((char *)&self->finfo, '\0', sizeof(self->finfo)); |
| 248 | return self; |
| 249 | } |
| 250 | |
| 251 | static void |
| 252 | mfsi_dealloc(self) |
| 253 | mfsiobject *self; |
| 254 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 255 | PyMem_DEL(self); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 258 | static PyObject * |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 259 | mfsi_getattr(self, name) |
| 260 | mfsiobject *self; |
| 261 | char *name; |
| 262 | { |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 263 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 274 | return Py_FindMethod(mfsi_methods, (PyObject *)self, name); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | |
| 278 | static int |
| 279 | mfsi_setattr(self, name, v) |
| 280 | mfsiobject *self; |
| 281 | char *name; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 282 | PyObject *v; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 283 | { |
| 284 | int rv; |
| 285 | int i; |
| 286 | |
| 287 | if ( v == NULL ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 288 | PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 289 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 304 | PyErr_SetString(PyExc_AttributeError, "No such attribute"); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 305 | return -1; |
| 306 | } |
| 307 | if (rv) |
| 308 | return 0; |
| 309 | return -1; |
| 310 | } |
| 311 | |
| 312 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 313 | static PyTypeObject Mfsitype = { |
| 314 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 315 | 0, /*ob_size*/ |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 316 | "FInfo", /*tp_name*/ |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 317 | 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 Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 336 | /* |
| 337 | ** Helper routine for other modules: return an FSSpec * if the |
| 338 | ** object is a python fsspec object, else NULL |
| 339 | */ |
| 340 | FSSpec * |
| 341 | mfs_GetFSSpecFSSpec(self) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 342 | PyObject *self; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 343 | { |
| 344 | if ( is_mfssobject(self) ) |
| 345 | return &((mfssobject *)self)->fsspec; |
| 346 | return NULL; |
| 347 | } |
| 348 | |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 349 | /* |
| 350 | ** Two generally useful routines |
| 351 | */ |
| 352 | static OSErr |
| 353 | PyMac_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 | |
| 372 | static OSErr |
| 373 | PyMac_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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 397 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 398 | mfss_as_pathname(self, args) |
| 399 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 400 | PyObject *args; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 401 | { |
| 402 | char strbuf[257]; |
| 403 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 404 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 405 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 406 | return NULL; |
Jack Jansen | 84fb1fa | 1996-11-09 18:46:57 +0000 | [diff] [blame] | 407 | err = PyMac_GetFullPath(&self->fsspec, strbuf); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 408 | if ( err ) { |
| 409 | PyErr_Mac(ErrorObject, err); |
| 410 | return NULL; |
| 411 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 412 | return PyString_FromString(strbuf); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 415 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 416 | mfss_as_tuple(self, args) |
| 417 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 418 | PyObject *args; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 419 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 420 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 421 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 426 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 427 | mfss_NewAlias(self, args) |
| 428 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 429 | PyObject *args; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 430 | { |
| 431 | FSSpec src, *srcp; |
| 432 | OSErr err; |
| 433 | AliasHandle alias; |
| 434 | |
| 435 | src.name[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 436 | if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src)) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 437 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 448 | return (PyObject *)newmfsaobject(alias); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 451 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 452 | mfss_NewAliasMinimal(self, args) |
| 453 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 454 | PyObject *args; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 455 | { |
| 456 | OSErr err; |
| 457 | AliasHandle alias; |
| 458 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 459 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 460 | return NULL; |
| 461 | err = NewAliasMinimal(&self->fsspec, &alias); |
| 462 | if ( err ) { |
| 463 | PyErr_Mac(ErrorObject, err); |
| 464 | return NULL; |
| 465 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 466 | return (PyObject *)newmfsaobject(alias); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 469 | /* XXXX These routines should be replaced by a wrapper to the *FInfo routines */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 470 | static PyObject * |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 471 | mfss_GetCreatorType(self, args) |
| 472 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 473 | PyObject *args; |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 474 | { |
| 475 | OSErr err; |
| 476 | FInfo info; |
| 477 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 478 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 479 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 489 | static PyObject * |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 490 | mfss_SetCreatorType(self, args) |
| 491 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 492 | PyObject *args; |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 493 | { |
| 494 | OSErr err; |
| 495 | OSType creator, type; |
| 496 | FInfo info; |
| 497 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 498 | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 499 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 512 | Py_INCREF(Py_None); |
| 513 | return Py_None; |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 516 | static PyObject * |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 517 | mfss_GetFInfo(self, args) |
| 518 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 519 | PyObject *args; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 520 | { |
| 521 | OSErr err; |
| 522 | mfsiobject *fip; |
| 523 | |
| 524 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 525 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 526 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 532 | Py_DECREF(fip); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 533 | return NULL; |
| 534 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 535 | return (PyObject *)fip; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 538 | static PyObject * |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 539 | mfss_SetFInfo(self, args) |
| 540 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 541 | PyObject *args; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 542 | { |
| 543 | OSErr err; |
| 544 | mfsiobject *fip; |
| 545 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 546 | if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip)) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 547 | return NULL; |
| 548 | err = FSpSetFInfo(&self->fsspec, &fip->finfo); |
| 549 | if ( err ) { |
| 550 | PyErr_Mac(ErrorObject, err); |
| 551 | return NULL; |
| 552 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 553 | Py_INCREF(Py_None); |
| 554 | return Py_None; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 557 | static PyObject * |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 558 | mfss_GetDates(self, args) |
| 559 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 560 | PyObject *args; |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 561 | { |
| 562 | OSErr err; |
| 563 | unsigned long crdat, mddat, bkdat; |
| 564 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 565 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 566 | return NULL; |
| 567 | err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat); |
| 568 | if ( err ) { |
| 569 | PyErr_Mac(ErrorObject, err); |
| 570 | return NULL; |
| 571 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 572 | return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat); |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 575 | static PyObject * |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 576 | mfss_SetDates(self, args) |
| 577 | mfssobject *self; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 578 | PyObject *args; |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 579 | { |
| 580 | OSErr err; |
| 581 | double crdat, mddat, bkdat; |
| 582 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 583 | if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat)) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 584 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 591 | Py_INCREF(Py_None); |
| 592 | return Py_None; |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 595 | static 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 Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 606 | |
| 607 | {NULL, NULL} /* sentinel */ |
| 608 | }; |
| 609 | |
| 610 | /* ---------- */ |
| 611 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 612 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 613 | mfss_getattr(self, name) |
| 614 | mfssobject *self; |
| 615 | char *name; |
| 616 | { |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 617 | if ( strcmp(name, "data") == 0) |
| 618 | return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec)); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 619 | return Py_FindMethod(mfss_methods, (PyObject *)self, name); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | mfssobject * |
| 623 | newmfssobject(fss) |
| 624 | FSSpec *fss; |
| 625 | { |
| 626 | mfssobject *self; |
| 627 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 628 | self = PyObject_NEW(mfssobject, &Mfsstype); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 629 | if (self == NULL) |
| 630 | return NULL; |
| 631 | self->fsspec = *fss; |
| 632 | return self; |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | mfss_dealloc(self) |
| 637 | mfssobject *self; |
| 638 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 639 | PyMem_DEL(self); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 642 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 643 | mfss_repr(self) |
| 644 | mfssobject *self; |
| 645 | { |
| 646 | char buf[512]; |
| 647 | |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 648 | sprintf(buf, "FSSpec((%d, %d, '%.*s'))", |
| 649 | self->fsspec.vRefNum, |
| 650 | self->fsspec.parID, |
| 651 | self->fsspec.name[0], self->fsspec.name+1); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 652 | return PyString_FromString(buf); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static int |
| 656 | mfss_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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 675 | statichere PyTypeObject Mfsstype = { |
| 676 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 677 | 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 Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 697 | static PyObject * |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 698 | mfs_ResolveAliasFile(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 699 | PyObject *self; /* Not used */ |
| 700 | PyObject *args; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 701 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 702 | FSSpec fss; |
| 703 | Boolean chain = 1, isfolder, wasaliased; |
| 704 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 705 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 706 | if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 707 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 708 | err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased); |
| 709 | if ( err ) { |
| 710 | PyErr_Mac(ErrorObject, err); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 711 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 712 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 713 | return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 716 | static PyObject * |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 717 | mfs_StandardGetFile(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 718 | PyObject *self; /* Not used */ |
| 719 | PyObject *args; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 720 | { |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 721 | SFTypeList list; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 722 | short numtypes; |
| 723 | StandardFileReply reply; |
| 724 | |
| 725 | list[0] = list[1] = list[2] = list[3] = 0; |
| 726 | numtypes = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 727 | if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0], |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 728 | PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], |
| 729 | PyMac_GetOSType, &list[3]) ) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 730 | return NULL; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 731 | while ( numtypes < 4 && list[numtypes] ) { |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 732 | numtypes++; |
| 733 | } |
Jack Jansen | c263286 | 1995-06-03 21:15:50 +0000 | [diff] [blame] | 734 | if ( numtypes == 0 ) |
| 735 | numtypes = -1; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 736 | StandardGetFile((FileFilterUPP)0, numtypes, list, &reply); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 737 | return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 740 | static PyObject * |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 741 | mfs_PromptGetFile(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 742 | PyObject *self; /* Not used */ |
| 743 | PyObject *args; |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 744 | { |
| 745 | SFTypeList list; |
| 746 | short numtypes; |
| 747 | StandardFileReply reply; |
| 748 | char *prompt = NULL; |
| 749 | |
| 750 | list[0] = list[1] = list[2] = list[3] = 0; |
| 751 | numtypes = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 752 | if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0], |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 753 | PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], |
| 754 | PyMac_GetOSType, &list[3]) ) |
| 755 | return NULL; |
| 756 | while ( numtypes < 4 && list[numtypes] ) { |
| 757 | numtypes++; |
| 758 | } |
| 759 | if ( numtypes == 0 ) |
| 760 | numtypes = -1; |
| 761 | PyMac_PromptGetFile(numtypes, list, &reply, prompt); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 762 | return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 765 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 766 | mfs_StandardPutFile(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 767 | PyObject *self; /* Not used */ |
| 768 | PyObject *args; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 769 | { |
| 770 | Str255 prompt, dft; |
| 771 | StandardFileReply reply; |
| 772 | |
| 773 | dft[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 774 | if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) ) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 775 | return NULL; |
| 776 | StandardPutFile(prompt, dft, &reply); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 777 | return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 780 | /* |
| 781 | ** Set initial directory for file dialogs */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 782 | static PyObject * |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 783 | mfs_SetFolder(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 784 | PyObject *self; |
| 785 | PyObject *args; |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 786 | { |
| 787 | FSSpec spec; |
| 788 | FSSpec ospec; |
| 789 | short orefnum; |
| 790 | long oparid; |
| 791 | |
| 792 | /* Get old values */ |
| 793 | orefnum = -LMGetSFSaveDisk(); |
| 794 | oparid = LMGetCurDirStore(); |
| 795 | (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec); |
| 796 | |
| 797 | /* Go to working directory by default */ |
| 798 | (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 799 | if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec)) |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 800 | return NULL; |
| 801 | /* Set standard-file working directory */ |
| 802 | LMSetSFSaveDisk(-spec.vRefNum); |
| 803 | LMSetCurDirStore(spec.parID); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 804 | return (PyObject *)newmfssobject(&ospec); |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 807 | static PyObject * |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 808 | mfs_FSSpec(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 809 | PyObject *self; /* Not used */ |
| 810 | PyObject *args; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 811 | { |
| 812 | FSSpec fss; |
| 813 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 814 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 815 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 816 | return (PyObject *)newmfssobject(&fss); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 819 | static PyObject * |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 820 | mfs_RawFSSpec(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 821 | PyObject *self; /* Not used */ |
| 822 | PyObject *args; |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 823 | { |
| 824 | FSSpec *fssp; |
| 825 | int size; |
| 826 | |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 827 | if (!PyArg_ParseTuple(args, "s#", &fssp, &size)) |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 828 | return NULL; |
| 829 | if ( size != sizeof(FSSpec) ) { |
| 830 | PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record"); |
| 831 | return NULL; |
| 832 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 833 | return (PyObject *)newmfssobject(fssp); |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 836 | static PyObject * |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 837 | mfs_RawAlias(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 838 | PyObject *self; /* Not used */ |
| 839 | PyObject *args; |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 840 | { |
| 841 | char *dataptr; |
| 842 | Handle h; |
| 843 | int size; |
| 844 | |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 845 | if (!PyArg_ParseTuple(args, "s#", &dataptr, &size)) |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 846 | return NULL; |
| 847 | h = NewHandle(size); |
| 848 | if ( h == NULL ) { |
| 849 | PyErr_NoMemory(); |
| 850 | return NULL; |
| 851 | } |
| 852 | HLock(h); |
| 853 | memcpy((char *)*h, dataptr, size); |
| 854 | HUnlock(h); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 855 | return (PyObject *)newmfsaobject((AliasHandle)h); |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 858 | static PyObject * |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 859 | mfs_GetDirectory(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 860 | PyObject *self; /* Not used */ |
| 861 | PyObject *args; |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 862 | { |
| 863 | FSSpec fsdir; |
| 864 | int ok; |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 865 | char *prompt = NULL; |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 866 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 867 | if (!PyArg_ParseTuple(args, "|s", &prompt) ) |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 868 | return NULL; |
| 869 | |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 870 | ok = PyMac_GetDirectory(&fsdir, prompt); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 871 | return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok); |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 874 | static PyObject * |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 875 | mfs_FindFolder(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 876 | PyObject *self; /* Not used */ |
| 877 | PyObject *args; |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 878 | { |
| 879 | OSErr err; |
| 880 | short where; |
| 881 | OSType which; |
| 882 | int create; |
| 883 | short refnum; |
| 884 | long dirid; |
| 885 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 886 | if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) ) |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 887 | return NULL; |
| 888 | err = FindFolder(where, which, (Boolean)create, &refnum, &dirid); |
| 889 | if ( err ) { |
| 890 | PyErr_Mac(ErrorObject, err); |
| 891 | return NULL; |
| 892 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 893 | return Py_BuildValue("(ii)", refnum, dirid); |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 896 | static PyObject * |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 897 | mfs_FindApplication(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 898 | PyObject *self; /* Not used */ |
| 899 | PyObject *args; |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 900 | { |
| 901 | OSErr err; |
| 902 | OSType which; |
| 903 | FSSpec fss; |
| 904 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 905 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) ) |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 906 | return NULL; |
| 907 | err = FindApplicationFromCreator(which, &fss); |
| 908 | if ( err ) { |
| 909 | PyErr_Mac(ErrorObject, err); |
| 910 | return NULL; |
| 911 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 912 | return (PyObject *)newmfssobject(&fss); |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 915 | static PyObject * |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 916 | mfs_FInfo(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 917 | PyObject *self; |
| 918 | PyObject *args; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 919 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 920 | return (PyObject *)newmfsiobject(); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 923 | static PyObject * |
| 924 | mfs_NewAliasMinimalFromFullPath(self, args) |
| 925 | PyObject *self; /* Not used */ |
| 926 | PyObject *args; |
| 927 | { |
| 928 | OSErr err; |
| 929 | char *fullpath; |
| 930 | int fullpathlen; |
| 931 | AliasHandle alias; |
| 932 | Str32 zonename; |
| 933 | Str31 servername; |
| 934 | |
| 935 | if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) ) |
| 936 | return NULL; |
| 937 | zonename[0] = 0; |
| 938 | servername[0] = 0; |
| 939 | err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename, |
| 940 | servername, &alias); |
| 941 | if ( err ) { |
| 942 | PyErr_Mac(ErrorObject, err); |
| 943 | return NULL; |
| 944 | } |
| 945 | return (PyObject *)newmfsaobject(alias); |
| 946 | } |
| 947 | |
| 948 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 949 | /* List of methods defined in the module */ |
| 950 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 951 | static struct PyMethodDef mfs_methods[] = { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 952 | {"ResolveAliasFile", mfs_ResolveAliasFile, 1}, |
| 953 | {"StandardGetFile", mfs_StandardGetFile, 1}, |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 954 | {"PromptGetFile", mfs_PromptGetFile, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 955 | {"StandardPutFile", mfs_StandardPutFile, 1}, |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 956 | {"GetDirectory", mfs_GetDirectory, 1}, |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 957 | {"SetFolder", mfs_SetFolder, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 958 | {"FSSpec", mfs_FSSpec, 1}, |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 959 | {"RawFSSpec", mfs_RawFSSpec, 1}, |
| 960 | {"RawAlias", mfs_RawAlias, 1}, |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 961 | {"FindFolder", mfs_FindFolder, 1}, |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 962 | {"FindApplication", mfs_FindApplication, 1}, |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 963 | {"FInfo", mfs_FInfo, 1}, |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 964 | {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1}, |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 965 | |
| 966 | {NULL, NULL} /* sentinel */ |
| 967 | }; |
| 968 | |
| 969 | |
| 970 | /* Initialization function for the module (*must* be called initmacfs) */ |
| 971 | |
| 972 | void |
| 973 | initmacfs() |
| 974 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 975 | PyObject *m, *d; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 976 | |
| 977 | /* Create the module and add the functions */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 978 | m = Py_InitModule("macfs", mfs_methods); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 979 | |
| 980 | /* Add some symbolic constants to the module */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 981 | d = PyModule_GetDict(m); |
Jack Jansen | 55e3927 | 1997-10-07 21:47:25 +0000 | [diff] [blame] | 982 | ErrorObject = PyErr_NewException("macfs.error", NULL, NULL); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 983 | PyDict_SetItemString(d, "error", ErrorObject); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 984 | |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 985 | Mfsatype.ob_type = &PyType_Type; |
| 986 | Py_INCREF(&Mfsatype); |
| 987 | PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype); |
| 988 | Mfsstype.ob_type = &PyType_Type; |
| 989 | Py_INCREF(&Mfsstype); |
| 990 | PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype); |
| 991 | Mfsitype.ob_type = &PyType_Type; |
| 992 | Py_INCREF(&Mfsitype); |
| 993 | PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 994 | /* XXXX Add constants here */ |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 995 | } |