| 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 | MODNAME = '_Launch' # The name of the module |
|---|
| 10 | n/a | OBJECTNAME = 'UNUSED' # The basic name of the objects used here |
|---|
| 11 | n/a | KIND = 'Record' # Usually 'Ptr' or 'Handle' |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | # The following is *usually* unchanged but may still require tuning |
|---|
| 14 | n/a | MODPREFIX = 'Launch' # The prefix for module-wide routines |
|---|
| 15 | n/a | OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them |
|---|
| 16 | n/a | OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods |
|---|
| 17 | n/a | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|---|
| 18 | n/a | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | from macsupport import * |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | # Create the type objects |
|---|
| 23 | n/a | LSAcceptanceFlags = Type("LSAcceptanceFlags", "l") |
|---|
| 24 | n/a | LSInitializeFlags = Type("LSInitializeFlags", "l") |
|---|
| 25 | n/a | LSRequestedInfo = Type("LSRequestedInfo", "l") |
|---|
| 26 | n/a | LSRolesMask = Type("LSRolesMask", "l") |
|---|
| 27 | n/a | UniCharCount = Type("UniCharCount", "l") |
|---|
| 28 | n/a | OptCFStringRef = OpaqueByValueType("CFStringRef", "OptCFStringRefObj") |
|---|
| 29 | n/a | LSItemInfoRecord = OpaqueType("LSItemInfoRecord", "LSItemInfoRecord") |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | includestuff = includestuff + """ |
|---|
| 32 | n/a | #if PY_VERSION_HEX < 0x02040000 |
|---|
| 33 | n/a | PyObject *PyMac_GetOSErrException(void); |
|---|
| 34 | n/a | #endif |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | #include <ApplicationServices/ApplicationServices.h> |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | /* |
|---|
| 39 | n/a | ** Optional CFStringRef. None will pass NULL |
|---|
| 40 | n/a | */ |
|---|
| 41 | n/a | static int |
|---|
| 42 | n/a | OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec) |
|---|
| 43 | n/a | { |
|---|
| 44 | n/a | if (v == Py_None) { |
|---|
| 45 | n/a | *spec = NULL; |
|---|
| 46 | n/a | return 1; |
|---|
| 47 | n/a | } |
|---|
| 48 | n/a | return CFStringRefObj_Convert(v, spec); |
|---|
| 49 | n/a | } |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | PyObject * |
|---|
| 52 | n/a | OptCFStringRefObj_New(CFStringRef it) |
|---|
| 53 | n/a | { |
|---|
| 54 | n/a | if (it == NULL) { |
|---|
| 55 | n/a | Py_INCREF(Py_None); |
|---|
| 56 | n/a | return Py_None; |
|---|
| 57 | n/a | } |
|---|
| 58 | n/a | return CFStringRefObj_New(it); |
|---|
| 59 | n/a | } |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | /* |
|---|
| 62 | n/a | ** Convert LSItemInfoRecord to Python. |
|---|
| 63 | n/a | */ |
|---|
| 64 | n/a | PyObject * |
|---|
| 65 | n/a | LSItemInfoRecord_New(LSItemInfoRecord *it) |
|---|
| 66 | n/a | { |
|---|
| 67 | n/a | return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}", |
|---|
| 68 | n/a | "flags", it->flags, |
|---|
| 69 | n/a | "filetype", PyMac_BuildOSType, it->filetype, |
|---|
| 70 | n/a | "creator", PyMac_BuildOSType, it->creator, |
|---|
| 71 | n/a | "extension", OptCFStringRefObj_New, it->extension, |
|---|
| 72 | n/a | "iconFileName", OptCFStringRefObj_New, it->iconFileName, |
|---|
| 73 | n/a | "kindID", it->kindID); |
|---|
| 74 | n/a | } |
|---|
| 75 | n/a | """ |
|---|
| 76 | n/a | |
|---|
| 77 | n/a | # From here on it's basically all boiler plate... |
|---|
| 78 | n/a | execfile(string.lower(MODPREFIX) + 'typetest.py') |
|---|
| 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(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) |
|---|
| 83 | n/a | ##module.addobject(object) |
|---|
| 84 | n/a | |
|---|
| 85 | n/a | # Create the generator classes used to populate the lists |
|---|
| 86 | n/a | Function = OSErrFunctionGenerator |
|---|
| 87 | n/a | ##Method = OSErrMethodGenerator |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | # Create and populate the lists |
|---|
| 90 | n/a | functions = [] |
|---|
| 91 | n/a | ##methods = [] |
|---|
| 92 | n/a | execfile(INPUTFILE) |
|---|
| 93 | n/a | |
|---|
| 94 | n/a | # add the populated lists to the generator groups |
|---|
| 95 | n/a | # (in a different wordl the scan program would generate this) |
|---|
| 96 | n/a | for f in functions: module.add(f) |
|---|
| 97 | n/a | ##for f in methods: object.add(f) |
|---|
| 98 | n/a | |
|---|
| 99 | n/a | # generate output (open the output file as late as possible) |
|---|
| 100 | n/a | SetOutputFileName(OUTPUTFILE) |
|---|
| 101 | n/a | module.generate() |
|---|