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