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