| 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 | import string |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | # Declarations that change for each manager |
|---|
| 9 | n/a | MACHEADERFILE = 'OSA.h' # The Apple header file |
|---|
| 10 | n/a | MODNAME = '_OSA' # The name of the module |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | # The following is *usually* unchanged but may still require tuning |
|---|
| 13 | n/a | MODPREFIX = 'OSA' # The prefix for module-wide routines |
|---|
| 14 | n/a | OBJECTPREFIX = 'OSAObj' # The prefix for object methods |
|---|
| 15 | n/a | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|---|
| 16 | n/a | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | from macsupport import * |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | # Create the type objects |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | includestuff = includestuff + """ |
|---|
| 23 | n/a | #if PY_VERSION_HEX < 0x02040000 |
|---|
| 24 | n/a | PyObject *PyMac_GetOSErrException(void); |
|---|
| 25 | n/a | #endif |
|---|
| 26 | n/a | #include <Carbon/Carbon.h> |
|---|
| 27 | n/a | |
|---|
| 28 | n/a | #ifdef USE_TOOLBOX_OBJECT_GLUE |
|---|
| 29 | n/a | extern PyObject *_OSAObj_New(ComponentInstance); |
|---|
| 30 | n/a | extern int _OSAObj_Convert(PyObject *, ComponentInstance *); |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | #define OSAObj_New _OSAObj_New |
|---|
| 33 | n/a | #define OSAObj_Convert _OSAObj_Convert |
|---|
| 34 | n/a | #endif |
|---|
| 35 | n/a | """ |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | initstuff = initstuff + """ |
|---|
| 38 | n/a | /* |
|---|
| 39 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, OSAObj_New); |
|---|
| 40 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, OSAObj_Convert); |
|---|
| 41 | n/a | */ |
|---|
| 42 | n/a | """ |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | ComponentInstance = OpaqueByValueType('ComponentInstance', OBJECTPREFIX) |
|---|
| 45 | n/a | OSAError = OSErrType("OSAError", "l") |
|---|
| 46 | n/a | # OSALocalOrGlobal = Type("OSALocalOrGlobal", "l") |
|---|
| 47 | n/a | OSAID = Type("OSAID", "l") |
|---|
| 48 | n/a | OSADebugCallFrameRef = Type("OSADebugCallFrameRef", "l") |
|---|
| 49 | n/a | OSADebugSessionRef = Type("OSADebugSessionRef", "l") |
|---|
| 50 | n/a | OSADebugStepKind = Type("OSADebugStepKind", "l") |
|---|
| 51 | n/a | DescType = OSTypeType("DescType") |
|---|
| 52 | n/a | AEDesc = OpaqueType('AEDesc') |
|---|
| 53 | n/a | AEDesc_ptr = OpaqueType('AEDesc') |
|---|
| 54 | n/a | AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc') |
|---|
| 55 | n/a | AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc') |
|---|
| 56 | n/a | AEDescList = OpaqueType('AEDescList', 'AEDesc') |
|---|
| 57 | n/a | AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc') |
|---|
| 58 | n/a | AERecord = OpaqueType('AERecord', 'AEDesc') |
|---|
| 59 | n/a | AERecord_ptr = OpaqueType('AERecord', 'AEDesc') |
|---|
| 60 | n/a | AppleEvent = OpaqueType('AppleEvent', 'AEDesc') |
|---|
| 61 | n/a | AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc') |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | # NOTE: at the moment OSA.ComponentInstance is not a subclass |
|---|
| 64 | n/a | # of Cm.ComponentInstance. If this is a problem it can be fixed. |
|---|
| 65 | n/a | class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|---|
| 66 | n/a | def outputCheckNewArg(self): |
|---|
| 67 | n/a | Output("""if (itself == NULL) { |
|---|
| 68 | n/a | PyErr_SetString(OSA_Error,"NULL ComponentInstance"); |
|---|
| 69 | n/a | return NULL; |
|---|
| 70 | n/a | }""") |
|---|
| 71 | n/a | |
|---|
| 72 | n/a | def outputCheckConvertArg(self): |
|---|
| 73 | n/a | Output(""" |
|---|
| 74 | n/a | if (CmpInstObj_Convert(v, p_itself)) |
|---|
| 75 | n/a | return 1; |
|---|
| 76 | n/a | PyErr_Clear(); |
|---|
| 77 | n/a | """) |
|---|
| 78 | n/a | |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | # Create the generator groups and link them |
|---|
| 81 | n/a | module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
|---|
| 82 | n/a | object = MyObjectDefinition('OSAComponentInstance', OBJECTPREFIX, |
|---|
| 83 | n/a | 'ComponentInstance') |
|---|
| 84 | n/a | module.addobject(object) |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | # Create the generator classes used to populate the lists |
|---|
| 87 | n/a | Function = OSErrWeakLinkFunctionGenerator |
|---|
| 88 | n/a | Method = OSErrWeakLinkMethodGenerator |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | # Test which types we are still missing. |
|---|
| 91 | n/a | execfile(string.lower(MODPREFIX) + 'typetest.py') |
|---|
| 92 | n/a | |
|---|
| 93 | n/a | # Create and populate the lists |
|---|
| 94 | n/a | functions = [] |
|---|
| 95 | n/a | methods = [] |
|---|
| 96 | n/a | execfile(INPUTFILE) |
|---|
| 97 | n/a | |
|---|
| 98 | n/a | # add the populated lists to the generator groups |
|---|
| 99 | n/a | # (in a different wordl the scan program would generate this) |
|---|
| 100 | n/a | for f in functions: module.add(f) |
|---|
| 101 | n/a | for f in methods: object.add(f) |
|---|
| 102 | n/a | |
|---|
| 103 | n/a | # generate output (open the output file as late as possible) |
|---|
| 104 | n/a | SetOutputFileName(OUTPUTFILE) |
|---|
| 105 | n/a | module.generate() |
|---|