|
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 |
|
6 import string |
|
7 |
|
8 # Declarations that change for each manager |
|
9 MACHEADERFILE = 'Fonts.h' # The Apple header file |
|
10 MODNAME = '_Fm' # The name of the module |
|
11 |
|
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 |
|
16 |
|
17 from macsupport import * |
|
18 |
|
19 # Create the type objects |
|
20 |
|
21 class RevVarInputBufferType(VarInputBufferType): |
|
22 def passInput(self, name): |
|
23 return "%s__len__, %s__in__" % (name, name) |
|
24 |
|
25 TextBuffer = RevVarInputBufferType() |
|
26 |
|
27 |
|
28 includestuff = includestuff + """ |
|
29 #include <Carbon/Carbon.h> |
|
30 |
|
31 |
|
32 /* |
|
33 ** Parse/generate ComponentDescriptor records |
|
34 */ |
|
35 static PyObject * |
|
36 FMRec_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... */ |
|
49 static int |
|
50 FMRec_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 |
|
63 FMetricRecPtr = OpaqueType('FMetricRec', 'FMRec') |
|
64 |
|
65 # Create the generator groups and link them |
|
66 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
|
67 |
|
68 # Create the generator classes used to populate the lists |
|
69 Function = OSErrWeakLinkFunctionGenerator |
|
70 |
|
71 # Create and populate the lists |
|
72 functions = [] |
|
73 execfile(INPUTFILE) |
|
74 |
|
75 # add the populated lists to the generator groups |
|
76 # (in a different wordl the scan program would generate this) |
|
77 for f in functions: module.add(f) |
|
78 |
|
79 # generate output (open the output file as late as possible) |
|
80 SetOutputFileName(OUTPUTFILE) |
|
81 module.generate() |