Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Mac / Modules / fm / fmsupport.py
blobf0b1e292626df42e319bc12434180521fe31a257
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 = MODNAME # 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 includestuff = includestuff + """
22 #include <%s>""" % MACHEADERFILE + """
25 ** Parse/generate ComponentDescriptor records
27 PyObject *FMRec_New(itself)
28 FMetricRec *itself;
31 return Py_BuildValue("O&O&O&O&O&",
32 PyMac_BuildFixed, itself->ascent,
33 PyMac_BuildFixed, itself->descent,
34 PyMac_BuildFixed, itself->leading,
35 PyMac_BuildFixed, itself->widMax,
36 ResObj_New, itself->wTabHandle);
39 #if 0
40 /* Not needed... */
41 FMRec_Convert(v, p_itself)
42 PyObject *v;
43 FMetricRec *p_itself;
45 return PyArg_ParseTuple(v, "O&O&O&O&O&",
46 PyMac_GetFixed, &itself->ascent,
47 PyMac_GetFixed, &itself->descent,
48 PyMac_GetFixed, &itself->leading,
49 PyMac_GetFixed, &itself->widMax,
50 ResObj_Convert, &itself->wTabHandle);
52 #endif
54 """
56 FMetricRecPtr = OpaqueType('FMetricRec', 'FMRec')
58 # Create the generator groups and link them
59 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
61 # Create the generator classes used to populate the lists
62 Function = OSErrFunctionGenerator
64 # Create and populate the lists
65 functions = []
66 execfile(INPUTFILE)
68 # add the populated lists to the generator groups
69 # (in a different wordl the scan program would generate this)
70 for f in functions: module.add(f)
72 # generate output (open the output file as late as possible)
73 SetOutputFileName(OUTPUTFILE)
74 module.generate()