Issue #7632: Fix a serious wrong output bug for string -> float conversion.
[python.git] / Mac / Modules / qd / qdscan.py
blob24fbb74f88b5d5f6c3b21e014db308cdf2f9bf4f
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 from bgenlocations import TOOLBOXDIR, BGENDIR
5 sys.path.append(BGENDIR)
7 from scantools import Scanner
9 def main():
10 input = "QuickDraw.h"
11 output = "qdgen.py"
12 defsoutput = TOOLBOXDIR + "QuickDraw.py"
13 scanner = MyScanner(input, output, defsoutput)
14 scanner.scan()
15 scanner.close()
17 # Grmpf. Universal Headers have Text-stuff in a different include file...
18 input = "QuickDrawText.h"
19 output = "@qdgentext.py"
20 defsoutput = "@QuickDrawText.py"
21 have_extra = 0
22 try:
23 scanner = MyScanner(input, output, defsoutput)
24 scanner.scan()
25 scanner.close()
26 have_extra = 1
27 except IOError:
28 pass
29 if have_extra:
30 print "=== Copying QuickDrawText stuff into main files... ==="
31 ifp = open("@qdgentext.py")
32 ofp = open("qdgen.py", "a")
33 ofp.write(ifp.read())
34 ifp.close()
35 ofp.close()
36 ifp = open("@QuickDrawText.py")
37 ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
38 ofp.write(ifp.read())
39 ifp.close()
40 ofp.close()
42 print "=== Testing definitions output code ==="
43 execfile(defsoutput, {}, {})
44 print "=== Done scanning and generating, now importing the generated code... ==="
45 import qdsupport
46 print "=== Done. It's up to you to compile it now! ==="
48 class MyScanner(Scanner):
50 def destination(self, type, name, arglist):
51 classname = "Function"
52 listname = "functions"
53 if arglist:
54 t, n, m = arglist[0]
55 if t in ('GrafPtr', 'CGrafPtr') and m == 'InMode':
56 classname = "Method"
57 listname = "gr_methods"
58 elif t == 'BitMapPtr' and m == 'InMode':
59 classname = "Method"
60 listname = "bm_methods"
61 ## elif t == "PolyHandle" and m == "InMode":
62 ## classname = "Method"
63 ## listname = "p_methods"
64 ## elif t == "RgnHandle" and m == "InMode":
65 ## classname = "Method"
66 ## listname = "r_methods"
67 return classname, listname
70 def writeinitialdefs(self):
71 self.defsfile.write("""
72 def FOUR_CHAR_CODE(x): return x
73 normal = 0
74 bold = 1
75 italic = 2
76 underline = 4
77 outline = 8
78 shadow = 0x10
79 condense = 0x20
80 extend = 0x40
81 """)
83 def makeblacklistnames(self):
84 return [
85 'InitGraf',
86 'StuffHex',
87 'StdLine',
88 'StdComment',
89 'StdGetPic',
90 'OpenPort',
91 'InitPort',
92 'ClosePort',
93 'OpenCPort',
94 'InitCPort',
95 'CloseCPort',
96 'BitMapToRegionGlue',
97 'StdOpcode', # XXXX Missing from library...
98 # The following are for non-macos use:
99 'LockPortBits',
100 'UnlockPortBits',
101 'UpdatePort',
102 'GetPortNativeWindow',
103 'GetNativeWindowPort',
104 'NativeRegionToMacRegion',
105 'MacRegionToNativeRegion',
106 'GetPortHWND',
107 'GetHWNDPort',
108 'GetPICTFromDIB',
110 'HandleToRgn', # Funny signature
112 # Need Cm, which we don't want to drag in just yet
113 'OpenCursorComponent',
114 'CloseCursorComponent',
115 'SetCursorComponent',
116 'CursorComponentChanged',
117 'CursorComponentSetData',
120 def makeblacklisttypes(self):
121 return [
122 "QDRegionBitsRef", # Should do this, but too lazy now.
123 'CIconHandle', # Obsolete
124 'CQDProcs',
125 'CQDProcsPtr',
126 'CSpecArray',
127 'ColorComplementProcPtr',
128 'ColorComplementUPP',
129 'ColorSearchProcPtr',
130 'ColorSearchUPP',
131 'ConstPatternParam',
132 'DeviceLoopDrawingProcPtr',
133 'DeviceLoopFlags',
134 'GrafVerb',
135 'OpenCPicParams_ptr',
136 'Ptr',
137 'QDProcs',
138 'ReqListRec',
139 'void_ptr',
140 'CustomXFerProcPtr',
143 def makerepairinstructions(self):
144 return [
145 ([('void_ptr', 'textBuf', 'InMode'),
146 ('short', 'firstByte', 'InMode'),
147 ('short', 'byteCount', 'InMode')],
148 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
150 # GetPen and SetPt use a point-pointer as output-only:
151 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
152 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
154 # All others use it as input/output:
155 ([('Point', '*', 'OutMode')],
156 [('*', '*', 'InOutMode')]),
158 # InsetRect, OffsetRect
159 ([('Rect', 'r', 'OutMode'),
160 ('short', 'dh', 'InMode'),
161 ('short', 'dv', 'InMode')],
162 [('Rect', 'r', 'InOutMode'),
163 ('short', 'dh', 'InMode'),
164 ('short', 'dv', 'InMode')]),
166 # MapRect
167 ([('Rect', 'r', 'OutMode'),
168 ('Rect_ptr', 'srcRect', 'InMode'),
169 ('Rect_ptr', 'dstRect', 'InMode')],
170 [('Rect', 'r', 'InOutMode'),
171 ('Rect_ptr', 'srcRect', 'InMode'),
172 ('Rect_ptr', 'dstRect', 'InMode')]),
174 # CopyBits and friends
175 ([('RgnHandle', 'maskRgn', 'InMode')],
176 [('OptRgnHandle', 'maskRgn', 'InMode')]),
178 ('QDFlushPortBuffer',
179 [('RgnHandle', '*', 'InMode')],
180 [('OptRgnHandle', '*', 'InMode')]),
182 # Accessors with reference argument also returned.
183 ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
184 [('void', '*', 'ReturnMode')]),
186 ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
187 [('void', '*', 'ReturnMode')]),
189 ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
190 [('void', '*', 'ReturnMode')]),
192 ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
193 [('void', '*', 'ReturnMode')]),
195 ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
196 [('void', '*', 'ReturnMode')]),
198 ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
199 [('void', '*', 'ReturnMode')]),
201 ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
202 [('void', '*', 'ReturnMode')]),
204 ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
205 [('void', '*', 'ReturnMode')]),
207 ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
208 [('void', '*', 'ReturnMode')]),
210 ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
211 [('void', '*', 'ReturnMode')]),
213 ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
214 [('void', '*', 'ReturnMode')]),
216 ([('Pattern_ptr', '*', 'ReturnMode')],
217 [('void', '*', 'ReturnMode')]),
219 ([('Point_ptr', 'QDLocalToGlobalPoint', 'ReturnMode')],
220 [('void', '*', 'ReturnMode')]),
222 ([('Rect_ptr', 'QDLocalToGlobalRect', 'ReturnMode')],
223 [('void', '*', 'ReturnMode')]),
225 ([('Point_ptr', 'QDGlobalToLocalPoint', 'ReturnMode')],
226 [('void', '*', 'ReturnMode')]),
228 ([('Rect_ptr', 'QDGlobalToLocalRect', 'ReturnMode')],
229 [('void', '*', 'ReturnMode')]),
233 if __name__ == "__main__":
234 main()