blob: 9d1a506ca455894fa8c24e7cbf8193e69758cd50 [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
Guido van Rossume56db431995-03-19 22:49:50 +0000107 ]
108
Jack Jansen723ad8a2000-12-12 22:10:21 +0000109 def makegreylist(self):
110 return [
111 ('#if !TARGET_API_MAC_CARBON', [
112 ]),
113 ('#if TARGET_API_MAC_CARBON', [
Jack Jansenbd58eda2001-01-24 14:05:11 +0000114 'IsPortOffscreen', # Lazy
115 'IsPortColor', # Lazy
116 'IsRegionRectangular',
117 'CreateNewPort',
118 'DisposePort',
119 'SetQDError',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000120 ])]
121
122
Guido van Rossume56db431995-03-19 22:49:50 +0000123 def makeblacklisttypes(self):
124 return [
Jack Jansen69b43ed1997-08-15 14:35:54 +0000125 'CIconHandle', # Obsolete
Guido van Rossume56db431995-03-19 22:49:50 +0000126 'CQDProcs',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000127 'CQDProcsPtr',
Guido van Rossume56db431995-03-19 22:49:50 +0000128 'CSpecArray',
Guido van Rossume56db431995-03-19 22:49:50 +0000129 'ColorComplementProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000130 'ColorComplementUPP',
Guido van Rossume56db431995-03-19 22:49:50 +0000131 'ColorSearchProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000132 'ColorSearchUPP',
Guido van Rossume56db431995-03-19 22:49:50 +0000133 'ConstPatternParam',
Guido van Rossume56db431995-03-19 22:49:50 +0000134 'DeviceLoopDrawingProcPtr',
135 'DeviceLoopFlags',
Guido van Rossume56db431995-03-19 22:49:50 +0000136 'GrafVerb',
137 'OpenCPicParams_ptr',
Guido van Rossume56db431995-03-19 22:49:50 +0000138 'Ptr',
139 'QDProcs',
Guido van Rossume56db431995-03-19 22:49:50 +0000140 'ReqListRec',
141 'void_ptr',
Jack Jansen723ad8a2000-12-12 22:10:21 +0000142 'CustomXFerProcPtr',
Guido van Rossume56db431995-03-19 22:49:50 +0000143 ]
144
145 def makerepairinstructions(self):
146 return [
147 ([('void_ptr', 'textBuf', 'InMode'),
148 ('short', 'firstByte', 'InMode'),
149 ('short', 'byteCount', 'InMode')],
150 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
151
Jack Jansen1d8ede71996-01-08 23:47:31 +0000152 # GetPen and SetPt use a point-pointer as output-only:
153 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
154 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
155
156 # All others use it as input/output:
Guido van Rossume56db431995-03-19 22:49:50 +0000157 ([('Point', '*', 'OutMode')],
158 [('*', '*', 'InOutMode')]),
Jack Jansen54c8f7e1995-11-14 10:46:01 +0000159
160 # InsetRect, OffsetRect
161 ([('Rect', 'r', 'OutMode'),
162 ('short', 'dh', 'InMode'),
163 ('short', 'dv', 'InMode')],
164 [('Rect', 'r', 'InOutMode'),
165 ('short', 'dh', 'InMode'),
166 ('short', 'dv', 'InMode')]),
167
168 # MapRect
169 ([('Rect', 'r', 'OutMode'),
170 ('Rect_ptr', 'srcRect', 'InMode'),
171 ('Rect_ptr', 'dstRect', 'InMode')],
172 [('Rect', 'r', 'InOutMode'),
173 ('Rect_ptr', 'srcRect', 'InMode'),
174 ('Rect_ptr', 'dstRect', 'InMode')]),
Jack Jansen425e9eb1995-12-12 15:02:03 +0000175
176 # CopyBits and friends
177 ([('RgnHandle', 'maskRgn', 'InMode')],
178 [('OptRgnHandle', 'maskRgn', 'InMode')]),
Jack Jansenbd58eda2001-01-24 14:05:11 +0000179
180 # Accessors with reference argument also returned.
181 ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
182 [('void', '*', 'ReturnMode')]),
183
184 ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
185 [('void', '*', 'ReturnMode')]),
186
187 ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
188 [('void', '*', 'ReturnMode')]),
189
190 ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
191 [('void', '*', 'ReturnMode')]),
192
193 ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
194 [('void', '*', 'ReturnMode')]),
195
196 ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
197 [('void', '*', 'ReturnMode')]),
198
199 ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
200 [('void', '*', 'ReturnMode')]),
201
202 ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
203 [('void', '*', 'ReturnMode')]),
204
205 ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
206 [('void', '*', 'ReturnMode')]),
207
208 ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
209 [('void', '*', 'ReturnMode')]),
210
211 ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
212 [('void', '*', 'ReturnMode')]),
213
214 ([('Pattern_ptr', '*', 'ReturnMode')],
215 [('void', '*', 'ReturnMode')]),
Guido van Rossume56db431995-03-19 22:49:50 +0000216
217 ]
218
219if __name__ == "__main__":
220 main()