Issue #7632: Fix a serious wrong output bug for string -> float conversion.
[python.git] / Mac / Modules / help / helpsupport.py
blob77f5c2ecc907a50adf727944be6590e034d090d8
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 MODNAME = '_Help' # The name of the module
10 OBJECTNAME = 'UNUSED' # The basic name of the objects used here
11 KIND = 'Record' # Usually 'Ptr' or 'Handle'
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX = 'Help' # The prefix for module-wide routines
15 OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
16 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
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
23 MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
24 MenuItemIndex = Type("MenuItemIndex", "H")
26 #WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
28 #RgnHandle = FakeType("(RgnHandle)0")
29 # XXXX Should be next, but this will break a lot of code...
30 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
32 #KeyMap = ArrayOutputBufferType("KeyMap")
33 ##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
34 ##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
35 #EventMask = Type("EventMask", "H")
36 #EventKind = Type("EventKind", "H")
38 includestuff = includestuff + """
39 #include <Carbon/Carbon.h>
40 """
42 class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
43 def outputCheckNewArg(self):
44 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
45 def outputCheckConvertArg(self):
46 OutLbrace("if (DlgObj_Check(v))")
47 Output("*p_itself = ((WindowObject *)v)->ob_itself;")
48 Output("return 1;")
49 OutRbrace()
50 Out("""
51 if (v == Py_None) { *p_itself = NULL; return 1; }
52 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
53 """)
55 # From here on it's basically all boiler plate...
57 # Create the generator groups and link them
58 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
59 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
60 ##module.addobject(object)
62 # Create the generator classes used to populate the lists
63 Function = OSErrFunctionGenerator
64 ##Method = OSErrMethodGenerator
66 # Create and populate the lists
67 functions = []
68 ##methods = []
69 execfile(INPUTFILE)
71 # add the populated lists to the generator groups
72 # (in a different wordl the scan program would generate this)
73 for f in functions: module.add(f)
74 ##for f in methods: object.add(f)
76 # generate output (open the output file as late as possible)
77 SetOutputFileName(OUTPUTFILE)
78 module.generate()