ยปCore Development>Code coverage>Mac/Modules/scrap/scrapsupport.py

Python code coverage for Mac/Modules/scrap/scrapsupport.py

#countcontent
1n/a# This script generates a Python interface for an Apple Macintosh Manager.
2n/a# It uses the "bgen" package to generate C code.
3n/a# The function specifications are generated by scanning the mamager's header file,
4n/a# using the "scantools" package (customized for this particular manager).
5n/a
6n/a# NOTE: the scrap include file is so bad that the bgen output has to be
7n/a# massaged by hand.
8n/a
9n/aimport string
10n/a
11n/a# Declarations that change for each manager
12n/aMACHEADERFILE = 'Scrap.h' # The Apple header file
13n/aMODNAME = '_Scrap' # The name of the module
14n/aOBJECTNAME = 'Scrap' # The basic name of the objects used here
15n/a
16n/a# The following is *usually* unchanged but may still require tuning
17n/aMODPREFIX = 'Scrap' # The prefix for module-wide routines
18n/aOBJECTTYPE = OBJECTNAME + 'Ref' # The C type used to represent them
19n/aOBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
20n/aINPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
21n/aOUTPUTFILE = '@' + MODNAME + "module.c" # The file generated by this program
22n/a
23n/afrom macsupport import *
24n/a
25n/a# Create the type objects
26n/aScrapRef = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
27n/a
28n/aincludestuff = includestuff + """
29n/a#include <Carbon/Carbon.h>
30n/a
31n/a/*
32n/a** Generate ScrapInfo records
33n/a*/
34n/astatic PyObject *
35n/aSCRRec_New(itself)
36n/a ScrapStuff *itself;
37n/a{
38n/a
39n/a return Py_BuildValue("lO&hhO&", itself->scrapSize,
40n/a ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
41n/a PyMac_BuildStr255, itself->scrapName);
42n/a}
43n/a"""
44n/a
45n/aScrapStuffPtr = OpaqueByValueType('ScrapStuffPtr', 'SCRRec')
46n/aScrapFlavorType = OSTypeType('ScrapFlavorType')
47n/aScrapFlavorFlags = Type('ScrapFlavorFlags', 'l')
48n/a#ScrapFlavorInfo = OpaqueType('ScrapFlavorInfo', 'ScrapFlavorInfo')
49n/aputscrapbuffer = FixedInputBufferType('void *')
50n/a
51n/aclass MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
52n/a pass
53n/a
54n/a# Create the generator groups and link them
55n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
56n/aobject = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
57n/amodule.addobject(object)
58n/a
59n/a# Create the generator classes used to populate the lists
60n/aFunction = OSErrFunctionGenerator
61n/aMethod = OSErrMethodGenerator
62n/a
63n/a# Create and populate the lists
64n/afunctions = []
65n/amethods = []
66n/aexecfile(INPUTFILE)
67n/a
68n/a# add the populated lists to the generator groups
69n/a# (in a different wordl the scan program would generate this)
70n/afor f in functions: module.add(f)
71n/afor f in methods: object.add(f)
72n/a
73n/a# generate output (open the output file as late as possible)
74n/aSetOutputFileName(OUTPUTFILE)
75n/amodule.generate()