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