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