Debian Codegraph @

cpython27/Mac/Modules/scrap/scrapsupport.py

raw symbols SCIP
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 # NOTE: the scrap include file is so bad that the bgen output has to be
7 # massaged by hand.
8
9 import string
10
11 # Declarations that change for each manager
12 MACHEADERFILE = 'Scrap.h' # The Apple header file
13 MODNAME = '_Scrap' # The name of the module
14 OBJECTNAME = 'Scrap' # The basic name of the objects used here
15
16 # The following is *usually* unchanged but may still require tuning
17 MODPREFIX = 'Scrap' # The prefix for module-wide routines
18 OBJECTTYPE = OBJECTNAME + 'Ref' # The C type used to represent them
19 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
20 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
21 OUTPUTFILE = '@' + MODNAME + "module.c" # The file generated by this program
22
23 from macsupport import *
24
25 # Create the type objects
26 ScrapRef = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
27
28 includestuff = includestuff + """
29 #include <Carbon/Carbon.h>
30
31 /*
32 ** Generate ScrapInfo records
33 */
34 static PyObject *
35 SCRRec_New(itself)
36 ScrapStuff *itself;
37 {
38
39 return Py_BuildValue("lO&hhO&", itself->scrapSize,
40 ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
41 PyMac_BuildStr255, itself->scrapName);
42 }
43 """
44
45 ScrapStuffPtr = OpaqueByValueType('ScrapStuffPtr', 'SCRRec')
46 ScrapFlavorType = OSTypeType('ScrapFlavorType')
47 ScrapFlavorFlags = Type('ScrapFlavorFlags', 'l')
48 #ScrapFlavorInfo = OpaqueType('ScrapFlavorInfo', 'ScrapFlavorInfo')
49 putscrapbuffer = FixedInputBufferType('void *')
50
51 class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
52 pass
53
54 # Create the generator groups and link them
55 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
56 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
57 module.addobject(object)
58
59 # Create the generator classes used to populate the lists
60 Function = OSErrFunctionGenerator
61 Method = OSErrMethodGenerator
62
63 # Create and populate the lists
64 functions = []
65 methods = []
66 execfile(INPUTFILE)
67
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)
71 for f in methods: object.add(f)
72
73 # generate output (open the output file as late as possible)
74 SetOutputFileName(OUTPUTFILE)
75 module.generate()