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