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" |
Jack Jansen | a5bca57 | 2001-08-03 15:39:27 +0000 | [diff] [blame] | 27 | #include "pymactoolbox.h" |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 28 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 29 | #ifdef WITHOUT_FRAMEWORKS |
Guido van Rossum | becdbec | 1995-02-14 01:27:24 +0000 | [diff] [blame] | 30 | #include <Memory.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 31 | #include <Files.h> |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 32 | #include <Folders.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 33 | #include <StandardFile.h> |
| 34 | #include <Aliases.h> |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 35 | #include <LowMem.h> |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 36 | #else |
| 37 | #include <Carbon/Carbon.h> |
| 38 | #endif |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 39 | |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 40 | #include "getapplbycreator.h" |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 41 | |
Jack Jansen | a5bca57 | 2001-08-03 15:39:27 +0000 | [diff] [blame] | 42 | #ifdef USE_TOOLBOX_OBJECT_GLUE |
| 43 | extern int _PyMac_GetFSSpec(PyObject *, FSSpec *); |
| 44 | #define PyMac_GetFSSpec _PyMac_GetFSSpec |
| 45 | #endif |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 46 | static PyObject *ErrorObject; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 47 | |
| 48 | /* ----------------------------------------------------- */ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 49 | /* Declarations for objects of type Alias */ |
| 50 | |
| 51 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 52 | PyObject_HEAD |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 53 | AliasHandle alias; |
| 54 | } mfsaobject; |
| 55 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 56 | staticforward PyTypeObject Mfsatype; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 57 | |
| 58 | #define is_mfsaobject(v) ((v)->ob_type == &Mfsatype) |
| 59 | |
| 60 | /* ---------------------------------------------------------------- */ |
| 61 | /* Declarations for objects of type FSSpec */ |
| 62 | |
| 63 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 64 | PyObject_HEAD |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 65 | FSSpec fsspec; |
| 66 | } mfssobject; |
| 67 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 68 | staticforward PyTypeObject Mfsstype; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 69 | |
| 70 | #define is_mfssobject(v) ((v)->ob_type == &Mfsstype) |
| 71 | |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 72 | /* ---------------------------------------------------------------- */ |
| 73 | /* Declarations for objects of type FSRef */ |
| 74 | |
| 75 | typedef struct { |
| 76 | PyObject_HEAD |
| 77 | FSRef fsref; |
| 78 | } mfsrobject; |
| 79 | |
| 80 | staticforward PyTypeObject Mfsrtype; |
| 81 | |
| 82 | #define is_mfsrobject(v) ((v)->ob_type == &Mfsrtype) |
| 83 | |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 84 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 85 | /* ---------------------------------------------------------------- */ |
| 86 | /* Declarations for objects of type FInfo */ |
| 87 | |
| 88 | typedef struct { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 89 | PyObject_HEAD |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 90 | FInfo finfo; |
| 91 | } mfsiobject; |
| 92 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 93 | staticforward PyTypeObject Mfsitype; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 94 | |
| 95 | #define is_mfsiobject(v) ((v)->ob_type == &Mfsitype) |
| 96 | |
| 97 | |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 98 | staticforward mfssobject *newmfssobject(FSSpec *fss); /* Forward */ |
| 99 | staticforward mfsrobject *newmfsrobject(FSRef *fsr); /* Forward */ |
Guido van Rossum | efd9767 | 1995-01-26 22:56:16 +0000 | [diff] [blame] | 100 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 101 | /* ---------------------------------------------------------------- */ |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 102 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 103 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 104 | mfsa_Resolve(mfsaobject *self, PyObject *args) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 105 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 106 | FSSpec from, *fromp, result; |
| 107 | Boolean changed; |
| 108 | OSErr err; |
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 | from.name[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 111 | if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 112 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 113 | if (from.name[0] ) |
| 114 | fromp = &from; |
| 115 | else |
| 116 | fromp = NULL; |
| 117 | err = ResolveAlias(fromp, self->alias, &result, &changed); |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 118 | if ( err && err != fnfErr ) { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 119 | PyErr_Mac(ErrorObject, err); |
| 120 | return NULL; |
| 121 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 122 | return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 125 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 126 | mfsa_GetInfo(mfsaobject *self, PyObject *args) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 127 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 128 | Str63 value; |
| 129 | int i; |
| 130 | OSErr err; |
| 131 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 132 | if (!PyArg_ParseTuple(args, "i", &i)) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 133 | return NULL; |
| 134 | err = GetAliasInfo(self->alias, (AliasInfoType)i, value); |
| 135 | if ( err ) { |
| 136 | PyErr_Mac(ErrorObject, err); |
| 137 | return 0; |
| 138 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 139 | return PyString_FromStringAndSize((char *)&value[1], value[0]); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 142 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 143 | mfsa_Update(mfsaobject *self, PyObject *args) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 144 | { |
| 145 | FSSpec target, fromfile, *fromfilep; |
| 146 | OSErr err; |
| 147 | Boolean changed; |
| 148 | |
| 149 | fromfile.name[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 150 | if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 151 | PyMac_GetFSSpec, &fromfile)) |
| 152 | return NULL; |
| 153 | if ( fromfile.name[0] ) |
| 154 | fromfilep = &fromfile; |
| 155 | else |
| 156 | fromfilep = NULL; |
| 157 | err = UpdateAlias(fromfilep, &target, self->alias, &changed); |
| 158 | if ( err ) { |
| 159 | PyErr_Mac(ErrorObject, err); |
| 160 | return 0; |
| 161 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 162 | return Py_BuildValue("i", (int)changed); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 165 | static struct PyMethodDef mfsa_methods[] = { |
| 166 | {"Resolve", (PyCFunction)mfsa_Resolve, 1}, |
| 167 | {"GetInfo", (PyCFunction)mfsa_GetInfo, 1}, |
| 168 | {"Update", (PyCFunction)mfsa_Update, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 169 | |
| 170 | {NULL, NULL} /* sentinel */ |
| 171 | }; |
| 172 | |
| 173 | /* ---------- */ |
| 174 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 175 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 176 | mfsa_getattr(mfsaobject *self, char *name) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 177 | { |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 178 | if ( strcmp(name, "data") == 0 ) { |
| 179 | int size; |
| 180 | PyObject *rv; |
| 181 | |
| 182 | size = GetHandleSize((Handle)self->alias); |
| 183 | HLock((Handle)self->alias); |
| 184 | rv = PyString_FromStringAndSize(*(Handle)self->alias, size); |
| 185 | HUnlock((Handle)self->alias); |
| 186 | return rv; |
| 187 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 188 | return Py_FindMethod(mfsa_methods, (PyObject *)self, name); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Jack Jansen | 9ae898b | 2000-07-11 21:16:03 +0000 | [diff] [blame] | 191 | static mfsaobject * |
| 192 | newmfsaobject(AliasHandle alias) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 193 | { |
| 194 | mfsaobject *self; |
| 195 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 196 | self = PyObject_NEW(mfsaobject, &Mfsatype); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 197 | if (self == NULL) |
| 198 | return NULL; |
| 199 | self->alias = alias; |
| 200 | return self; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | static void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 205 | mfsa_dealloc(mfsaobject *self) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 206 | { |
| 207 | #if 0 |
| 208 | if ( self->alias ) { |
| 209 | should we do something here? |
| 210 | } |
| 211 | #endif |
| 212 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 213 | PyMem_DEL(self); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 216 | statichere PyTypeObject Mfsatype = { |
| 217 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 218 | 0, /*ob_size*/ |
| 219 | "Alias", /*tp_name*/ |
| 220 | sizeof(mfsaobject), /*tp_basicsize*/ |
| 221 | 0, /*tp_itemsize*/ |
| 222 | /* methods */ |
| 223 | (destructor)mfsa_dealloc, /*tp_dealloc*/ |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 224 | (printfunc)0, /*tp_print*/ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 225 | (getattrfunc)mfsa_getattr, /*tp_getattr*/ |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 226 | (setattrfunc)0, /*tp_setattr*/ |
| 227 | (cmpfunc)0, /*tp_compare*/ |
| 228 | (reprfunc)0, /*tp_repr*/ |
| 229 | 0, /*tp_as_number*/ |
| 230 | 0, /*tp_as_sequence*/ |
| 231 | 0, /*tp_as_mapping*/ |
| 232 | (hashfunc)0, /*tp_hash*/ |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | /* End of code for Alias objects */ |
| 236 | /* -------------------------------------------------------- */ |
| 237 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 238 | /* ---------------------------------------------------------------- */ |
| 239 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 240 | static struct PyMethodDef mfsi_methods[] = { |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 241 | |
| 242 | {NULL, NULL} /* sentinel */ |
| 243 | }; |
| 244 | |
| 245 | /* ---------- */ |
| 246 | |
| 247 | static mfsiobject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 248 | newmfsiobject(void) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 249 | { |
| 250 | mfsiobject *self; |
| 251 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 252 | self = PyObject_NEW(mfsiobject, &Mfsitype); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 253 | if (self == NULL) |
| 254 | return NULL; |
| 255 | memset((char *)&self->finfo, '\0', sizeof(self->finfo)); |
| 256 | return self; |
| 257 | } |
| 258 | |
| 259 | static void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 260 | mfsi_dealloc(mfsiobject *self) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 261 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 262 | PyMem_DEL(self); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 265 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 266 | mfsi_getattr(mfsiobject *self, char *name) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 267 | { |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 268 | if ( strcmp(name, "Type") == 0 ) |
| 269 | return PyMac_BuildOSType(self->finfo.fdType); |
| 270 | else if ( strcmp(name, "Creator") == 0 ) |
| 271 | return PyMac_BuildOSType(self->finfo.fdCreator); |
| 272 | else if ( strcmp(name, "Flags") == 0 ) |
| 273 | return Py_BuildValue("i", (int)self->finfo.fdFlags); |
| 274 | else if ( strcmp(name, "Location") == 0 ) |
| 275 | return PyMac_BuildPoint(self->finfo.fdLocation); |
| 276 | else if ( strcmp(name, "Fldr") == 0 ) |
| 277 | return Py_BuildValue("i", (int)self->finfo.fdFldr); |
| 278 | else |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 279 | return Py_FindMethod(mfsi_methods, (PyObject *)self, name); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
| 283 | static int |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 284 | mfsi_setattr(mfsiobject *self, char *name, PyObject *v) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 285 | { |
| 286 | int rv; |
| 287 | int i; |
| 288 | |
| 289 | if ( v == NULL ) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 290 | PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 291 | return -1; |
| 292 | } |
| 293 | if ( strcmp(name, "Type") == 0 ) |
| 294 | rv = PyMac_GetOSType(v, &self->finfo.fdType); |
| 295 | else if ( strcmp(name, "Creator") == 0 ) |
| 296 | rv = PyMac_GetOSType(v, &self->finfo.fdCreator); |
| 297 | else if ( strcmp(name, "Flags") == 0 ) { |
| 298 | rv = PyArg_Parse(v, "i", &i); |
| 299 | self->finfo.fdFlags = (short)i; |
| 300 | } else if ( strcmp(name, "Location") == 0 ) |
| 301 | rv = PyMac_GetPoint(v, &self->finfo.fdLocation); |
| 302 | else if ( strcmp(name, "Fldr") == 0 ) { |
| 303 | rv = PyArg_Parse(v, "i", &i); |
| 304 | self->finfo.fdFldr = (short)i; |
| 305 | } else { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 306 | PyErr_SetString(PyExc_AttributeError, "No such attribute"); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 307 | return -1; |
| 308 | } |
| 309 | if (rv) |
| 310 | return 0; |
| 311 | return -1; |
| 312 | } |
| 313 | |
| 314 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 315 | static PyTypeObject Mfsitype = { |
| 316 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 317 | 0, /*ob_size*/ |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 318 | "FInfo", /*tp_name*/ |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 319 | sizeof(mfsiobject), /*tp_basicsize*/ |
| 320 | 0, /*tp_itemsize*/ |
| 321 | /* methods */ |
| 322 | (destructor)mfsi_dealloc, /*tp_dealloc*/ |
| 323 | (printfunc)0, /*tp_print*/ |
| 324 | (getattrfunc)mfsi_getattr, /*tp_getattr*/ |
| 325 | (setattrfunc)mfsi_setattr, /*tp_setattr*/ |
| 326 | (cmpfunc)0, /*tp_compare*/ |
| 327 | (reprfunc)0, /*tp_repr*/ |
| 328 | 0, /*tp_as_number*/ |
| 329 | 0, /*tp_as_sequence*/ |
| 330 | 0, /*tp_as_mapping*/ |
| 331 | (hashfunc)0, /*tp_hash*/ |
| 332 | }; |
| 333 | |
| 334 | /* End of code for FInfo object objects */ |
| 335 | /* -------------------------------------------------------- */ |
| 336 | |
| 337 | |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 338 | /* |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 339 | ** Helper routines for the FSRef and FSSpec creators in macglue.c |
| 340 | ** They return an FSSpec/FSRef if the Python object encapsulating |
| 341 | ** either is passed. They return a boolean success indicator. |
| 342 | ** Note that they do not set an exception on failure, they're only |
| 343 | ** helper routines. |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 344 | */ |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 345 | static int |
| 346 | _mfs_GetFSSpecFromFSSpec(PyObject *self, FSSpec *fssp) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 347 | { |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 348 | if ( is_mfssobject(self) ) { |
| 349 | *fssp = ((mfssobject *)self)->fsspec; |
| 350 | return 1; |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | /* Return an FSSpec if this is an FSref */ |
| 356 | static int |
| 357 | _mfs_GetFSSpecFromFSRef(PyObject *self, FSSpec *fssp) |
| 358 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 359 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 360 | static FSRef *fsrp; |
| 361 | |
| 362 | if ( is_mfsrobject(self) ) { |
| 363 | fsrp = &((mfsrobject *)self)->fsref; |
| 364 | if ( FSGetCatalogInfo(&((mfsrobject *)self)->fsref, kFSCatInfoNone, NULL, NULL, fssp, NULL) == noErr ) |
| 365 | return 1; |
| 366 | } |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 367 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | /* Return an FSRef if this is an FSRef */ |
| 372 | static int |
| 373 | _mfs_GetFSRefFromFSRef(PyObject *self, FSRef *fsrp) |
| 374 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 375 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 376 | if ( is_mfsrobject(self) ) { |
| 377 | *fsrp = ((mfsrobject *)self)->fsref; |
| 378 | return 1; |
| 379 | } |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 380 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* Return an FSRef if this is an FSSpec */ |
| 385 | static int |
| 386 | _mfs_GetFSRefFromFSSpec(PyObject *self, FSRef *fsrp) |
| 387 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 388 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 389 | if ( is_mfssobject(self) ) { |
| 390 | if ( FSpMakeFSRef(&((mfssobject *)self)->fsspec, fsrp) == noErr ) |
| 391 | return 1; |
| 392 | } |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 393 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 394 | return 0; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 397 | /* |
| 398 | ** Two generally useful routines |
| 399 | */ |
| 400 | static OSErr |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 401 | PyMac_GetFileDates(FSSpec *fss, unsigned long *crdat, unsigned long *mddat, |
| 402 | unsigned long *bkdat) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 403 | { |
| 404 | CInfoPBRec pb; |
| 405 | OSErr error; |
| 406 | |
| 407 | pb.dirInfo.ioNamePtr = fss->name; |
| 408 | pb.dirInfo.ioFDirIndex = 0; |
| 409 | pb.dirInfo.ioVRefNum = fss->vRefNum; |
| 410 | pb.dirInfo.ioDrDirID = fss->parID; |
| 411 | error = PBGetCatInfoSync(&pb); |
| 412 | if ( error ) return error; |
| 413 | *crdat = pb.hFileInfo.ioFlCrDat; |
| 414 | *mddat = pb.hFileInfo.ioFlMdDat; |
| 415 | *bkdat = pb.hFileInfo.ioFlBkDat; |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static OSErr |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 420 | PyMac_SetFileDates(FSSpec *fss, unsigned long crdat, unsigned long mddat, |
| 421 | unsigned long bkdat) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 422 | { |
| 423 | CInfoPBRec pb; |
| 424 | OSErr error; |
| 425 | |
| 426 | pb.dirInfo.ioNamePtr = fss->name; |
| 427 | pb.dirInfo.ioFDirIndex = 0; |
| 428 | pb.dirInfo.ioVRefNum = fss->vRefNum; |
| 429 | pb.dirInfo.ioDrDirID = fss->parID; |
| 430 | error = PBGetCatInfoSync(&pb); |
| 431 | if ( error ) return error; |
| 432 | pb.dirInfo.ioNamePtr = fss->name; |
| 433 | pb.dirInfo.ioFDirIndex = 0; |
| 434 | pb.dirInfo.ioVRefNum = fss->vRefNum; |
| 435 | pb.dirInfo.ioDrDirID = fss->parID; |
| 436 | pb.hFileInfo.ioFlCrDat = crdat; |
| 437 | pb.hFileInfo.ioFlMdDat = mddat; |
| 438 | pb.hFileInfo.ioFlBkDat = bkdat; |
| 439 | error = PBSetCatInfoSync(&pb); |
| 440 | return error; |
| 441 | } |
| 442 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 443 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 444 | mfss_as_pathname(mfssobject *self, PyObject *args) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 445 | { |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 446 | #if TARGET_API_MAC_OSX |
| 447 | PyErr_SetString(PyExc_NotImplementedError, "FSSpec.as_pathname not supported on this platform"); |
| 448 | return 0; |
| 449 | #else |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 450 | char strbuf[257]; |
| 451 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 452 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 453 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 454 | return NULL; |
Jack Jansen | 84fb1fa | 1996-11-09 18:46:57 +0000 | [diff] [blame] | 455 | err = PyMac_GetFullPath(&self->fsspec, strbuf); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 456 | if ( err ) { |
| 457 | PyErr_Mac(ErrorObject, err); |
| 458 | return NULL; |
| 459 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 460 | return PyString_FromString(strbuf); |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 461 | #endif |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 464 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 465 | mfss_as_tuple(mfssobject *self, PyObject *args) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 466 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 467 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 468 | return NULL; |
| 469 | return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID, |
| 470 | &self->fsspec.name[1], self->fsspec.name[0]); |
| 471 | } |
| 472 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 473 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 474 | mfss_NewAlias(mfssobject *self, PyObject *args) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 475 | { |
| 476 | FSSpec src, *srcp; |
| 477 | OSErr err; |
| 478 | AliasHandle alias; |
| 479 | |
| 480 | src.name[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 481 | if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src)) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 482 | return NULL; |
| 483 | if ( src.name[0] ) |
| 484 | srcp = &src; |
| 485 | else |
| 486 | srcp = NULL; |
| 487 | err = NewAlias(srcp, &self->fsspec, &alias); |
| 488 | if ( err ) { |
| 489 | PyErr_Mac(ErrorObject, err); |
| 490 | return NULL; |
| 491 | } |
| 492 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 493 | return (PyObject *)newmfsaobject(alias); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 496 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 497 | mfss_NewAliasMinimal(mfssobject *self, PyObject *args) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 498 | { |
| 499 | OSErr err; |
| 500 | AliasHandle alias; |
| 501 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 502 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 503 | return NULL; |
| 504 | err = NewAliasMinimal(&self->fsspec, &alias); |
| 505 | if ( err ) { |
| 506 | PyErr_Mac(ErrorObject, err); |
| 507 | return NULL; |
| 508 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 509 | return (PyObject *)newmfsaobject(alias); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 512 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 513 | mfss_FSpMakeFSRef(mfssobject *self, PyObject *args) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 514 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 515 | #if TARGET_API_MAC_OS8 |
| 516 | PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform"); |
| 517 | return 0; |
| 518 | #else |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 519 | OSErr err; |
| 520 | FSRef fsref; |
| 521 | |
| 522 | if (!PyArg_ParseTuple(args, "")) |
| 523 | return NULL; |
| 524 | err = FSpMakeFSRef(&self->fsspec, &fsref); |
| 525 | if ( err ) { |
| 526 | PyErr_Mac(ErrorObject, err); |
| 527 | return NULL; |
| 528 | } |
| 529 | return (PyObject *)newmfsrobject(&fsref); |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 530 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 533 | /* 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] | 534 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 535 | mfss_GetCreatorType(mfssobject *self, PyObject *args) |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 536 | { |
| 537 | OSErr err; |
| 538 | FInfo info; |
| 539 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 540 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 541 | return NULL; |
| 542 | err = FSpGetFInfo(&self->fsspec, &info); |
| 543 | if ( err ) { |
| 544 | PyErr_Mac(ErrorObject, err); |
| 545 | return NULL; |
| 546 | } |
| 547 | return Py_BuildValue("(O&O&)", |
| 548 | PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType); |
| 549 | } |
| 550 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 551 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 552 | mfss_SetCreatorType(mfssobject *self, PyObject *args) |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 553 | { |
| 554 | OSErr err; |
| 555 | OSType creator, type; |
| 556 | FInfo info; |
| 557 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 558 | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 559 | return NULL; |
| 560 | err = FSpGetFInfo(&self->fsspec, &info); |
| 561 | if ( err ) { |
| 562 | PyErr_Mac(ErrorObject, err); |
| 563 | return NULL; |
| 564 | } |
| 565 | info.fdType = type; |
| 566 | info.fdCreator = creator; |
| 567 | err = FSpSetFInfo(&self->fsspec, &info); |
| 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 | Py_INCREF(Py_None); |
| 573 | return Py_None; |
Jack Jansen | 8828fcf | 1995-02-02 14:23:52 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 576 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 577 | mfss_GetFInfo(mfssobject *self, PyObject *args) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 578 | { |
| 579 | OSErr err; |
| 580 | mfsiobject *fip; |
| 581 | |
| 582 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 583 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 584 | return NULL; |
| 585 | if ( (fip=newmfsiobject()) == NULL ) |
| 586 | return NULL; |
| 587 | err = FSpGetFInfo(&self->fsspec, &fip->finfo); |
| 588 | if ( err ) { |
| 589 | PyErr_Mac(ErrorObject, err); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 590 | Py_DECREF(fip); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 591 | return NULL; |
| 592 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 593 | return (PyObject *)fip; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 596 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 597 | mfss_SetFInfo(mfssobject *self, PyObject *args) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 598 | { |
| 599 | OSErr err; |
| 600 | mfsiobject *fip; |
| 601 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 602 | if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip)) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 603 | return NULL; |
| 604 | err = FSpSetFInfo(&self->fsspec, &fip->finfo); |
| 605 | if ( err ) { |
| 606 | PyErr_Mac(ErrorObject, err); |
| 607 | return NULL; |
| 608 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 609 | Py_INCREF(Py_None); |
| 610 | return Py_None; |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 613 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 614 | mfss_GetDates(mfssobject *self, PyObject *args) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 615 | { |
| 616 | OSErr err; |
| 617 | unsigned long crdat, mddat, bkdat; |
| 618 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 619 | if (!PyArg_ParseTuple(args, "")) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 620 | return NULL; |
| 621 | err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat); |
| 622 | if ( err ) { |
| 623 | PyErr_Mac(ErrorObject, err); |
| 624 | return NULL; |
| 625 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 626 | return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat); |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 629 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 630 | mfss_SetDates(mfssobject *self, PyObject *args) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 631 | { |
| 632 | OSErr err; |
| 633 | double crdat, mddat, bkdat; |
| 634 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 635 | if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat)) |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 636 | return NULL; |
| 637 | err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat, |
| 638 | (unsigned long)mddat, (unsigned long)bkdat); |
| 639 | if ( err ) { |
| 640 | PyErr_Mac(ErrorObject, err); |
| 641 | return NULL; |
| 642 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 643 | Py_INCREF(Py_None); |
| 644 | return Py_None; |
Jack Jansen | 0bdf979 | 1996-09-15 22:11:25 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 647 | static struct PyMethodDef mfss_methods[] = { |
| 648 | {"as_pathname", (PyCFunction)mfss_as_pathname, 1}, |
| 649 | {"as_tuple", (PyCFunction)mfss_as_tuple, 1}, |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 650 | {"as_fsref", (PyCFunction)mfss_FSpMakeFSRef, 1}, |
| 651 | {"FSpMakeFSRef", (PyCFunction)mfss_FSpMakeFSRef, 1}, |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 652 | {"NewAlias", (PyCFunction)mfss_NewAlias, 1}, |
| 653 | {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1}, |
| 654 | {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1}, |
| 655 | {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1}, |
| 656 | {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1}, |
| 657 | {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1}, |
| 658 | {"GetDates", (PyCFunction)mfss_GetDates, 1}, |
| 659 | {"SetDates", (PyCFunction)mfss_SetDates, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 660 | |
| 661 | {NULL, NULL} /* sentinel */ |
| 662 | }; |
| 663 | |
| 664 | /* ---------- */ |
| 665 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 666 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 667 | mfss_getattr(mfssobject *self, char *name) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 668 | { |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 669 | if ( strcmp(name, "data") == 0) |
| 670 | return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec)); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 671 | return Py_FindMethod(mfss_methods, (PyObject *)self, name); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | mfssobject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 675 | newmfssobject(FSSpec *fss) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 676 | { |
| 677 | mfssobject *self; |
| 678 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 679 | self = PyObject_NEW(mfssobject, &Mfsstype); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 680 | if (self == NULL) |
| 681 | return NULL; |
| 682 | self->fsspec = *fss; |
| 683 | return self; |
| 684 | } |
| 685 | |
| 686 | static void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 687 | mfss_dealloc(mfssobject *self) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 688 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 689 | PyMem_DEL(self); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 692 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 693 | mfss_repr(mfssobject *self) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 694 | { |
| 695 | char buf[512]; |
| 696 | |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 697 | sprintf(buf, "FSSpec((%d, %ld, '%.*s'))", |
Guido van Rossum | f45b53b | 1995-02-20 23:43:29 +0000 | [diff] [blame] | 698 | self->fsspec.vRefNum, |
| 699 | self->fsspec.parID, |
| 700 | self->fsspec.name[0], self->fsspec.name+1); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 701 | return PyString_FromString(buf); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static int |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 705 | mfss_compare(mfssobject *v, mfssobject *w) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 706 | { |
| 707 | int minlen; |
| 708 | int res; |
| 709 | |
| 710 | if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1; |
| 711 | if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1; |
| 712 | if ( v->fsspec.parID < w->fsspec.parID ) return -1; |
| 713 | if ( v->fsspec.parID > w->fsspec.parID ) return 1; |
| 714 | minlen = v->fsspec.name[0]; |
| 715 | if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0]; |
| 716 | res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen); |
| 717 | if ( res ) return res; |
| 718 | if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1; |
| 719 | if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1; |
| 720 | return res; |
| 721 | } |
| 722 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 723 | statichere PyTypeObject Mfsstype = { |
| 724 | PyObject_HEAD_INIT(&PyType_Type) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 725 | 0, /*ob_size*/ |
| 726 | "FSSpec", /*tp_name*/ |
| 727 | sizeof(mfssobject), /*tp_basicsize*/ |
| 728 | 0, /*tp_itemsize*/ |
| 729 | /* methods */ |
| 730 | (destructor)mfss_dealloc, /*tp_dealloc*/ |
| 731 | (printfunc)0, /*tp_print*/ |
| 732 | (getattrfunc)mfss_getattr, /*tp_getattr*/ |
| 733 | (setattrfunc)0, /*tp_setattr*/ |
| 734 | (cmpfunc)mfss_compare, /*tp_compare*/ |
| 735 | (reprfunc)mfss_repr, /*tp_repr*/ |
| 736 | 0, /*tp_as_number*/ |
| 737 | 0, /*tp_as_sequence*/ |
| 738 | 0, /*tp_as_mapping*/ |
| 739 | (hashfunc)0, /*tp_hash*/ |
| 740 | }; |
| 741 | |
| 742 | /* End of code for FSSpec objects */ |
| 743 | /* -------------------------------------------------------- */ |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 744 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 745 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 746 | mfsr_as_fsspec(mfsrobject *self, PyObject *args) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 747 | { |
| 748 | OSErr err; |
| 749 | FSSpec fss; |
| 750 | |
| 751 | if (!PyArg_ParseTuple(args, "")) |
| 752 | return NULL; |
| 753 | err = FSGetCatalogInfo(&self->fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL); |
| 754 | if ( err ) { |
| 755 | PyErr_Mac(ErrorObject, err); |
| 756 | return NULL; |
| 757 | } |
| 758 | Py_INCREF(Py_None); |
| 759 | return (PyObject *)newmfssobject(&fss); |
| 760 | } |
| 761 | |
| 762 | static struct PyMethodDef mfsr_methods[] = { |
| 763 | {"as_fsspec", (PyCFunction)mfsr_as_fsspec, 1}, |
| 764 | #if 0 |
| 765 | {"as_pathname", (PyCFunction)mfss_as_pathname, 1}, |
| 766 | {"as_tuple", (PyCFunction)mfss_as_tuple, 1}, |
| 767 | {"NewAlias", (PyCFunction)mfss_NewAlias, 1}, |
| 768 | {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1}, |
| 769 | {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1}, |
| 770 | {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1}, |
| 771 | {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1}, |
| 772 | {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1}, |
| 773 | {"GetDates", (PyCFunction)mfss_GetDates, 1}, |
| 774 | {"SetDates", (PyCFunction)mfss_SetDates, 1}, |
| 775 | #endif |
| 776 | |
| 777 | {NULL, NULL} /* sentinel */ |
| 778 | }; |
| 779 | |
| 780 | /* ---------- */ |
| 781 | |
| 782 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 783 | mfsr_getattr(mfsrobject *self, char *name) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 784 | { |
| 785 | if ( strcmp(name, "data") == 0) |
| 786 | return PyString_FromStringAndSize((char *)&self->fsref, sizeof(FSRef)); |
| 787 | return Py_FindMethod(mfsr_methods, (PyObject *)self, name); |
| 788 | } |
| 789 | |
| 790 | mfsrobject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 791 | newmfsrobject(FSRef *fsr) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 792 | { |
| 793 | mfsrobject *self; |
| 794 | |
| 795 | self = PyObject_NEW(mfsrobject, &Mfsrtype); |
| 796 | if (self == NULL) |
| 797 | return NULL; |
| 798 | self->fsref = *fsr; |
| 799 | return self; |
| 800 | } |
| 801 | |
| 802 | static int |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 803 | mfsr_compare(mfsrobject *v, mfsrobject *w) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 804 | { |
| 805 | OSErr err; |
| 806 | |
| 807 | if ( v == w ) return 0; |
| 808 | err = FSCompareFSRefs(&v->fsref, &w->fsref); |
| 809 | if ( err == 0 ) |
| 810 | return 0; |
| 811 | if (v < w ) |
| 812 | return -1; |
| 813 | return 1; |
| 814 | } |
| 815 | |
| 816 | static void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 817 | mfsr_dealloc(mfsrobject *self) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 818 | { |
| 819 | PyMem_DEL(self); |
| 820 | } |
| 821 | |
| 822 | statichere PyTypeObject Mfsrtype = { |
| 823 | PyObject_HEAD_INIT(&PyType_Type) |
| 824 | 0, /*ob_size*/ |
| 825 | "FSRef", /*tp_name*/ |
| 826 | sizeof(mfsrobject), /*tp_basicsize*/ |
| 827 | 0, /*tp_itemsize*/ |
| 828 | /* methods */ |
| 829 | (destructor)mfsr_dealloc, /*tp_dealloc*/ |
| 830 | (printfunc)0, /*tp_print*/ |
| 831 | (getattrfunc)mfsr_getattr, /*tp_getattr*/ |
| 832 | (setattrfunc)0, /*tp_setattr*/ |
| 833 | (cmpfunc)mfsr_compare, /*tp_compare*/ |
| 834 | (reprfunc)0, /*tp_repr*/ |
| 835 | 0, /*tp_as_number*/ |
| 836 | 0, /*tp_as_sequence*/ |
| 837 | 0, /*tp_as_mapping*/ |
| 838 | (hashfunc)0, /*tp_hash*/ |
| 839 | }; |
| 840 | |
| 841 | /* End of code for FSRef objects */ |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 842 | #endif /* !TARGET_API_MAC_OS8 */ |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 843 | /* -------------------------------------------------------- */ |
| 844 | |
| 845 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 846 | mfs_ResolveAliasFile(PyObject *self, PyObject *args) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 847 | { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 848 | FSSpec fss; |
| 849 | Boolean chain = 1, isfolder, wasaliased; |
| 850 | OSErr err; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 851 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 852 | if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 853 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 854 | err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased); |
| 855 | if ( err ) { |
| 856 | PyErr_Mac(ErrorObject, err); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 857 | return NULL; |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 858 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 859 | return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 862 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 863 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 864 | mfs_StandardGetFile(PyObject *self, PyObject *args) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 865 | { |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 866 | SFTypeList list; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 867 | short numtypes; |
| 868 | StandardFileReply reply; |
| 869 | |
| 870 | list[0] = list[1] = list[2] = list[3] = 0; |
| 871 | numtypes = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 872 | if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0], |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 873 | PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], |
| 874 | PyMac_GetOSType, &list[3]) ) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 875 | return NULL; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 876 | while ( numtypes < 4 && list[numtypes] ) { |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 877 | numtypes++; |
| 878 | } |
Jack Jansen | c263286 | 1995-06-03 21:15:50 +0000 | [diff] [blame] | 879 | if ( numtypes == 0 ) |
| 880 | numtypes = -1; |
Guido van Rossum | b2f524a | 1995-01-30 08:56:06 +0000 | [diff] [blame] | 881 | StandardGetFile((FileFilterUPP)0, numtypes, list, &reply); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 882 | return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 885 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 886 | mfs_PromptGetFile(PyObject *self, PyObject *args) |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 887 | { |
| 888 | SFTypeList list; |
| 889 | short numtypes; |
| 890 | StandardFileReply reply; |
| 891 | char *prompt = NULL; |
| 892 | |
| 893 | list[0] = list[1] = list[2] = list[3] = 0; |
| 894 | numtypes = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 895 | 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] | 896 | PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], |
| 897 | PyMac_GetOSType, &list[3]) ) |
| 898 | return NULL; |
| 899 | while ( numtypes < 4 && list[numtypes] ) { |
| 900 | numtypes++; |
| 901 | } |
| 902 | if ( numtypes == 0 ) |
| 903 | numtypes = -1; |
| 904 | PyMac_PromptGetFile(numtypes, list, &reply, prompt); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 905 | return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 908 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 909 | mfs_StandardPutFile(PyObject *self, PyObject *args) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 910 | { |
| 911 | Str255 prompt, dft; |
| 912 | StandardFileReply reply; |
| 913 | |
| 914 | dft[0] = 0; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 915 | if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) ) |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 916 | return NULL; |
| 917 | StandardPutFile(prompt, dft, &reply); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 918 | return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood); |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 921 | /* |
| 922 | ** Set initial directory for file dialogs */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 923 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 924 | mfs_SetFolder(PyObject *self, PyObject *args) |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 925 | { |
| 926 | FSSpec spec; |
| 927 | FSSpec ospec; |
| 928 | short orefnum; |
| 929 | long oparid; |
| 930 | |
| 931 | /* Get old values */ |
| 932 | orefnum = -LMGetSFSaveDisk(); |
| 933 | oparid = LMGetCurDirStore(); |
| 934 | (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec); |
| 935 | |
| 936 | /* Go to working directory by default */ |
| 937 | (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 938 | if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec)) |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 939 | return NULL; |
| 940 | /* Set standard-file working directory */ |
| 941 | LMSetSFSaveDisk(-spec.vRefNum); |
| 942 | LMSetCurDirStore(spec.parID); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 943 | return (PyObject *)newmfssobject(&ospec); |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 944 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 945 | #endif |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 946 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 947 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 948 | mfs_FSSpec(PyObject *self, PyObject *args) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 949 | { |
| 950 | FSSpec fss; |
| 951 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 952 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss)) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 953 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 954 | return (PyObject *)newmfssobject(&fss); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 957 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 958 | mfs_FSRef(PyObject *self, PyObject *args) |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 959 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 960 | #if TARGET_API_MAC_OS8 |
| 961 | PyErr_SetString(PyExc_NotImplementedError, "FSRef objects not supported on this platform"); |
| 962 | return 0; |
| 963 | #else |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 964 | FSRef fsr; |
| 965 | |
| 966 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &fsr)) |
| 967 | return NULL; |
| 968 | return (PyObject *)newmfsrobject(&fsr); |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 969 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 973 | mfs_RawFSSpec(PyObject *self, PyObject *args) |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 974 | { |
| 975 | FSSpec *fssp; |
| 976 | int size; |
| 977 | |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 978 | if (!PyArg_ParseTuple(args, "s#", &fssp, &size)) |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 979 | return NULL; |
| 980 | if ( size != sizeof(FSSpec) ) { |
| 981 | PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record"); |
| 982 | return NULL; |
| 983 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 984 | return (PyObject *)newmfssobject(fssp); |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 987 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 988 | mfs_RawAlias(PyObject *self, PyObject *args) |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 989 | { |
| 990 | char *dataptr; |
| 991 | Handle h; |
| 992 | int size; |
| 993 | |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 994 | if (!PyArg_ParseTuple(args, "s#", &dataptr, &size)) |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 995 | return NULL; |
| 996 | h = NewHandle(size); |
| 997 | if ( h == NULL ) { |
| 998 | PyErr_NoMemory(); |
| 999 | return NULL; |
| 1000 | } |
| 1001 | HLock(h); |
| 1002 | memcpy((char *)*h, dataptr, size); |
| 1003 | HUnlock(h); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1004 | return (PyObject *)newmfsaobject((AliasHandle)h); |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1007 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1008 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 1009 | mfs_GetDirectory(PyObject *self, PyObject *args) |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 1010 | { |
| 1011 | FSSpec fsdir; |
| 1012 | int ok; |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 1013 | char *prompt = NULL; |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 1014 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1015 | if (!PyArg_ParseTuple(args, "|s", &prompt) ) |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 1016 | return NULL; |
| 1017 | |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 1018 | ok = PyMac_GetDirectory(&fsdir, prompt); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1019 | return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok); |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 1020 | } |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 1021 | #endif |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 1022 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1023 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 1024 | mfs_FindFolder(PyObject *self, PyObject *args) |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 1025 | { |
| 1026 | OSErr err; |
| 1027 | short where; |
| 1028 | OSType which; |
| 1029 | int create; |
| 1030 | short refnum; |
| 1031 | long dirid; |
| 1032 | |
Jack Jansen | abd703d | 2001-03-15 14:38:10 +0000 | [diff] [blame] | 1033 | if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) ) |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 1034 | return NULL; |
| 1035 | err = FindFolder(where, which, (Boolean)create, &refnum, &dirid); |
| 1036 | if ( err ) { |
| 1037 | PyErr_Mac(ErrorObject, err); |
| 1038 | return NULL; |
| 1039 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1040 | return Py_BuildValue("(ii)", refnum, dirid); |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1043 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 1044 | mfs_FindApplication(PyObject *self, PyObject *args) |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 1045 | { |
| 1046 | OSErr err; |
| 1047 | OSType which; |
| 1048 | FSSpec fss; |
| 1049 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1050 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) ) |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 1051 | return NULL; |
| 1052 | err = FindApplicationFromCreator(which, &fss); |
| 1053 | if ( err ) { |
| 1054 | PyErr_Mac(ErrorObject, err); |
| 1055 | return NULL; |
| 1056 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1057 | return (PyObject *)newmfssobject(&fss); |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1060 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 1061 | mfs_FInfo(PyObject *self, PyObject *args) |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 1062 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1063 | return (PyObject *)newmfsiobject(); |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 1066 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 1067 | mfs_NewAliasMinimalFromFullPath(PyObject *self, PyObject *args) |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 1068 | { |
| 1069 | OSErr err; |
| 1070 | char *fullpath; |
| 1071 | int fullpathlen; |
| 1072 | AliasHandle alias; |
| 1073 | Str32 zonename; |
| 1074 | Str31 servername; |
| 1075 | |
| 1076 | if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) ) |
| 1077 | return NULL; |
| 1078 | zonename[0] = 0; |
| 1079 | servername[0] = 0; |
| 1080 | err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename, |
| 1081 | servername, &alias); |
| 1082 | if ( err ) { |
| 1083 | PyErr_Mac(ErrorObject, err); |
| 1084 | return NULL; |
| 1085 | } |
| 1086 | return (PyObject *)newmfsaobject(alias); |
| 1087 | } |
| 1088 | |
| 1089 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1090 | /* List of methods defined in the module */ |
| 1091 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1092 | static struct PyMethodDef mfs_methods[] = { |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 1093 | {"ResolveAliasFile", mfs_ResolveAliasFile, 1}, |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1094 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 1095 | {"StandardGetFile", mfs_StandardGetFile, 1}, |
Jack Jansen | d5d5f46 | 1995-08-14 12:22:56 +0000 | [diff] [blame] | 1096 | {"PromptGetFile", mfs_PromptGetFile, 1}, |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 1097 | {"StandardPutFile", mfs_StandardPutFile, 1}, |
Jack Jansen | 81f51c7 | 1995-02-20 15:45:25 +0000 | [diff] [blame] | 1098 | {"GetDirectory", mfs_GetDirectory, 1}, |
Jack Jansen | d99d283 | 1996-07-22 15:26:01 +0000 | [diff] [blame] | 1099 | {"SetFolder", mfs_SetFolder, 1}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1100 | #endif |
Jack Jansen | 17ba43f | 1995-01-26 16:22:07 +0000 | [diff] [blame] | 1101 | {"FSSpec", mfs_FSSpec, 1}, |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1102 | {"FSRef", mfs_FSRef, 1}, |
Jack Jansen | c889b76 | 1995-02-13 12:00:46 +0000 | [diff] [blame] | 1103 | {"RawFSSpec", mfs_RawFSSpec, 1}, |
| 1104 | {"RawAlias", mfs_RawAlias, 1}, |
Jack Jansen | 2c67362 | 1995-06-18 20:05:14 +0000 | [diff] [blame] | 1105 | {"FindFolder", mfs_FindFolder, 1}, |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 1106 | {"FindApplication", mfs_FindApplication, 1}, |
Jack Jansen | 3d18593 | 1995-08-07 14:04:10 +0000 | [diff] [blame] | 1107 | {"FInfo", mfs_FInfo, 1}, |
Jack Jansen | d993648 | 1997-06-16 14:31:38 +0000 | [diff] [blame] | 1108 | {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1}, |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1109 | |
| 1110 | {NULL, NULL} /* sentinel */ |
| 1111 | }; |
| 1112 | |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1113 | /* |
| 1114 | ** Convert a Python object to an FSSpec. |
| 1115 | ** The object may either be a full pathname, an FSSpec, an FSRef or a triple |
| 1116 | ** (vrefnum, dirid, path). |
| 1117 | */ |
| 1118 | int |
| 1119 | PyMac_GetFSRef(PyObject *v, FSRef *fsr) |
| 1120 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 1121 | #if TARGET_API_MAC_OS8 |
| 1122 | return 0; |
| 1123 | #else |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1124 | /* If it's an FSRef we're also okay. */ |
| 1125 | if (_mfs_GetFSRefFromFSRef(v, fsr)) |
| 1126 | return 1; |
| 1127 | /* first check whether it already is an FSSpec */ |
| 1128 | if ( _mfs_GetFSRefFromFSSpec(v, fsr) ) |
| 1129 | return 1; |
| 1130 | if ( PyString_Check(v) ) { |
Jack Jansen | a5bca57 | 2001-08-03 15:39:27 +0000 | [diff] [blame] | 1131 | #if TARGET_API_MAC_OSX |
| 1132 | OSStatus err; |
| 1133 | if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) { |
| 1134 | PyErr_Mac(ErrorObject, err); |
| 1135 | return 0; |
| 1136 | } |
| 1137 | return 1; |
| 1138 | #else |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1139 | PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform"); |
| 1140 | return 0; |
Jack Jansen | a5bca57 | 2001-08-03 15:39:27 +0000 | [diff] [blame] | 1141 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1142 | } |
| 1143 | PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname"); |
| 1144 | return 0; |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 1145 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | /* Convert FSSpec to PyObject */ |
| 1149 | PyObject *PyMac_BuildFSRef(FSRef *v) |
| 1150 | { |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 1151 | #if TARGET_API_MAC_OS8 |
| 1152 | return NULL; |
| 1153 | #else |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1154 | return (PyObject *)newmfsrobject(v); |
Jack Jansen | cbed91b | 2001-08-03 13:31:36 +0000 | [diff] [blame] | 1155 | #endif |
Jack Jansen | 4e566ab | 2001-07-08 22:07:23 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | /* |
| 1159 | ** Convert a Python object to an FSRef. |
| 1160 | ** The object may either be a full pathname (OSX only), an FSSpec or an FSRef. |
| 1161 | */ |
| 1162 | int |
| 1163 | PyMac_GetFSSpec(PyObject *v, FSSpec *fs) |
| 1164 | { |
| 1165 | Str255 path; |
| 1166 | short refnum; |
| 1167 | long parid; |
| 1168 | OSErr err; |
| 1169 | |
| 1170 | /* first check whether it already is an FSSpec */ |
| 1171 | if ( _mfs_GetFSSpecFromFSSpec(v, fs) ) |
| 1172 | return 1; |
| 1173 | /* If it's an FSRef we're also okay. */ |
| 1174 | if (_mfs_GetFSSpecFromFSRef(v, fs)) |
| 1175 | return 1; |
| 1176 | if ( PyString_Check(v) ) { |
| 1177 | /* It's a pathname */ |
| 1178 | if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) ) |
| 1179 | return 0; |
| 1180 | refnum = 0; /* XXXX Should get CurWD here?? */ |
| 1181 | parid = 0; |
| 1182 | } else { |
| 1183 | if( !PyArg_Parse(v, "(hlO&); FSSpec should be FSSpec, FSRef, fullpath or (vrefnum,dirid,path)", |
| 1184 | &refnum, &parid, PyMac_GetStr255, &path)) { |
| 1185 | return 0; |
| 1186 | } |
| 1187 | } |
| 1188 | err = FSMakeFSSpec(refnum, parid, path, fs); |
| 1189 | if ( err && err != fnfErr ) { |
| 1190 | PyMac_Error(err); |
| 1191 | return 0; |
| 1192 | } |
| 1193 | return 1; |
| 1194 | } |
| 1195 | |
| 1196 | /* Convert FSSpec to PyObject */ |
| 1197 | PyObject *PyMac_BuildFSSpec(FSSpec *v) |
| 1198 | { |
| 1199 | return (PyObject *)newmfssobject(v); |
| 1200 | } |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1201 | |
| 1202 | /* Initialization function for the module (*must* be called initmacfs) */ |
| 1203 | |
| 1204 | void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 1205 | initmacfs(void) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1206 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1207 | PyObject *m, *d; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1208 | |
Jack Jansen | 4590049 | 2001-08-06 15:32:30 +0000 | [diff] [blame] | 1209 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec); |
Jack Jansen | a5bca57 | 2001-08-03 15:39:27 +0000 | [diff] [blame] | 1210 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1211 | /* Create the module and add the functions */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1212 | m = Py_InitModule("macfs", mfs_methods); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1213 | |
| 1214 | /* Add some symbolic constants to the module */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1215 | d = PyModule_GetDict(m); |
Jack Jansen | 4377a1a | 2000-01-24 10:37:59 +0000 | [diff] [blame] | 1216 | ErrorObject = PyMac_GetOSErrException(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 1217 | PyDict_SetItemString(d, "error", ErrorObject); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1218 | |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1219 | Mfsatype.ob_type = &PyType_Type; |
| 1220 | Py_INCREF(&Mfsatype); |
| 1221 | PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype); |
| 1222 | Mfsstype.ob_type = &PyType_Type; |
| 1223 | Py_INCREF(&Mfsstype); |
| 1224 | PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype); |
| 1225 | Mfsitype.ob_type = &PyType_Type; |
| 1226 | Py_INCREF(&Mfsitype); |
| 1227 | PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1228 | /* XXXX Add constants here */ |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1229 | } |