This commit was manufactured by cvs2svn to create tag 'r212c1'.
[python/dscho.git] / Mac / Modules / scrap / scrapsupport.py
blob44dee333abf4d89868122ff869f82a7ab8cc0143
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 # NOTE: the scrap include file is so bad that the bgen output has to be
7 # massaged by hand.
9 import string
11 # Declarations that change for each manager
12 MACHEADERFILE = 'Scrap.h' # The Apple header file
13 MODNAME = 'Scrap' # The name of the module
15 # The following is *usually* unchanged but may still require tuning
16 MODPREFIX = MODNAME # The prefix for module-wide routines
17 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18 OUTPUTFILE = '@' + MODNAME + "module.c" # The file generated by this program
20 from macsupport import *
22 # Create the type objects
24 includestuff = includestuff + """
25 #ifdef WITHOUT_FRAMEWORKS
26 #include <Scrap.h>
27 #else
28 #include <Carbon/Carbon.h>
29 #endif
32 ** Generate ScrapInfo records
34 static PyObject *
35 SCRRec_New(itself)
36 ScrapStuff *itself;
39 return Py_BuildValue("lO&hhO&", itself->scrapSize,
40 ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
41 PyMac_BuildStr255, itself->scrapName);
43 """
45 ScrapStuffPtr = OpaqueByValueType('ScrapStuffPtr', 'SCRRec')
46 ScrapFlavorType = OSTypeType('ScrapFlavorType')
47 putscrapbuffer = FixedInputBufferType('void *')
49 # Create the generator groups and link them
50 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
52 # Create the generator classes used to populate the lists
53 Function = OSErrFunctionGenerator
55 # Create and populate the lists
56 functions = []
57 execfile(INPUTFILE)
59 # add the populated lists to the generator groups
60 # (in a different wordl the scan program would generate this)
61 for f in functions: module.add(f)
63 # generate output (open the output file as late as possible)
64 SetOutputFileName(OUTPUTFILE)
65 module.generate()