This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Mac / Modules / fm / fmsupport.py
blob20ae292354574d74f0b6cdc757282cf6482856e7
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).
6 import string
8 # Declarations that change for each manager
9 MACHEADERFILE = 'Fonts.h' # The Apple header file
10 MODNAME = '_Fm' # The name of the module
12 # The following is *usually* unchanged but may still require tuning
13 MODPREFIX = 'Fm' # The prefix for module-wide routines
14 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
15 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
17 from macsupport import *
19 # Create the type objects
21 class RevVarInputBufferType(VarInputBufferType):
22 def passInput(self, name):
23 return "%s__len__, %s__in__" % (name, name)
25 TextBuffer = RevVarInputBufferType()
28 includestuff = includestuff + """
29 #ifdef WITHOUT_FRAMEWORKS
30 #include <Fonts.h>
31 #else
32 #include <Carbon/Carbon.h>
33 #endif
37 ** Parse/generate ComponentDescriptor records
39 static PyObject *
40 FMRec_New(FMetricRec *itself)
43 return Py_BuildValue("O&O&O&O&O&",
44 PyMac_BuildFixed, itself->ascent,
45 PyMac_BuildFixed, itself->descent,
46 PyMac_BuildFixed, itself->leading,
47 PyMac_BuildFixed, itself->widMax,
48 ResObj_New, itself->wTabHandle);
51 #if 0
52 /* Not needed... */
53 static int
54 FMRec_Convert(PyObject *v, FMetricRec *p_itself)
56 return PyArg_ParseTuple(v, "O&O&O&O&O&",
57 PyMac_GetFixed, &itself->ascent,
58 PyMac_GetFixed, &itself->descent,
59 PyMac_GetFixed, &itself->leading,
60 PyMac_GetFixed, &itself->widMax,
61 ResObj_Convert, &itself->wTabHandle);
63 #endif
65 """
67 FMetricRecPtr = OpaqueType('FMetricRec', 'FMRec')
69 # Create the generator groups and link them
70 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
72 # Create the generator classes used to populate the lists
73 Function = OSErrWeakLinkFunctionGenerator
75 # Create and populate the lists
76 functions = []
77 execfile(INPUTFILE)
79 # add the populated lists to the generator groups
80 # (in a different wordl the scan program would generate this)
81 for f in functions: module.add(f)
83 # generate output (open the output file as late as possible)
84 SetOutputFileName(OUTPUTFILE)
85 module.generate()