append(): Fixing the test for convertability after consultation with
[python/dscho.git] / Mac / Modules / scrap / scrapsupport.py
blob65525be22904f18d53528a7a6625836c89c65e94
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
14 OBJECTNAME = 'Scrap' # The basic name of the objects used here
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
23 from macsupport import *
25 # Create the type objects
26 ScrapRef = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
28 includestuff = includestuff + """
29 #ifdef WITHOUT_FRAMEWORKS
30 #include <Scrap.h>
31 #else
32 #include <Carbon/Carbon.h>
33 #endif
36 ** Generate ScrapInfo records
38 static PyObject *
39 SCRRec_New(itself)
40 ScrapStuff *itself;
43 return Py_BuildValue("lO&hhO&", itself->scrapSize,
44 ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
45 PyMac_BuildStr255, itself->scrapName);
47 """
49 ScrapStuffPtr = OpaqueByValueType('ScrapStuffPtr', 'SCRRec')
50 ScrapFlavorType = OSTypeType('ScrapFlavorType')
51 ScrapFlavorFlags = Type('ScrapFlavorFlags', 'l')
52 #ScrapFlavorInfo = OpaqueType('ScrapFlavorInfo', 'ScrapFlavorInfo')
53 putscrapbuffer = FixedInputBufferType('void *')
55 class MyObjectDefinition(GlobalObjectDefinition):
56 pass
58 # Create the generator groups and link them
59 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
60 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
61 module.addobject(object)
63 # Create the generator classes used to populate the lists
64 Function = OSErrFunctionGenerator
65 Method = OSErrMethodGenerator
67 # Create and populate the lists
68 functions = []
69 methods = []
70 execfile(INPUTFILE)
72 # add the populated lists to the generator groups
73 # (in a different wordl the scan program would generate this)
74 for f in functions: module.add(f)
75 for f in methods: object.add(f)
77 # generate output (open the output file as late as possible)
78 SetOutputFileName(OUTPUTFILE)
79 module.generate()