blob: 85a8cdc04c1504da86528d212d63c7e460075b14 [file] [log] [blame]
Guido van Rossume56db431995-03-19 22:49:50 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
Jack Jansen0c4d9471998-04-17 14:07:56 +00003import sys
4import os
Jack Jansenaaebdd62002-08-05 15:39:30 +00005from bgenlocations import TOOLBOXDIR, BGENDIR
Jack Jansen0c4d9471998-04-17 14:07:56 +00006sys.path.append(BGENDIR)
Guido van Rossume56db431995-03-19 22:49:50 +00007
8from scantools import Scanner
9
10def main():
Tim Peters182b5ac2004-07-18 06:16:08 +000011 input = "QuickDraw.h"
12 output = "qdgen.py"
13 defsoutput = TOOLBOXDIR + "QuickDraw.py"
14 scanner = MyScanner(input, output, defsoutput)
15 scanner.scan()
16 scanner.close()
17
18 # Grmpf. Universal Headers have Text-stuff in a different include file...
19 input = "QuickDrawText.h"
20 output = "@qdgentext.py"
21 defsoutput = "@QuickDrawText.py"
22 have_extra = 0
23 try:
24 scanner = MyScanner(input, output, defsoutput)
25 scanner.scan()
26 scanner.close()
27 have_extra = 1
28 except IOError:
29 pass
30 if have_extra:
31 print "=== Copying QuickDrawText stuff into main files... ==="
32 ifp = open("@qdgentext.py")
33 ofp = open("qdgen.py", "a")
34 ofp.write(ifp.read())
35 ifp.close()
36 ofp.close()
37 ifp = open("@QuickDrawText.py")
38 ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
39 ofp.write(ifp.read())
40 ifp.close()
41 ofp.close()
42
43 print "=== Testing definitions output code ==="
44 execfile(defsoutput, {}, {})
45 print "=== Done scanning and generating, now importing the generated code... ==="
46 import qdsupport
47 print "=== Done. It's up to you to compile it now! ==="
Guido van Rossume56db431995-03-19 22:49:50 +000048
49class MyScanner(Scanner):
50
Tim Peters182b5ac2004-07-18 06:16:08 +000051 def destination(self, type, name, arglist):
52 classname = "Function"
53 listname = "functions"
54 if arglist:
55 t, n, m = arglist[0]
56 if t in ('GrafPtr', 'CGrafPtr') and m == 'InMode':
57 classname = "Method"
58 listname = "gr_methods"
59 elif t == 'BitMapPtr' and m == 'InMode':
60 classname = "Method"
61 listname = "bm_methods"
62## elif t == "PolyHandle" and m == "InMode":
63## classname = "Method"
64## listname = "p_methods"
65## elif t == "RgnHandle" and m == "InMode":
66## classname = "Method"
67## listname = "r_methods"
68 return classname, listname
Guido van Rossume56db431995-03-19 22:49:50 +000069
Jack Jansen7f725e41998-04-23 13:21:09 +000070
Tim Peters182b5ac2004-07-18 06:16:08 +000071 def writeinitialdefs(self):
72 self.defsfile.write("""
Jack Jansend9f5a391999-01-21 13:31:30 +000073def FOUR_CHAR_CODE(x): return x
Tim Peters182b5ac2004-07-18 06:16:08 +000074normal = 0
75bold = 1
76italic = 2
77underline = 4
78outline = 8
79shadow = 0x10
80condense = 0x20
81extend = 0x40
Jack Jansend9f5a391999-01-21 13:31:30 +000082""")
Jack Jansen7f725e41998-04-23 13:21:09 +000083
Tim Peters182b5ac2004-07-18 06:16:08 +000084 def makeblacklistnames(self):
85 return [
86 'InitGraf',
87 'StuffHex',
88 'StdLine',
89 'StdComment',
90 'StdGetPic',
91 'OpenPort',
92 'InitPort',
93 'ClosePort',
94 'OpenCPort',
95 'InitCPort',
96 'CloseCPort',
97 'BitMapToRegionGlue',
98 'StdOpcode', # XXXX Missing from library...
99 # The following are for non-macos use:
100 'LockPortBits',
101 'UnlockPortBits',
102 'UpdatePort',
103 'GetPortNativeWindow',
104 'GetNativeWindowPort',
105 'NativeRegionToMacRegion',
106 'MacRegionToNativeRegion',
107 'GetPortHWND',
108 'GetHWNDPort',
109 'GetPICTFromDIB',
Jack Jansen21f96871998-02-20 16:02:09 +0000110
Tim Peters182b5ac2004-07-18 06:16:08 +0000111 'HandleToRgn', # Funny signature
Guido van Rossume56db431995-03-19 22:49:50 +0000112
Tim Peters182b5ac2004-07-18 06:16:08 +0000113 # Need Cm, which we don't want to drag in just yet
114 'OpenCursorComponent',
115 'CloseCursorComponent',
116 'SetCursorComponent',
117 'CursorComponentChanged',
118 'CursorComponentSetData',
119 ]
Guido van Rossume56db431995-03-19 22:49:50 +0000120
Tim Peters182b5ac2004-07-18 06:16:08 +0000121 def makeblacklisttypes(self):
122 return [
123 "QDRegionBitsRef", # Should do this, but too lazy now.
124 'CIconHandle', # Obsolete
125 'CQDProcs',
126 'CQDProcsPtr',
127 'CSpecArray',
128 'ColorComplementProcPtr',
129 'ColorComplementUPP',
130 'ColorSearchProcPtr',
131 'ColorSearchUPP',
132 'ConstPatternParam',
133 'DeviceLoopDrawingProcPtr',
134 'DeviceLoopFlags',
135 'GrafVerb',
136 'OpenCPicParams_ptr',
137 'Ptr',
138 'QDProcs',
139 'ReqListRec',
140 'void_ptr',
141 'CustomXFerProcPtr',
142 ]
Jack Jansen54c8f7e1995-11-14 10:46:01 +0000143
Tim Peters182b5ac2004-07-18 06:16:08 +0000144 def makerepairinstructions(self):
145 return [
146 ([('void_ptr', 'textBuf', 'InMode'),
147 ('short', 'firstByte', 'InMode'),
148 ('short', 'byteCount', 'InMode')],
149 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
150
151 # GetPen and SetPt use a point-pointer as output-only:
152 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
153 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
154
155 # All others use it as input/output:
156 ([('Point', '*', 'OutMode')],
157 [('*', '*', 'InOutMode')]),
158
159 # InsetRect, OffsetRect
160 ([('Rect', 'r', 'OutMode'),
161 ('short', 'dh', 'InMode'),
162 ('short', 'dv', 'InMode')],
163 [('Rect', 'r', 'InOutMode'),
164 ('short', 'dh', 'InMode'),
165 ('short', 'dv', 'InMode')]),
166
167 # MapRect
168 ([('Rect', 'r', 'OutMode'),
169 ('Rect_ptr', 'srcRect', 'InMode'),
170 ('Rect_ptr', 'dstRect', 'InMode')],
171 [('Rect', 'r', 'InOutMode'),
172 ('Rect_ptr', 'srcRect', 'InMode'),
173 ('Rect_ptr', 'dstRect', 'InMode')]),
174
175 # CopyBits and friends
176 ([('RgnHandle', 'maskRgn', 'InMode')],
177 [('OptRgnHandle', 'maskRgn', 'InMode')]),
178
179 ('QDFlushPortBuffer',
180 [('RgnHandle', '*', 'InMode')],
181 [('OptRgnHandle', '*', 'InMode')]),
182
183 # Accessors with reference argument also returned.
184 ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
185 [('void', '*', 'ReturnMode')]),
186
187 ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
188 [('void', '*', 'ReturnMode')]),
189
190 ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
191 [('void', '*', 'ReturnMode')]),
192
193 ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
194 [('void', '*', 'ReturnMode')]),
195
196 ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
197 [('void', '*', 'ReturnMode')]),
198
199 ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
200 [('void', '*', 'ReturnMode')]),
201
202 ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
203 [('void', '*', 'ReturnMode')]),
204
205 ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
206 [('void', '*', 'ReturnMode')]),
207
208 ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
209 [('void', '*', 'ReturnMode')]),
210
211 ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
212 [('void', '*', 'ReturnMode')]),
213
214 ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
215 [('void', '*', 'ReturnMode')]),
216
217 ([('Pattern_ptr', '*', 'ReturnMode')],
218 [('void', '*', 'ReturnMode')]),
219
220 ([('Point_ptr', 'QDLocalToGlobalPoint', 'ReturnMode')],
221 [('void', '*', 'ReturnMode')]),
222
223 ([('Rect_ptr', 'QDLocalToGlobalRect', 'ReturnMode')],
224 [('void', '*', 'ReturnMode')]),
225
226 ([('Point_ptr', 'QDGlobalToLocalPoint', 'ReturnMode')],
227 [('void', '*', 'ReturnMode')]),
228
229 ([('Rect_ptr', 'QDGlobalToLocalRect', 'ReturnMode')],
230 [('void', '*', 'ReturnMode')]),
231
232 ]
Guido van Rossume56db431995-03-19 22:49:50 +0000233
234if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +0000235 main()