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