| 1 | n/a | # This script generates a Python interface for an Apple Macintosh Manager. |
|---|
| 2 | n/a | # It uses the "bgen" package to generate C code. |
|---|
| 3 | n/a | # The function specifications are generated by scanning the mamager's header file, |
|---|
| 4 | n/a | # using the "scantools" package (customized for this particular manager). |
|---|
| 5 | n/a | # |
|---|
| 6 | n/a | # XXXX TO DO: |
|---|
| 7 | n/a | # - Implement correct missing FSSpec handling for Alias methods |
|---|
| 8 | n/a | # - Implement FInfo |
|---|
| 9 | n/a | # |
|---|
| 10 | n/a | # WARNING WARNING WARNING |
|---|
| 11 | n/a | # The file _Filemodule.c was modified manually, don't run this script |
|---|
| 12 | n/a | # unless you really know what you're doing. |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | import sys |
|---|
| 15 | n/a | sys.exit(42) |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | import string |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | # Declarations that change for each manager |
|---|
| 20 | n/a | #MACHEADERFILE = 'Files.h' # The Apple header file |
|---|
| 21 | n/a | MODNAME = '_File' # The name of the module |
|---|
| 22 | n/a | LONGMODNAME = 'Carbon.File' # The "normal" external name of the module |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | # The following is *usually* unchanged but may still require tuning |
|---|
| 25 | n/a | MODPREFIX = 'File' # The prefix for module-wide routines |
|---|
| 26 | n/a | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|---|
| 27 | n/a | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|---|
| 28 | n/a | |
|---|
| 29 | n/a | from macsupport import * |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | # Various integers: |
|---|
| 32 | n/a | SInt64 = Type("SInt64", "L") |
|---|
| 33 | n/a | UInt64 = Type("UInt64", "L") |
|---|
| 34 | n/a | FNMessage = Type("FNMessage", "l") |
|---|
| 35 | n/a | FSAllocationFlags = Type("FSAllocationFlags", "H") |
|---|
| 36 | n/a | FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l") |
|---|
| 37 | n/a | FSIteratorFlags = Type("FSIteratorFlags", "l") |
|---|
| 38 | n/a | FSVolumeRefNum = Type("FSVolumeRefNum", "h") |
|---|
| 39 | n/a | AliasInfoType = Type("AliasInfoType", "h") |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | # Various types of strings: |
|---|
| 42 | n/a | #class UniCharCountBuffer(InputOnlyType): |
|---|
| 43 | n/a | # pass |
|---|
| 44 | n/a | class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType): |
|---|
| 45 | n/a | pass |
|---|
| 46 | n/a | FullPathName = VarReverseInputBufferType() |
|---|
| 47 | n/a | ConstStr31Param = OpaqueArrayType("Str31", "PyMac_BuildStr255", "PyMac_GetStr255") |
|---|
| 48 | n/a | ConstStr32Param = OpaqueArrayType("Str32", "PyMac_BuildStr255", "PyMac_GetStr255") |
|---|
| 49 | n/a | ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255") |
|---|
| 50 | n/a | Str63 = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255") |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255") |
|---|
| 53 | n/a | UInt8_ptr = InputOnlyType("UInt8 *", "s") |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | # Other types: |
|---|
| 56 | n/a | class OptionalFSxxxType(OpaqueByValueType): |
|---|
| 57 | n/a | def declare(self, name): |
|---|
| 58 | n/a | Output("%s %s__buf__;", self.typeName, name) |
|---|
| 59 | n/a | Output("%s *%s = &%s__buf__;", self.typeName, name, name) |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | class FSCatalogInfoAndBitmapType(InputOnlyType): |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | def __init__(self): |
|---|
| 64 | n/a | InputOnlyType.__init__(self, "BUG", "BUG") |
|---|
| 65 | n/a | |
|---|
| 66 | n/a | def declare(self, name): |
|---|
| 67 | n/a | Output("PyObject *%s__object = NULL;", name) |
|---|
| 68 | n/a | Output("FSCatalogInfoBitmap %s__bitmap = 0;", name) |
|---|
| 69 | n/a | Output("FSCatalogInfo %s;", name) |
|---|
| 70 | n/a | |
|---|
| 71 | n/a | def getargsFormat(self): |
|---|
| 72 | n/a | return "lO" |
|---|
| 73 | n/a | |
|---|
| 74 | n/a | def getargsArgs(self, name): |
|---|
| 75 | n/a | return "%s__bitmap, %s__object"%(name, name) |
|---|
| 76 | n/a | |
|---|
| 77 | n/a | def getargsCheck(self, name): |
|---|
| 78 | n/a | Output("if (!convert_FSCatalogInfo(%s__object, %s__bitmap, &%s)) return NULL;", name, name, name) |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | def passInput(self, name): |
|---|
| 81 | n/a | return "%s__bitmap, &%s"% (name, name) |
|---|
| 82 | n/a | |
|---|
| 83 | n/a | def passOutput(self, name): |
|---|
| 84 | n/a | return "%s__bitmap, &%s"% (name, name) |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | def mkvalueFormat(self): |
|---|
| 87 | n/a | return "O" |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | def mkvalueArgs(self, name): |
|---|
| 90 | n/a | return "%s__object" % (name) |
|---|
| 91 | n/a | |
|---|
| 92 | n/a | def xxxxmkvalueCheck(self, name): |
|---|
| 93 | n/a | Output("if ((%s__object = new_FSCatalogInfo(%s__bitmap, &%s)) == NULL) return NULL;", name, name) |
|---|
| 94 | n/a | |
|---|
| 95 | n/a | class FSCatalogInfoAndBitmap_inType(FSCatalogInfoAndBitmapType, InputOnlyMixIn): |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | def xxxxmkvalueCheck(self, name): |
|---|
| 98 | n/a | pass |
|---|
| 99 | n/a | |
|---|
| 100 | n/a | class FSCatalogInfoAndBitmap_outType(FSCatalogInfoAndBitmapType): |
|---|
| 101 | n/a | |
|---|
| 102 | n/a | def getargsFormat(self): |
|---|
| 103 | n/a | return "l" |
|---|
| 104 | n/a | |
|---|
| 105 | n/a | def getargsArgs(self, name): |
|---|
| 106 | n/a | return "%s__bitmap" % name |
|---|
| 107 | n/a | |
|---|
| 108 | n/a | def getargsCheck(self, name): |
|---|
| 109 | n/a | pass |
|---|
| 110 | n/a | |
|---|
| 111 | n/a | FInfo = OpaqueType("FInfo", "FInfo") |
|---|
| 112 | n/a | FInfo_ptr = OpaqueType("FInfo", "FInfo") |
|---|
| 113 | n/a | AliasHandle = OpaqueByValueType("AliasHandle", "Alias") |
|---|
| 114 | n/a | FSSpec = OpaqueType("FSSpec", "FSSpec") |
|---|
| 115 | n/a | FSSpec_ptr = OpaqueType("FSSpec", "FSSpec") |
|---|
| 116 | n/a | OptFSSpecPtr = OptionalFSxxxType("FSSpec", "BUG", "myPyMac_GetOptFSSpecPtr") |
|---|
| 117 | n/a | FSRef = OpaqueType("FSRef", "FSRef") |
|---|
| 118 | n/a | FSRef_ptr = OpaqueType("FSRef", "FSRef") |
|---|
| 119 | n/a | OptFSRefPtr = OptionalFSxxxType("FSRef", "BUG", "myPyMac_GetOptFSRefPtr") |
|---|
| 120 | n/a | FSCatalogInfo = OpaqueType("FSCatalogInfo", "FSCatalogInfo") |
|---|
| 121 | n/a | FSCatalogInfo_ptr = OpaqueType("FSCatalogInfo", "FSCatalogInfo") |
|---|
| 122 | n/a | |
|---|
| 123 | n/a | # To be done: |
|---|
| 124 | n/a | #CatPositionRec |
|---|
| 125 | n/a | #FSCatalogInfo |
|---|
| 126 | n/a | #FSForkInfo |
|---|
| 127 | n/a | #FSIterator |
|---|
| 128 | n/a | #FSVolumeInfo |
|---|
| 129 | n/a | #FSSpecArrayPtr |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | includestuff = includestuff + """ |
|---|
| 132 | n/a | #include <Carbon/Carbon.h> |
|---|
| 133 | n/a | |
|---|
| 134 | n/a | #ifdef USE_TOOLBOX_OBJECT_GLUE |
|---|
| 135 | n/a | extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec); |
|---|
| 136 | n/a | extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr); |
|---|
| 137 | n/a | extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec); |
|---|
| 138 | n/a | extern PyObject *_PyMac_BuildFSRef(FSRef *spec); |
|---|
| 139 | n/a | |
|---|
| 140 | n/a | #define PyMac_GetFSSpec _PyMac_GetFSSpec |
|---|
| 141 | n/a | #define PyMac_GetFSRef _PyMac_GetFSRef |
|---|
| 142 | n/a | #define PyMac_BuildFSSpec _PyMac_BuildFSSpec |
|---|
| 143 | n/a | #define PyMac_BuildFSRef _PyMac_BuildFSRef |
|---|
| 144 | n/a | #else |
|---|
| 145 | n/a | extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec); |
|---|
| 146 | n/a | extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr); |
|---|
| 147 | n/a | extern PyObject *PyMac_BuildFSSpec(FSSpec *spec); |
|---|
| 148 | n/a | extern PyObject *PyMac_BuildFSRef(FSRef *spec); |
|---|
| 149 | n/a | #endif |
|---|
| 150 | n/a | |
|---|
| 151 | n/a | /* Forward declarations */ |
|---|
| 152 | n/a | static PyObject *FInfo_New(FInfo *itself); |
|---|
| 153 | n/a | static PyObject *FSRef_New(FSRef *itself); |
|---|
| 154 | n/a | static PyObject *FSSpec_New(FSSpec *itself); |
|---|
| 155 | n/a | static PyObject *Alias_New(AliasHandle itself); |
|---|
| 156 | n/a | static int FInfo_Convert(PyObject *v, FInfo *p_itself); |
|---|
| 157 | n/a | #define FSRef_Convert PyMac_GetFSRef |
|---|
| 158 | n/a | #define FSSpec_Convert PyMac_GetFSSpec |
|---|
| 159 | n/a | static int Alias_Convert(PyObject *v, AliasHandle *p_itself); |
|---|
| 160 | n/a | |
|---|
| 161 | n/a | /* |
|---|
| 162 | n/a | ** UTCDateTime records |
|---|
| 163 | n/a | */ |
|---|
| 164 | n/a | static int |
|---|
| 165 | n/a | UTCDateTime_Convert(PyObject *v, UTCDateTime *ptr) |
|---|
| 166 | n/a | { |
|---|
| 167 | n/a | return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction); |
|---|
| 168 | n/a | } |
|---|
| 169 | n/a | |
|---|
| 170 | n/a | static PyObject * |
|---|
| 171 | n/a | UTCDateTime_New(UTCDateTime *ptr) |
|---|
| 172 | n/a | { |
|---|
| 173 | n/a | return Py_BuildValue("(HlH)", ptr->highSeconds, ptr->lowSeconds, ptr->fraction); |
|---|
| 174 | n/a | } |
|---|
| 175 | n/a | |
|---|
| 176 | n/a | /* |
|---|
| 177 | n/a | ** Optional fsspec and fsref pointers. None will pass NULL |
|---|
| 178 | n/a | */ |
|---|
| 179 | n/a | static int |
|---|
| 180 | n/a | myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec) |
|---|
| 181 | n/a | { |
|---|
| 182 | n/a | if (v == Py_None) { |
|---|
| 183 | n/a | *spec = NULL; |
|---|
| 184 | n/a | return 1; |
|---|
| 185 | n/a | } |
|---|
| 186 | n/a | return PyMac_GetFSSpec(v, *spec); |
|---|
| 187 | n/a | } |
|---|
| 188 | n/a | |
|---|
| 189 | n/a | static int |
|---|
| 190 | n/a | myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref) |
|---|
| 191 | n/a | { |
|---|
| 192 | n/a | if (v == Py_None) { |
|---|
| 193 | n/a | *ref = NULL; |
|---|
| 194 | n/a | return 1; |
|---|
| 195 | n/a | } |
|---|
| 196 | n/a | return PyMac_GetFSRef(v, *ref); |
|---|
| 197 | n/a | } |
|---|
| 198 | n/a | |
|---|
| 199 | n/a | /* |
|---|
| 200 | n/a | ** Parse/generate objsect |
|---|
| 201 | n/a | */ |
|---|
| 202 | n/a | static PyObject * |
|---|
| 203 | n/a | PyMac_BuildHFSUniStr255(HFSUniStr255 *itself) |
|---|
| 204 | n/a | { |
|---|
| 205 | n/a | |
|---|
| 206 | n/a | return Py_BuildValue("u#", itself->unicode, itself->length); |
|---|
| 207 | n/a | } |
|---|
| 208 | n/a | |
|---|
| 209 | n/a | #ifndef __LP64__ |
|---|
| 210 | n/a | /* |
|---|
| 211 | n/a | ** Get pathname for a given FSSpec |
|---|
| 212 | n/a | */ |
|---|
| 213 | n/a | static OSErr |
|---|
| 214 | n/a | _PyMac_GetFullPathname(FSSpec *fss, char *path, int len) |
|---|
| 215 | n/a | { |
|---|
| 216 | n/a | FSRef fsr; |
|---|
| 217 | n/a | OSErr err; |
|---|
| 218 | n/a | |
|---|
| 219 | n/a | *path = '\0'; |
|---|
| 220 | n/a | err = FSpMakeFSRef(fss, &fsr); |
|---|
| 221 | n/a | if (err == fnfErr) { |
|---|
| 222 | n/a | /* FSSpecs can point to non-existing files, fsrefs can't. */ |
|---|
| 223 | n/a | FSSpec fss2; |
|---|
| 224 | n/a | int tocopy; |
|---|
| 225 | n/a | |
|---|
| 226 | n/a | err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2); |
|---|
| 227 | n/a | if (err) |
|---|
| 228 | n/a | return err; |
|---|
| 229 | n/a | err = FSpMakeFSRef(&fss2, &fsr); |
|---|
| 230 | n/a | if (err) |
|---|
| 231 | n/a | return err; |
|---|
| 232 | n/a | err = (OSErr)FSRefMakePath(&fsr, path, len-1); |
|---|
| 233 | n/a | if (err) |
|---|
| 234 | n/a | return err; |
|---|
| 235 | n/a | /* This part is not 100% safe: we append the filename part, but |
|---|
| 236 | n/a | ** I'm not sure that we don't run afoul of the various 8bit |
|---|
| 237 | n/a | ** encodings here. Will have to look this up at some point... |
|---|
| 238 | n/a | */ |
|---|
| 239 | n/a | strcat(path, "/"); |
|---|
| 240 | n/a | tocopy = fss->name[0]; |
|---|
| 241 | n/a | if ((strlen(path) + tocopy) >= len) |
|---|
| 242 | n/a | tocopy = len - strlen(path) - 1; |
|---|
| 243 | n/a | if (tocopy > 0) |
|---|
| 244 | n/a | strncat(path, fss->name+1, tocopy); |
|---|
| 245 | n/a | } |
|---|
| 246 | n/a | else { |
|---|
| 247 | n/a | if (err) |
|---|
| 248 | n/a | return err; |
|---|
| 249 | n/a | err = (OSErr)FSRefMakePath(&fsr, path, len); |
|---|
| 250 | n/a | if (err) |
|---|
| 251 | n/a | return err; |
|---|
| 252 | n/a | } |
|---|
| 253 | n/a | return 0; |
|---|
| 254 | n/a | } |
|---|
| 255 | n/a | #endif /* !__LP64__ */ |
|---|
| 256 | n/a | |
|---|
| 257 | n/a | """ |
|---|
| 258 | n/a | |
|---|
| 259 | n/a | finalstuff = finalstuff + """ |
|---|
| 260 | n/a | |
|---|
| 261 | n/a | #ifndef __LP64__ |
|---|
| 262 | n/a | int |
|---|
| 263 | n/a | PyMac_GetFSSpec(PyObject *v, FSSpec *spec) |
|---|
| 264 | n/a | { |
|---|
| 265 | n/a | Str255 path; |
|---|
| 266 | n/a | short refnum; |
|---|
| 267 | n/a | long parid; |
|---|
| 268 | n/a | OSErr err; |
|---|
| 269 | n/a | FSRef fsr; |
|---|
| 270 | n/a | |
|---|
| 271 | n/a | if (FSSpec_Check(v)) { |
|---|
| 272 | n/a | *spec = ((FSSpecObject *)v)->ob_itself; |
|---|
| 273 | n/a | return 1; |
|---|
| 274 | n/a | } |
|---|
| 275 | n/a | |
|---|
| 276 | n/a | if (PyArg_Parse(v, "(hlO&)", |
|---|
| 277 | n/a | &refnum, &parid, PyMac_GetStr255, &path)) { |
|---|
| 278 | n/a | err = FSMakeFSSpec(refnum, parid, path, spec); |
|---|
| 279 | n/a | if ( err && err != fnfErr ) { |
|---|
| 280 | n/a | PyMac_Error(err); |
|---|
| 281 | n/a | return 0; |
|---|
| 282 | n/a | } |
|---|
| 283 | n/a | return 1; |
|---|
| 284 | n/a | } |
|---|
| 285 | n/a | PyErr_Clear(); |
|---|
| 286 | n/a | /* Otherwise we try to go via an FSRef. On OSX we go all the way, |
|---|
| 287 | n/a | ** on OS9 we accept only a real FSRef object |
|---|
| 288 | n/a | */ |
|---|
| 289 | n/a | if ( PyMac_GetFSRef(v, &fsr) ) { |
|---|
| 290 | n/a | err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL); |
|---|
| 291 | n/a | if (err != noErr) { |
|---|
| 292 | n/a | PyMac_Error(err); |
|---|
| 293 | n/a | return 0; |
|---|
| 294 | n/a | } |
|---|
| 295 | n/a | return 1; |
|---|
| 296 | n/a | } |
|---|
| 297 | n/a | return 0; |
|---|
| 298 | n/a | } |
|---|
| 299 | n/a | |
|---|
| 300 | n/a | #endif /* !__LP64__ */ |
|---|
| 301 | n/a | |
|---|
| 302 | n/a | int |
|---|
| 303 | n/a | PyMac_GetFSRef(PyObject *v, FSRef *fsr) |
|---|
| 304 | n/a | { |
|---|
| 305 | n/a | OSStatus err; |
|---|
| 306 | n/a | FSSpec fss; |
|---|
| 307 | n/a | |
|---|
| 308 | n/a | if (FSRef_Check(v)) { |
|---|
| 309 | n/a | *fsr = ((FSRefObject *)v)->ob_itself; |
|---|
| 310 | n/a | return 1; |
|---|
| 311 | n/a | } |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | /* On OSX we now try a pathname */ |
|---|
| 314 | n/a | if ( PyString_Check(v) || PyUnicode_Check(v)) { |
|---|
| 315 | n/a | char *path = NULL; |
|---|
| 316 | n/a | if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path)) |
|---|
| 317 | n/a | return 0; |
|---|
| 318 | n/a | if ( (err=FSPathMakeRef(path, fsr, NULL)) ) |
|---|
| 319 | n/a | PyMac_Error(err); |
|---|
| 320 | n/a | PyMem_Free(path); |
|---|
| 321 | n/a | return !err; |
|---|
| 322 | n/a | } |
|---|
| 323 | n/a | /* XXXX Should try unicode here too */ |
|---|
| 324 | n/a | /* Otherwise we try to go via an FSSpec */ |
|---|
| 325 | n/a | #ifndef __LP64__ |
|---|
| 326 | n/a | if (FSSpec_Check(v)) { |
|---|
| 327 | n/a | fss = ((FSSpecObject *)v)->ob_itself; |
|---|
| 328 | n/a | if ((err=FSpMakeFSRef(&fss, fsr)) == 0) |
|---|
| 329 | n/a | return 1; |
|---|
| 330 | n/a | PyMac_Error(err); |
|---|
| 331 | n/a | return 0; |
|---|
| 332 | n/a | } |
|---|
| 333 | n/a | PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required"); |
|---|
| 334 | n/a | #else /* __LP64__ */ |
|---|
| 335 | n/a | PyErr_SetString(PyExc_TypeError, "FSRef or pathname required"); |
|---|
| 336 | n/a | #endif /* __LP64__ */ |
|---|
| 337 | n/a | return 0; |
|---|
| 338 | n/a | } |
|---|
| 339 | n/a | |
|---|
| 340 | n/a | #ifndef __LP64__ |
|---|
| 341 | n/a | extern PyObject * |
|---|
| 342 | n/a | PyMac_BuildFSSpec(FSSpec *spec) |
|---|
| 343 | n/a | { |
|---|
| 344 | n/a | return FSSpec_New(spec); |
|---|
| 345 | n/a | } |
|---|
| 346 | n/a | #endif /* __LP64__ */ |
|---|
| 347 | n/a | |
|---|
| 348 | n/a | extern PyObject * |
|---|
| 349 | n/a | PyMac_BuildFSRef(FSRef *spec) |
|---|
| 350 | n/a | { |
|---|
| 351 | n/a | return FSRef_New(spec); |
|---|
| 352 | n/a | } |
|---|
| 353 | n/a | """ |
|---|
| 354 | n/a | |
|---|
| 355 | n/a | initstuff = initstuff + """ |
|---|
| 356 | n/a | #ifndef __LP64__ |
|---|
| 357 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec); |
|---|
| 358 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec); |
|---|
| 359 | n/a | #endif /* !__LP64__*/ |
|---|
| 360 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef); |
|---|
| 361 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef); |
|---|
| 362 | n/a | """ |
|---|
| 363 | n/a | |
|---|
| 364 | n/a | execfile(string.lower(MODPREFIX) + 'typetest.py') |
|---|
| 365 | n/a | |
|---|
| 366 | n/a | # Our object types: |
|---|
| 367 | n/a | class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition): |
|---|
| 368 | n/a | getsetlist = [ |
|---|
| 369 | n/a | ("nodeFlags", |
|---|
| 370 | n/a | "return Py_BuildValue(\"H\", self->ob_itself.nodeFlags);", |
|---|
| 371 | n/a | "return PyArg_Parse(v, \"H\", &self->ob_itself.nodeFlags)-1;", |
|---|
| 372 | n/a | None |
|---|
| 373 | n/a | ), |
|---|
| 374 | n/a | ("volume", |
|---|
| 375 | n/a | "return Py_BuildValue(\"h\", self->ob_itself.volume);", |
|---|
| 376 | n/a | "return PyArg_Parse(v, \"h\", &self->ob_itself.volume)-1;", |
|---|
| 377 | n/a | None |
|---|
| 378 | n/a | ), |
|---|
| 379 | n/a | ("parentDirID", |
|---|
| 380 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.parentDirID);", |
|---|
| 381 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.parentDirID)-1;", |
|---|
| 382 | n/a | None |
|---|
| 383 | n/a | ), |
|---|
| 384 | n/a | ("nodeID", |
|---|
| 385 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.nodeID);", |
|---|
| 386 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.nodeID)-1;", |
|---|
| 387 | n/a | None |
|---|
| 388 | n/a | ), |
|---|
| 389 | n/a | ("createDate", |
|---|
| 390 | n/a | "return Py_BuildValue(\"O&\", UTCDateTime_New, &self->ob_itself.createDate);", |
|---|
| 391 | n/a | "return PyArg_Parse(v, \"O&\", UTCDateTime_Convert, &self->ob_itself.createDate)-1;", |
|---|
| 392 | n/a | None |
|---|
| 393 | n/a | ), |
|---|
| 394 | n/a | ("contentModDate", |
|---|
| 395 | n/a | "return Py_BuildValue(\"O&\", UTCDateTime_New, &self->ob_itself.contentModDate);", |
|---|
| 396 | n/a | "return PyArg_Parse(v, \"O&\", UTCDateTime_Convert, &self->ob_itself.contentModDate)-1;", |
|---|
| 397 | n/a | None |
|---|
| 398 | n/a | ), |
|---|
| 399 | n/a | ("attributeModDate", |
|---|
| 400 | n/a | "return Py_BuildValue(\"O&\", UTCDateTime_New, &self->ob_itself.attributeModDate);", |
|---|
| 401 | n/a | "return PyArg_Parse(v, \"O&\", UTCDateTime_Convert, &self->ob_itself.attributeModDate)-1;", |
|---|
| 402 | n/a | None |
|---|
| 403 | n/a | ), |
|---|
| 404 | n/a | ("accessDate", |
|---|
| 405 | n/a | "return Py_BuildValue(\"O&\", UTCDateTime_New, &self->ob_itself.accessDate);", |
|---|
| 406 | n/a | "return PyArg_Parse(v, \"O&\", UTCDateTime_Convert, &self->ob_itself.accessDate)-1;", |
|---|
| 407 | n/a | None |
|---|
| 408 | n/a | ), |
|---|
| 409 | n/a | ("backupDate", |
|---|
| 410 | n/a | "return Py_BuildValue(\"O&\", UTCDateTime_New, &self->ob_itself.backupDate);", |
|---|
| 411 | n/a | "return PyArg_Parse(v, \"O&\", UTCDateTime_Convert, &self->ob_itself.backupDate)-1;", |
|---|
| 412 | n/a | None |
|---|
| 413 | n/a | ), |
|---|
| 414 | n/a | ("permissions", |
|---|
| 415 | n/a | "return Py_BuildValue(\"(llll)\", self->ob_itself.permissions[0], self->ob_itself.permissions[1], self->ob_itself.permissions[2], self->ob_itself.permissions[3]);", |
|---|
| 416 | n/a | "return PyArg_Parse(v, \"(llll)\", &self->ob_itself.permissions[0], &self->ob_itself.permissions[1], &self->ob_itself.permissions[2], &self->ob_itself.permissions[3])-1;", |
|---|
| 417 | n/a | None |
|---|
| 418 | n/a | ), |
|---|
| 419 | n/a | # XXXX FinderInfo TBD |
|---|
| 420 | n/a | # XXXX FinderXInfo TBD |
|---|
| 421 | n/a | ("valence", |
|---|
| 422 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.valence);", |
|---|
| 423 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.valence)-1;", |
|---|
| 424 | n/a | None |
|---|
| 425 | n/a | ), |
|---|
| 426 | n/a | ("dataLogicalSize", |
|---|
| 427 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.dataLogicalSize);", |
|---|
| 428 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.dataLogicalSize)-1;", |
|---|
| 429 | n/a | None |
|---|
| 430 | n/a | ), |
|---|
| 431 | n/a | ("dataPhysicalSize", |
|---|
| 432 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.dataPhysicalSize);", |
|---|
| 433 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.dataPhysicalSize)-1;", |
|---|
| 434 | n/a | None |
|---|
| 435 | n/a | ), |
|---|
| 436 | n/a | ("rsrcLogicalSize", |
|---|
| 437 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.rsrcLogicalSize);", |
|---|
| 438 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.rsrcLogicalSize)-1;", |
|---|
| 439 | n/a | None |
|---|
| 440 | n/a | ), |
|---|
| 441 | n/a | ("rsrcPhysicalSize", |
|---|
| 442 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.rsrcPhysicalSize);", |
|---|
| 443 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.rsrcPhysicalSize)-1;", |
|---|
| 444 | n/a | None |
|---|
| 445 | n/a | ), |
|---|
| 446 | n/a | ("sharingFlags", |
|---|
| 447 | n/a | "return Py_BuildValue(\"l\", self->ob_itself.sharingFlags);", |
|---|
| 448 | n/a | "return PyArg_Parse(v, \"l\", &self->ob_itself.sharingFlags)-1;", |
|---|
| 449 | n/a | None |
|---|
| 450 | n/a | ), |
|---|
| 451 | n/a | ("userPrivileges", |
|---|
| 452 | n/a | "return Py_BuildValue(\"b\", self->ob_itself.userPrivileges);", |
|---|
| 453 | n/a | "return PyArg_Parse(v, \"b\", &self->ob_itself.userPrivileges)-1;", |
|---|
| 454 | n/a | None |
|---|
| 455 | n/a | ), |
|---|
| 456 | n/a | ] |
|---|
| 457 | n/a | # The same info, but in a different form |
|---|
| 458 | n/a | INITFORMAT = "HhllO&O&O&O&O&llllllb" |
|---|
| 459 | n/a | INITARGS = """&((FSCatalogInfoObject *)_self)->ob_itself.nodeFlags, |
|---|
| 460 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.volume, |
|---|
| 461 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.parentDirID, |
|---|
| 462 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.nodeID, |
|---|
| 463 | n/a | UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.createDate, |
|---|
| 464 | n/a | UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.contentModDate, |
|---|
| 465 | n/a | UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.attributeModDate, |
|---|
| 466 | n/a | UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.accessDate, |
|---|
| 467 | n/a | UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.backupDate, |
|---|
| 468 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.valence, |
|---|
| 469 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.dataLogicalSize, |
|---|
| 470 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.dataPhysicalSize, |
|---|
| 471 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.rsrcLogicalSize, |
|---|
| 472 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.rsrcPhysicalSize, |
|---|
| 473 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.sharingFlags, |
|---|
| 474 | n/a | &((FSCatalogInfoObject *)_self)->ob_itself.userPrivileges""" |
|---|
| 475 | n/a | INITNAMES = """ |
|---|
| 476 | n/a | "nodeFlags", |
|---|
| 477 | n/a | "volume", |
|---|
| 478 | n/a | "parentDirID", |
|---|
| 479 | n/a | "nodeID", |
|---|
| 480 | n/a | "createDate", |
|---|
| 481 | n/a | "contentModDate", |
|---|
| 482 | n/a | "atributeModDate", |
|---|
| 483 | n/a | "accessDate", |
|---|
| 484 | n/a | "backupDate", |
|---|
| 485 | n/a | "valence", |
|---|
| 486 | n/a | "dataLogicalSize", |
|---|
| 487 | n/a | "dataPhysicalSize", |
|---|
| 488 | n/a | "rsrcLogicalSize", |
|---|
| 489 | n/a | "rsrcPhysicalSize", |
|---|
| 490 | n/a | "sharingFlags", |
|---|
| 491 | n/a | "userPrivileges" |
|---|
| 492 | n/a | """ |
|---|
| 493 | n/a | |
|---|
| 494 | n/a | def __init__(self, name, prefix, itselftype): |
|---|
| 495 | n/a | ObjectDefinition.__init__(self, name, prefix, itselftype) |
|---|
| 496 | n/a | self.argref = "*" # Store FSSpecs, but pass them by address |
|---|
| 497 | n/a | |
|---|
| 498 | n/a | def outputCheckNewArg(self): |
|---|
| 499 | n/a | Output("if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }") |
|---|
| 500 | n/a | |
|---|
| 501 | n/a | def output_tp_newBody(self): |
|---|
| 502 | n/a | Output("PyObject *self;"); |
|---|
| 503 | n/a | Output() |
|---|
| 504 | n/a | Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;") |
|---|
| 505 | n/a | Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));", |
|---|
| 506 | n/a | self.objecttype, self.itselftype) |
|---|
| 507 | n/a | Output("return self;") |
|---|
| 508 | n/a | |
|---|
| 509 | n/a | def output_tp_initBody(self): |
|---|
| 510 | n/a | Output("static char *kw[] = {%s, 0};", self.INITNAMES) |
|---|
| 511 | n/a | Output() |
|---|
| 512 | n/a | Output("if (!PyArg_ParseTupleAndKeywords(_args, _kwds, \"|%s\", kw, %s))", |
|---|
| 513 | n/a | self.INITFORMAT, self.INITARGS) |
|---|
| 514 | n/a | OutLbrace() |
|---|
| 515 | n/a | Output("return -1;") |
|---|
| 516 | n/a | OutRbrace() |
|---|
| 517 | n/a | Output("return 0;") |
|---|
| 518 | n/a | |
|---|
| 519 | n/a | class FInfoDefinition(PEP253Mixin, ObjectDefinition): |
|---|
| 520 | n/a | getsetlist = [ |
|---|
| 521 | n/a | ("Type", |
|---|
| 522 | n/a | "return Py_BuildValue(\"O&\", PyMac_BuildOSType, self->ob_itself.fdType);", |
|---|
| 523 | n/a | "return PyArg_Parse(v, \"O&\", PyMac_GetOSType, &self->ob_itself.fdType)-1;", |
|---|
| 524 | n/a | "4-char file type" |
|---|
| 525 | n/a | ), |
|---|
| 526 | n/a | ("Creator", |
|---|
| 527 | n/a | "return Py_BuildValue(\"O&\", PyMac_BuildOSType, self->ob_itself.fdCreator);", |
|---|
| 528 | n/a | "return PyArg_Parse(v, \"O&\", PyMac_GetOSType, &self->ob_itself.fdCreator)-1;", |
|---|
| 529 | n/a | "4-char file creator" |
|---|
| 530 | n/a | ), |
|---|
| 531 | n/a | ("Flags", |
|---|
| 532 | n/a | "return Py_BuildValue(\"H\", self->ob_itself.fdFlags);", |
|---|
| 533 | n/a | "return PyArg_Parse(v, \"H\", &self->ob_itself.fdFlags)-1;", |
|---|
| 534 | n/a | "Finder flag bits" |
|---|
| 535 | n/a | ), |
|---|
| 536 | n/a | ("Location", |
|---|
| 537 | n/a | "return Py_BuildValue(\"O&\", PyMac_BuildPoint, self->ob_itself.fdLocation);", |
|---|
| 538 | n/a | "return PyArg_Parse(v, \"O&\", PyMac_GetPoint, &self->ob_itself.fdLocation)-1;", |
|---|
| 539 | n/a | "(x, y) location of the file's icon in its parent finder window" |
|---|
| 540 | n/a | ), |
|---|
| 541 | n/a | ("Fldr", |
|---|
| 542 | n/a | "return Py_BuildValue(\"h\", self->ob_itself.fdFldr);", |
|---|
| 543 | n/a | "return PyArg_Parse(v, \"h\", &self->ob_itself.fdFldr)-1;", |
|---|
| 544 | n/a | "Original folder, for 'put away'" |
|---|
| 545 | n/a | ), |
|---|
| 546 | n/a | |
|---|
| 547 | n/a | ] |
|---|
| 548 | n/a | |
|---|
| 549 | n/a | def __init__(self, name, prefix, itselftype): |
|---|
| 550 | n/a | ObjectDefinition.__init__(self, name, prefix, itselftype) |
|---|
| 551 | n/a | self.argref = "*" # Store FSSpecs, but pass them by address |
|---|
| 552 | n/a | |
|---|
| 553 | n/a | def outputCheckNewArg(self): |
|---|
| 554 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 555 | n/a | |
|---|
| 556 | n/a | def output_tp_newBody(self): |
|---|
| 557 | n/a | Output("PyObject *self;"); |
|---|
| 558 | n/a | Output() |
|---|
| 559 | n/a | Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;") |
|---|
| 560 | n/a | Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));", |
|---|
| 561 | n/a | self.objecttype, self.itselftype) |
|---|
| 562 | n/a | Output("return self;") |
|---|
| 563 | n/a | |
|---|
| 564 | n/a | def output_tp_initBody(self): |
|---|
| 565 | n/a | Output("%s *itself = NULL;", self.itselftype) |
|---|
| 566 | n/a | Output("static char *kw[] = {\"itself\", 0};") |
|---|
| 567 | n/a | Output() |
|---|
| 568 | n/a | Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"|O&\", kw, FInfo_Convert, &itself))") |
|---|
| 569 | n/a | OutLbrace() |
|---|
| 570 | n/a | Output("if (itself) memcpy(&((%s *)_self)->ob_itself, itself, sizeof(%s));", |
|---|
| 571 | n/a | self.objecttype, self.itselftype) |
|---|
| 572 | n/a | Output("return 0;") |
|---|
| 573 | n/a | OutRbrace() |
|---|
| 574 | n/a | Output("return -1;") |
|---|
| 575 | n/a | |
|---|
| 576 | n/a | class FSSpecDefinition(PEP253Mixin, ObjectDefinition): |
|---|
| 577 | n/a | getsetlist = [ |
|---|
| 578 | n/a | ("data", |
|---|
| 579 | n/a | "return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));", |
|---|
| 580 | n/a | None, |
|---|
| 581 | n/a | "Raw data of the FSSpec object" |
|---|
| 582 | n/a | ) |
|---|
| 583 | n/a | ] |
|---|
| 584 | n/a | |
|---|
| 585 | n/a | def __init__(self, name, prefix, itselftype): |
|---|
| 586 | n/a | ObjectDefinition.__init__(self, name, prefix, itselftype) |
|---|
| 587 | n/a | self.argref = "*" # Store FSSpecs, but pass them by address |
|---|
| 588 | n/a | |
|---|
| 589 | n/a | def outputCheckNewArg(self): |
|---|
| 590 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 591 | n/a | |
|---|
| 592 | n/a | # We do Convert ourselves (with PyMac_GetFSxxx) |
|---|
| 593 | n/a | def outputConvert(self): |
|---|
| 594 | n/a | pass |
|---|
| 595 | n/a | |
|---|
| 596 | n/a | def output_tp_newBody(self): |
|---|
| 597 | n/a | Output("PyObject *self;"); |
|---|
| 598 | n/a | Output() |
|---|
| 599 | n/a | Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;") |
|---|
| 600 | n/a | Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));", |
|---|
| 601 | n/a | self.objecttype, self.itselftype) |
|---|
| 602 | n/a | Output("return self;") |
|---|
| 603 | n/a | |
|---|
| 604 | n/a | def output_tp_initBody(self): |
|---|
| 605 | n/a | Output("PyObject *v = NULL;") |
|---|
| 606 | n/a | Output("char *rawdata = NULL;") |
|---|
| 607 | n/a | Output("int rawdatalen = 0;") |
|---|
| 608 | n/a | Output("static char *kw[] = {\"itself\", \"rawdata\", 0};") |
|---|
| 609 | n/a | Output() |
|---|
| 610 | n/a | Output("if (!PyArg_ParseTupleAndKeywords(_args, _kwds, \"|Os#\", kw, &v, &rawdata, &rawdatalen))") |
|---|
| 611 | n/a | Output("return -1;") |
|---|
| 612 | n/a | Output("if (v && rawdata)") |
|---|
| 613 | n/a | OutLbrace() |
|---|
| 614 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"Only one of itself or rawdata may be specified\");") |
|---|
| 615 | n/a | Output("return -1;") |
|---|
| 616 | n/a | OutRbrace() |
|---|
| 617 | n/a | Output("if (!v && !rawdata)") |
|---|
| 618 | n/a | OutLbrace() |
|---|
| 619 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"One of itself or rawdata must be specified\");") |
|---|
| 620 | n/a | Output("return -1;") |
|---|
| 621 | n/a | OutRbrace() |
|---|
| 622 | n/a | Output("if (rawdata)") |
|---|
| 623 | n/a | OutLbrace() |
|---|
| 624 | n/a | Output("if (rawdatalen != sizeof(%s))", self.itselftype) |
|---|
| 625 | n/a | OutLbrace() |
|---|
| 626 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"%s rawdata incorrect size\");", |
|---|
| 627 | n/a | self.itselftype) |
|---|
| 628 | n/a | Output("return -1;") |
|---|
| 629 | n/a | OutRbrace() |
|---|
| 630 | n/a | Output("memcpy(&((%s *)_self)->ob_itself, rawdata, rawdatalen);", self.objecttype) |
|---|
| 631 | n/a | Output("return 0;") |
|---|
| 632 | n/a | OutRbrace() |
|---|
| 633 | n/a | Output("if (PyMac_GetFSSpec(v, &((%s *)_self)->ob_itself)) return 0;", self.objecttype) |
|---|
| 634 | n/a | Output("return -1;") |
|---|
| 635 | n/a | |
|---|
| 636 | n/a | def outputRepr(self): |
|---|
| 637 | n/a | Output() |
|---|
| 638 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 639 | n/a | OutLbrace() |
|---|
| 640 | n/a | Output("char buf[512];") |
|---|
| 641 | n/a | Output("""PyOS_snprintf(buf, sizeof(buf), \"%%s((%%d, %%ld, '%%.*s'))\", |
|---|
| 642 | n/a | self->ob_type->tp_name, |
|---|
| 643 | n/a | self->ob_itself.vRefNum, |
|---|
| 644 | n/a | self->ob_itself.parID, |
|---|
| 645 | n/a | self->ob_itself.name[0], self->ob_itself.name+1);""") |
|---|
| 646 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 647 | n/a | OutRbrace() |
|---|
| 648 | n/a | |
|---|
| 649 | n/a | class FSRefDefinition(PEP253Mixin, ObjectDefinition): |
|---|
| 650 | n/a | getsetlist = [ |
|---|
| 651 | n/a | ("data", |
|---|
| 652 | n/a | "return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));", |
|---|
| 653 | n/a | None, |
|---|
| 654 | n/a | "Raw data of the FSRef object" |
|---|
| 655 | n/a | ) |
|---|
| 656 | n/a | ] |
|---|
| 657 | n/a | |
|---|
| 658 | n/a | def __init__(self, name, prefix, itselftype): |
|---|
| 659 | n/a | ObjectDefinition.__init__(self, name, prefix, itselftype) |
|---|
| 660 | n/a | self.argref = "*" # Store FSRefs, but pass them by address |
|---|
| 661 | n/a | |
|---|
| 662 | n/a | def outputCheckNewArg(self): |
|---|
| 663 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 664 | n/a | |
|---|
| 665 | n/a | # We do Convert ourselves (with PyMac_GetFSxxx) |
|---|
| 666 | n/a | def outputConvert(self): |
|---|
| 667 | n/a | pass |
|---|
| 668 | n/a | |
|---|
| 669 | n/a | def output_tp_newBody(self): |
|---|
| 670 | n/a | Output("PyObject *self;"); |
|---|
| 671 | n/a | Output() |
|---|
| 672 | n/a | Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;") |
|---|
| 673 | n/a | Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));", |
|---|
| 674 | n/a | self.objecttype, self.itselftype) |
|---|
| 675 | n/a | Output("return self;") |
|---|
| 676 | n/a | |
|---|
| 677 | n/a | def output_tp_initBody(self): |
|---|
| 678 | n/a | Output("PyObject *v = NULL;") |
|---|
| 679 | n/a | Output("char *rawdata = NULL;") |
|---|
| 680 | n/a | Output("int rawdatalen = 0;") |
|---|
| 681 | n/a | Output("static char *kw[] = {\"itself\", \"rawdata\", 0};") |
|---|
| 682 | n/a | Output() |
|---|
| 683 | n/a | Output("if (!PyArg_ParseTupleAndKeywords(_args, _kwds, \"|Os#\", kw, &v, &rawdata, &rawdatalen))") |
|---|
| 684 | n/a | Output("return -1;") |
|---|
| 685 | n/a | Output("if (v && rawdata)") |
|---|
| 686 | n/a | OutLbrace() |
|---|
| 687 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"Only one of itself or rawdata may be specified\");") |
|---|
| 688 | n/a | Output("return -1;") |
|---|
| 689 | n/a | OutRbrace() |
|---|
| 690 | n/a | Output("if (!v && !rawdata)") |
|---|
| 691 | n/a | OutLbrace() |
|---|
| 692 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"One of itself or rawdata must be specified\");") |
|---|
| 693 | n/a | Output("return -1;") |
|---|
| 694 | n/a | OutRbrace() |
|---|
| 695 | n/a | Output("if (rawdata)") |
|---|
| 696 | n/a | OutLbrace() |
|---|
| 697 | n/a | Output("if (rawdatalen != sizeof(%s))", self.itselftype) |
|---|
| 698 | n/a | OutLbrace() |
|---|
| 699 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"%s rawdata incorrect size\");", |
|---|
| 700 | n/a | self.itselftype) |
|---|
| 701 | n/a | Output("return -1;") |
|---|
| 702 | n/a | OutRbrace() |
|---|
| 703 | n/a | Output("memcpy(&((%s *)_self)->ob_itself, rawdata, rawdatalen);", self.objecttype) |
|---|
| 704 | n/a | Output("return 0;") |
|---|
| 705 | n/a | OutRbrace() |
|---|
| 706 | n/a | Output("if (PyMac_GetFSRef(v, &((%s *)_self)->ob_itself)) return 0;", self.objecttype) |
|---|
| 707 | n/a | Output("return -1;") |
|---|
| 708 | n/a | |
|---|
| 709 | n/a | class AliasDefinition(PEP253Mixin, ObjectDefinition): |
|---|
| 710 | n/a | # XXXX Should inherit from resource? |
|---|
| 711 | n/a | getsetlist = [ |
|---|
| 712 | n/a | ("data", |
|---|
| 713 | n/a | """int size; |
|---|
| 714 | n/a | PyObject *rv; |
|---|
| 715 | n/a | |
|---|
| 716 | n/a | size = GetHandleSize((Handle)self->ob_itself); |
|---|
| 717 | n/a | HLock((Handle)self->ob_itself); |
|---|
| 718 | n/a | rv = PyString_FromStringAndSize(*(Handle)self->ob_itself, size); |
|---|
| 719 | n/a | HUnlock((Handle)self->ob_itself); |
|---|
| 720 | n/a | return rv; |
|---|
| 721 | n/a | """, |
|---|
| 722 | n/a | None, |
|---|
| 723 | n/a | "Raw data of the alias object" |
|---|
| 724 | n/a | ) |
|---|
| 725 | n/a | ] |
|---|
| 726 | n/a | |
|---|
| 727 | n/a | def outputCheckNewArg(self): |
|---|
| 728 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 729 | n/a | |
|---|
| 730 | n/a | def outputStructMembers(self): |
|---|
| 731 | n/a | ObjectDefinition.outputStructMembers(self) |
|---|
| 732 | n/a | Output("void (*ob_freeit)(%s ptr);", self.itselftype) |
|---|
| 733 | n/a | |
|---|
| 734 | n/a | def outputInitStructMembers(self): |
|---|
| 735 | n/a | ObjectDefinition.outputInitStructMembers(self) |
|---|
| 736 | n/a | Output("it->ob_freeit = NULL;") |
|---|
| 737 | n/a | |
|---|
| 738 | n/a | def outputCleanupStructMembers(self): |
|---|
| 739 | n/a | Output("if (self->ob_freeit && self->ob_itself)") |
|---|
| 740 | n/a | OutLbrace() |
|---|
| 741 | n/a | Output("self->ob_freeit(self->ob_itself);") |
|---|
| 742 | n/a | OutRbrace() |
|---|
| 743 | n/a | Output("self->ob_itself = NULL;") |
|---|
| 744 | n/a | |
|---|
| 745 | n/a | def output_tp_newBody(self): |
|---|
| 746 | n/a | Output("PyObject *self;"); |
|---|
| 747 | n/a | Output() |
|---|
| 748 | n/a | Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;") |
|---|
| 749 | n/a | Output("((%s *)self)->ob_itself = NULL;", self.objecttype) |
|---|
| 750 | n/a | Output("return self;") |
|---|
| 751 | n/a | |
|---|
| 752 | n/a | def output_tp_initBody(self): |
|---|
| 753 | n/a | Output("%s itself = NULL;", self.itselftype) |
|---|
| 754 | n/a | Output("char *rawdata = NULL;") |
|---|
| 755 | n/a | Output("int rawdatalen = 0;") |
|---|
| 756 | n/a | Output("Handle h;") |
|---|
| 757 | n/a | Output("static char *kw[] = {\"itself\", \"rawdata\", 0};") |
|---|
| 758 | n/a | Output() |
|---|
| 759 | n/a | Output("if (!PyArg_ParseTupleAndKeywords(_args, _kwds, \"|O&s#\", kw, %s_Convert, &itself, &rawdata, &rawdatalen))", |
|---|
| 760 | n/a | self.prefix) |
|---|
| 761 | n/a | Output("return -1;") |
|---|
| 762 | n/a | Output("if (itself && rawdata)") |
|---|
| 763 | n/a | OutLbrace() |
|---|
| 764 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"Only one of itself or rawdata may be specified\");") |
|---|
| 765 | n/a | Output("return -1;") |
|---|
| 766 | n/a | OutRbrace() |
|---|
| 767 | n/a | Output("if (!itself && !rawdata)") |
|---|
| 768 | n/a | OutLbrace() |
|---|
| 769 | n/a | Output("PyErr_SetString(PyExc_TypeError, \"One of itself or rawdata must be specified\");") |
|---|
| 770 | n/a | Output("return -1;") |
|---|
| 771 | n/a | OutRbrace() |
|---|
| 772 | n/a | Output("if (rawdata)") |
|---|
| 773 | n/a | OutLbrace() |
|---|
| 774 | n/a | Output("if ((h = NewHandle(rawdatalen)) == NULL)") |
|---|
| 775 | n/a | OutLbrace() |
|---|
| 776 | n/a | Output("PyErr_NoMemory();") |
|---|
| 777 | n/a | Output("return -1;") |
|---|
| 778 | n/a | OutRbrace() |
|---|
| 779 | n/a | Output("HLock(h);") |
|---|
| 780 | n/a | Output("memcpy((char *)*h, rawdata, rawdatalen);") |
|---|
| 781 | n/a | Output("HUnlock(h);") |
|---|
| 782 | n/a | Output("((%s *)_self)->ob_itself = (%s)h;", self.objecttype, self.itselftype) |
|---|
| 783 | n/a | Output("return 0;") |
|---|
| 784 | n/a | OutRbrace() |
|---|
| 785 | n/a | Output("((%s *)_self)->ob_itself = itself;", self.objecttype) |
|---|
| 786 | n/a | Output("return 0;") |
|---|
| 787 | n/a | |
|---|
| 788 | n/a | # Alias methods come in two flavors: those with the alias as arg1 and |
|---|
| 789 | n/a | # those with the alias as arg 2. |
|---|
| 790 | n/a | class Arg2MethodGenerator(OSErrMethodGenerator): |
|---|
| 791 | n/a | """Similar to MethodGenerator, but has self as second argument""" |
|---|
| 792 | n/a | |
|---|
| 793 | n/a | def parseArgumentList(self, args): |
|---|
| 794 | n/a | args0, arg1, argsrest = args[:1], args[1], args[2:] |
|---|
| 795 | n/a | t0, n0, m0 = arg1 |
|---|
| 796 | n/a | args = args0 + argsrest |
|---|
| 797 | n/a | if m0 != InMode: |
|---|
| 798 | n/a | raise ValueError, "method's 'self' must be 'InMode'" |
|---|
| 799 | n/a | self.itself = Variable(t0, "_self->ob_itself", SelfMode) |
|---|
| 800 | n/a | FunctionGenerator.parseArgumentList(self, args) |
|---|
| 801 | n/a | self.argumentList.insert(2, self.itself) |
|---|
| 802 | n/a | |
|---|
| 803 | n/a | # From here on it's basically all boiler plate... |
|---|
| 804 | n/a | |
|---|
| 805 | n/a | # Create the generator groups and link them |
|---|
| 806 | n/a | module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, |
|---|
| 807 | n/a | longname=LONGMODNAME) |
|---|
| 808 | n/a | |
|---|
| 809 | n/a | fscataloginfoobject = FSCatalogInfoDefinition('FSCatalogInfo', 'FSCatalogInfo', 'FSCatalogInfo') |
|---|
| 810 | n/a | finfoobject = FInfoDefinition('FInfo', 'FInfo', 'FInfo') |
|---|
| 811 | n/a | aliasobject = AliasDefinition('Alias', 'Alias', 'AliasHandle') |
|---|
| 812 | n/a | fsspecobject = FSSpecDefinition('FSSpec', 'FSSpec', 'FSSpec') |
|---|
| 813 | n/a | fsrefobject = FSRefDefinition('FSRef', 'FSRef', 'FSRef') |
|---|
| 814 | n/a | |
|---|
| 815 | n/a | module.addobject(fscataloginfoobject) |
|---|
| 816 | n/a | module.addobject(finfoobject) |
|---|
| 817 | n/a | module.addobject(aliasobject) |
|---|
| 818 | n/a | module.addobject(fsspecobject) |
|---|
| 819 | n/a | module.addobject(fsrefobject) |
|---|
| 820 | n/a | |
|---|
| 821 | n/a | # Create the generator classes used to populate the lists |
|---|
| 822 | n/a | Function = OSErrFunctionGenerator |
|---|
| 823 | n/a | Method = OSErrMethodGenerator |
|---|
| 824 | n/a | |
|---|
| 825 | n/a | # Create and populate the lists |
|---|
| 826 | n/a | functions = [] |
|---|
| 827 | n/a | alias_methods = [] |
|---|
| 828 | n/a | fsref_methods = [] |
|---|
| 829 | n/a | fsspec_methods = [] |
|---|
| 830 | n/a | execfile(INPUTFILE) |
|---|
| 831 | n/a | |
|---|
| 832 | n/a | # Manual generators: |
|---|
| 833 | n/a | FSRefMakePath_body = """ |
|---|
| 834 | n/a | OSStatus _err; |
|---|
| 835 | n/a | #define MAXPATHNAME 1024 |
|---|
| 836 | n/a | UInt8 path[MAXPATHNAME]; |
|---|
| 837 | n/a | UInt32 maxPathSize = MAXPATHNAME; |
|---|
| 838 | n/a | |
|---|
| 839 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 840 | n/a | return NULL; |
|---|
| 841 | n/a | _err = FSRefMakePath(&_self->ob_itself, |
|---|
| 842 | n/a | path, |
|---|
| 843 | n/a | maxPathSize); |
|---|
| 844 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 845 | n/a | _res = Py_BuildValue("s", path); |
|---|
| 846 | n/a | return _res; |
|---|
| 847 | n/a | """ |
|---|
| 848 | n/a | f = ManualGenerator("FSRefMakePath", FSRefMakePath_body) |
|---|
| 849 | n/a | f.docstring = lambda: "() -> string" |
|---|
| 850 | n/a | fsref_methods.append(f) |
|---|
| 851 | n/a | |
|---|
| 852 | n/a | FSRef_as_pathname_body = """ |
|---|
| 853 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 854 | n/a | return NULL; |
|---|
| 855 | n/a | _res = FSRef_FSRefMakePath(_self, _args); |
|---|
| 856 | n/a | return _res; |
|---|
| 857 | n/a | """ |
|---|
| 858 | n/a | f = ManualGenerator("as_pathname", FSRef_as_pathname_body) |
|---|
| 859 | n/a | f.docstring = lambda: "() -> string" |
|---|
| 860 | n/a | fsref_methods.append(f) |
|---|
| 861 | n/a | |
|---|
| 862 | n/a | FSSpec_as_pathname_body = """ |
|---|
| 863 | n/a | char strbuf[1024]; |
|---|
| 864 | n/a | OSErr err; |
|---|
| 865 | n/a | |
|---|
| 866 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 867 | n/a | return NULL; |
|---|
| 868 | n/a | err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf)); |
|---|
| 869 | n/a | if ( err ) { |
|---|
| 870 | n/a | PyMac_Error(err); |
|---|
| 871 | n/a | return NULL; |
|---|
| 872 | n/a | } |
|---|
| 873 | n/a | _res = PyString_FromString(strbuf); |
|---|
| 874 | n/a | return _res; |
|---|
| 875 | n/a | """ |
|---|
| 876 | n/a | f = ManualGenerator("as_pathname", FSSpec_as_pathname_body) |
|---|
| 877 | n/a | f.docstring = lambda: "() -> string" |
|---|
| 878 | n/a | fsspec_methods.append(f) |
|---|
| 879 | n/a | |
|---|
| 880 | n/a | FSSpec_as_tuple_body = """ |
|---|
| 881 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 882 | n/a | return NULL; |
|---|
| 883 | n/a | _res = Py_BuildValue("(iis#)", _self->ob_itself.vRefNum, _self->ob_itself.parID, |
|---|
| 884 | n/a | &_self->ob_itself.name[1], _self->ob_itself.name[0]); |
|---|
| 885 | n/a | return _res; |
|---|
| 886 | n/a | """ |
|---|
| 887 | n/a | f = ManualGenerator("as_tuple", FSSpec_as_tuple_body) |
|---|
| 888 | n/a | f.docstring = lambda: "() -> (vRefNum, dirID, name)" |
|---|
| 889 | n/a | fsspec_methods.append(f) |
|---|
| 890 | n/a | |
|---|
| 891 | n/a | pathname_body = """ |
|---|
| 892 | n/a | PyObject *obj; |
|---|
| 893 | n/a | |
|---|
| 894 | n/a | if (!PyArg_ParseTuple(_args, "O", &obj)) |
|---|
| 895 | n/a | return NULL; |
|---|
| 896 | n/a | if (PyString_Check(obj)) { |
|---|
| 897 | n/a | Py_INCREF(obj); |
|---|
| 898 | n/a | return obj; |
|---|
| 899 | n/a | } |
|---|
| 900 | n/a | if (PyUnicode_Check(obj)) |
|---|
| 901 | n/a | return PyUnicode_AsEncodedString(obj, "utf8", "strict"); |
|---|
| 902 | n/a | _res = PyObject_CallMethod(obj, "as_pathname", NULL); |
|---|
| 903 | n/a | return _res; |
|---|
| 904 | n/a | """ |
|---|
| 905 | n/a | f = ManualGenerator("pathname", pathname_body) |
|---|
| 906 | n/a | f.docstring = lambda: "(str|unicode|FSSpec|FSref) -> pathname" |
|---|
| 907 | n/a | functions.append(f) |
|---|
| 908 | n/a | |
|---|
| 909 | n/a | # add the populated lists to the generator groups |
|---|
| 910 | n/a | # (in a different wordl the scan program would generate this) |
|---|
| 911 | n/a | for f in functions: module.add(f) |
|---|
| 912 | n/a | for f in alias_methods: aliasobject.add(f) |
|---|
| 913 | n/a | for f in fsspec_methods: fsspecobject.add(f) |
|---|
| 914 | n/a | for f in fsref_methods: fsrefobject.add(f) |
|---|
| 915 | n/a | |
|---|
| 916 | n/a | # generate output (open the output file as late as possible) |
|---|
| 917 | n/a | SetOutputFileName(OUTPUTFILE) |
|---|
| 918 | n/a | module.generate() |
|---|