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