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 9MACHEADERFILE = 'Fonts.h' # The Apple header file 10MODNAME = '_Fm' # The name of the module 11 12# The following is *usually* unchanged but may still require tuning 13MODPREFIX = 'Fm' # The prefix for module-wide routines 14INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner 15OUTPUTFILE = MODNAME + "module.c" # The file generated by this program 16 17from macsupport import * 18 19# Create the type objects 20 21class RevVarInputBufferType(VarInputBufferType): 22 def passInput(self, name): 23 return "%s__len__, %s__in__" % (name, name) 24 25TextBuffer = RevVarInputBufferType() 26 27 28includestuff = includestuff + """ 29#include <Carbon/Carbon.h> 30 31 32/* 33** Parse/generate ComponentDescriptor records 34*/ 35static PyObject * 36FMRec_New(FMetricRec *itself) 37{ 38 39 return Py_BuildValue("O&O&O&O&O&", 40 PyMac_BuildFixed, itself->ascent, 41 PyMac_BuildFixed, itself->descent, 42 PyMac_BuildFixed, itself->leading, 43 PyMac_BuildFixed, itself->widMax, 44 ResObj_New, itself->wTabHandle); 45} 46 47#if 0 48/* Not needed... */ 49static int 50FMRec_Convert(PyObject *v, FMetricRec *p_itself) 51{ 52 return PyArg_ParseTuple(v, "O&O&O&O&O&", 53 PyMac_GetFixed, &itself->ascent, 54 PyMac_GetFixed, &itself->descent, 55 PyMac_GetFixed, &itself->leading, 56 PyMac_GetFixed, &itself->widMax, 57 ResObj_Convert, &itself->wTabHandle); 58} 59#endif 60 61""" 62 63FMetricRecPtr = OpaqueType('FMetricRec', 'FMRec') 64 65# Create the generator groups and link them 66module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) 67 68# Create the generator classes used to populate the lists 69Function = OSErrWeakLinkFunctionGenerator 70 71# Create and populate the lists 72functions = [] 73execfile(INPUTFILE) 74 75# add the populated lists to the generator groups 76# (in a different wordl the scan program would generate this) 77for f in functions: module.add(f) 78 79# generate output (open the output file as late as possible) 80SetOutputFileName(OUTPUTFILE) 81module.generate() 82