blob: 6711ac28feb177c35c210f208915becfb95813a1 [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
5BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6sys.path.append(BGENDIR)
Guido van Rossume56db431995-03-19 22:49:50 +00007
8from scantools import Scanner
Jack Jansen46d9e791996-04-12 16:29:23 +00009from bgenlocations import TOOLBOXDIR
Guido van Rossume56db431995-03-19 22:49:50 +000010
11def main():
12 input = "QuickDraw.h"
13 output = "qdgen.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000014 defsoutput = TOOLBOXDIR + "QuickDraw.py"
Guido van Rossume56db431995-03-19 22:49:50 +000015 scanner = MyScanner(input, output, defsoutput)
16 scanner.scan()
17 scanner.close()
Jack Jansenb81cf9d1995-06-06 13:08:40 +000018
19 # Grmpf. Universal Headers have Text-stuff in a different include file...
20 input = "QuickDrawText.h"
21 output = "@qdgentext.py"
22 defsoutput = "@QuickDrawText.py"
23 have_extra = 0
24 try:
25 scanner = MyScanner(input, output, defsoutput)
26 scanner.scan()
27 scanner.close()
28 have_extra = 1
29 except IOError:
30 pass
31 if have_extra:
32 print "=== Copying QuickDrawText stuff into main files... ==="
33 ifp = open("@qdgentext.py")
34 ofp = open("qdgen.py", "a")
35 ofp.write(ifp.read())
36 ifp.close()
37 ofp.close()
38 ifp = open("@QuickDrawText.py")
Jack Jansen46d9e791996-04-12 16:29:23 +000039 ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
Jack Jansenb81cf9d1995-06-06 13:08:40 +000040 ofp.write(ifp.read())
41 ifp.close()
42 ofp.close()
43
Guido van Rossume56db431995-03-19 22:49:50 +000044 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! ==="
47
48class MyScanner(Scanner):
49
50 def destination(self, type, name, arglist):
51 classname = "Function"
52 listname = "functions"
53 if arglist:
54 t, n, m = arglist[0]
Jack Jansen330381c1995-11-15 15:18:01 +000055## elif t == "PolyHandle" and m == "InMode":
56## classname = "Method"
57## listname = "p_methods"
58## elif t == "RgnHandle" and m == "InMode":
59## classname = "Method"
60## listname = "r_methods"
Guido van Rossume56db431995-03-19 22:49:50 +000061 return classname, listname
62
Jack Jansen7f725e41998-04-23 13:21:09 +000063
64 def writeinitialdefs(self):
Jack Jansend9f5a391999-01-21 13:31:30 +000065 self.defsfile.write("""
66def FOUR_CHAR_CODE(x): return x
67normal = 0
68bold = 1
69italic = 2
70underline = 4
71outline = 8
72shadow = 0x10
73condense = 0x20
74extend = 0x40
75""")
Jack Jansen7f725e41998-04-23 13:21:09 +000076
Guido van Rossume56db431995-03-19 22:49:50 +000077 def makeblacklistnames(self):
78 return [
79 'InitGraf',
80 'StuffHex',
81 'StdLine',
82 'StdComment',
83 'StdGetPic',
Jack Jansen330381c1995-11-15 15:18:01 +000084 'OpenPort',
85 'InitPort',
86 'ClosePort',
87 'OpenCPort',
88 'InitCPort',
89 'CloseCPort',
Jack Jansen41058c01995-11-16 22:48:29 +000090 'BitMapToRegionGlue',
Jack Jansen21f96871998-02-20 16:02:09 +000091 'StdOpcode', # XXXX Missing from library...
Jack Jansen1c4e6141998-04-21 15:23:55 +000092 # The following are for non-macos use:
93 'LockPortBits',
94 'UnlockPortBits',
95 'UpdatePort',
96 'GetPortNativeWindow',
97 'GetNativeWindowPort',
98 'NativeRegionToMacRegion',
99 'MacRegionToNativeRegion',
100 'GetPortHWND',
101 'GetHWNDPort',
102 'GetPICTFromDIB',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000103 'GetPortBitMapForCopyBits', # Something funny in the declaration
Jack Jansenbd58eda2001-01-24 14:05:11 +0000104
105 'HandleToRgn', # Funny signature
Jack Jansen21f96871998-02-20 16:02:09 +0000106
Jack Jansenf47075e2001-01-24 14:22:13 +0000107 # Need Cm, which we don't want to drag in just yet
108 'OpenCursorComponent',
109 'CloseCursorComponent',
110 'SetCursorComponent',
111 'CursorComponentChanged',
112 'CursorComponentSetData',
Guido van Rossume56db431995-03-19 22:49:50 +0000113 ]
114
Jack Jansen723ad8a2000-12-12 22:10:21 +0000115 def makegreylist(self):
116 return [
117 ('#if !TARGET_API_MAC_CARBON', [
118 ]),
119 ('#if TARGET_API_MAC_CARBON', [
Jack Jansenbd58eda2001-01-24 14:05:11 +0000120 'IsPortOffscreen', # Lazy
121 'IsPortColor', # Lazy
122 'IsRegionRectangular',
123 'CreateNewPort',
124 'DisposePort',
125 'SetQDError',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000126 ])]
127
128
Guido van Rossume56db431995-03-19 22:49:50 +0000129 def makeblacklisttypes(self):
130 return [
Jack Jansen69b43ed1997-08-15 14:35:54 +0000131 'CIconHandle', # Obsolete
Guido van Rossume56db431995-03-19 22:49:50 +0000132 'CQDProcs',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000133 'CQDProcsPtr',
Guido van Rossume56db431995-03-19 22:49:50 +0000134 'CSpecArray',
Guido van Rossume56db431995-03-19 22:49:50 +0000135 'ColorComplementProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000136 'ColorComplementUPP',
Guido van Rossume56db431995-03-19 22:49:50 +0000137 'ColorSearchProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000138 'ColorSearchUPP',
Guido van Rossume56db431995-03-19 22:49:50 +0000139 'ConstPatternParam',
Guido van Rossume56db431995-03-19 22:49:50 +0000140 'DeviceLoopDrawingProcPtr',
141 'DeviceLoopFlags',
Guido van Rossume56db431995-03-19 22:49:50 +0000142 'GrafVerb',
143 'OpenCPicParams_ptr',
Guido van Rossume56db431995-03-19 22:49:50 +0000144 'Ptr',
145 'QDProcs',
Guido van Rossume56db431995-03-19 22:49:50 +0000146 'ReqListRec',
147 'void_ptr',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000148 'CustomXFerProcPtr',
Guido van Rossume56db431995-03-19 22:49:50 +0000149 ]
150
151 def makerepairinstructions(self):
152 return [
153 ([('void_ptr', 'textBuf', 'InMode'),
154 ('short', 'firstByte', 'InMode'),
155 ('short', 'byteCount', 'InMode')],
156 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
157
Jack Jansen1d8ede71996-01-08 23:47:31 +0000158 # GetPen and SetPt use a point-pointer as output-only:
159 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
160 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
161
162 # All others use it as input/output:
Guido van Rossume56db431995-03-19 22:49:50 +0000163 ([('Point', '*', 'OutMode')],
164 [('*', '*', 'InOutMode')]),
Jack Jansen54c8f7e1995-11-14 10:46:01 +0000165
166 # InsetRect, OffsetRect
167 ([('Rect', 'r', 'OutMode'),
168 ('short', 'dh', 'InMode'),
169 ('short', 'dv', 'InMode')],
170 [('Rect', 'r', 'InOutMode'),
171 ('short', 'dh', 'InMode'),
172 ('short', 'dv', 'InMode')]),
173
174 # MapRect
175 ([('Rect', 'r', 'OutMode'),
176 ('Rect_ptr', 'srcRect', 'InMode'),
177 ('Rect_ptr', 'dstRect', 'InMode')],
178 [('Rect', 'r', 'InOutMode'),
179 ('Rect_ptr', 'srcRect', 'InMode'),
180 ('Rect_ptr', 'dstRect', 'InMode')]),
Jack Jansen425e9eb1995-12-12 15:02:03 +0000181
182 # CopyBits and friends
183 ([('RgnHandle', 'maskRgn', 'InMode')],
184 [('OptRgnHandle', 'maskRgn', 'InMode')]),
Jack Jansenbd58eda2001-01-24 14:05:11 +0000185
186 # Accessors with reference argument also returned.
187 ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
188 [('void', '*', 'ReturnMode')]),
189
190 ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
191 [('void', '*', 'ReturnMode')]),
192
193 ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
194 [('void', '*', 'ReturnMode')]),
195
196 ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
197 [('void', '*', 'ReturnMode')]),
198
199 ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
200 [('void', '*', 'ReturnMode')]),
201
202 ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
203 [('void', '*', 'ReturnMode')]),
204
205 ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
206 [('void', '*', 'ReturnMode')]),
207
208 ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
209 [('void', '*', 'ReturnMode')]),
210
211 ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
212 [('void', '*', 'ReturnMode')]),
213
214 ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
215 [('void', '*', 'ReturnMode')]),
216
217 ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
218 [('void', '*', 'ReturnMode')]),
219
220 ([('Pattern_ptr', '*', 'ReturnMode')],
221 [('void', '*', 'ReturnMode')]),
Guido van Rossume56db431995-03-19 22:49:50 +0000222
223 ]
224
225if __name__ == "__main__":
226 main()