This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Mac / Modules / qd / qdscan.py
blob756291514ffbb393b829af5ee9d573bdfe4ab52f
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 import os
5 BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6 sys.path.append(BGENDIR)
8 from scantools import Scanner
9 from bgenlocations import TOOLBOXDIR
11 def main():
12 input = "QuickDraw.h"
13 output = "qdgen.py"
14 defsoutput = TOOLBOXDIR + "QuickDraw.py"
15 scanner = MyScanner(input, output, defsoutput)
16 scanner.scan()
17 scanner.close()
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")
39 ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
40 ofp.write(ifp.read())
41 ifp.close()
42 ofp.close()
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 ## 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"
61 return classname, listname
64 def writeinitialdefs(self):
65 self.defsfile.write("""
66 def FOUR_CHAR_CODE(x): return x
67 normal = 0
68 bold = 1
69 italic = 2
70 underline = 4
71 outline = 8
72 shadow = 0x10
73 condense = 0x20
74 extend = 0x40
75 """)
77 def makeblacklistnames(self):
78 return [
79 'InitGraf',
80 'StuffHex',
81 'StdLine',
82 'StdComment',
83 'StdGetPic',
84 'OpenPort',
85 'InitPort',
86 'ClosePort',
87 'OpenCPort',
88 'InitCPort',
89 'CloseCPort',
90 'BitMapToRegionGlue',
91 'StdOpcode', # XXXX Missing from library...
92 # 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',
104 'HandleToRgn', # Funny signature
106 # Need Cm, which we don't want to drag in just yet
107 'OpenCursorComponent',
108 'CloseCursorComponent',
109 'SetCursorComponent',
110 'CursorComponentChanged',
111 'CursorComponentSetData',
114 def makegreylist(self):
115 return [
116 ('#if !TARGET_API_MAC_CARBON', [
118 ('#if TARGET_API_MAC_CARBON', [
119 'IsPortOffscreen', # Lazy
120 'IsPortColor', # Lazy
121 'IsRegionRectangular',
122 'CreateNewPort',
123 'DisposePort',
124 'SetQDError',
125 'IsPortPolyBeingDefined',
126 'QDSetDirtyRegion',
127 'QDGetDirtyRegion',
128 'IsValidPort',
129 'RgnToHandle',
133 def makeblacklisttypes(self):
134 return [
135 'CIconHandle', # Obsolete
136 'CQDProcs',
137 'CQDProcsPtr',
138 'CSpecArray',
139 'ColorComplementProcPtr',
140 'ColorComplementUPP',
141 'ColorSearchProcPtr',
142 'ColorSearchUPP',
143 'ConstPatternParam',
144 'DeviceLoopDrawingProcPtr',
145 'DeviceLoopFlags',
146 'GrafVerb',
147 'OpenCPicParams_ptr',
148 'Ptr',
149 'QDProcs',
150 'ReqListRec',
151 'void_ptr',
152 'CustomXFerProcPtr',
155 def makerepairinstructions(self):
156 return [
157 ([('void_ptr', 'textBuf', 'InMode'),
158 ('short', 'firstByte', 'InMode'),
159 ('short', 'byteCount', 'InMode')],
160 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
162 # GetPen and SetPt use a point-pointer as output-only:
163 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
164 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
166 # All others use it as input/output:
167 ([('Point', '*', 'OutMode')],
168 [('*', '*', 'InOutMode')]),
170 # InsetRect, OffsetRect
171 ([('Rect', 'r', 'OutMode'),
172 ('short', 'dh', 'InMode'),
173 ('short', 'dv', 'InMode')],
174 [('Rect', 'r', 'InOutMode'),
175 ('short', 'dh', 'InMode'),
176 ('short', 'dv', 'InMode')]),
178 # MapRect
179 ([('Rect', 'r', 'OutMode'),
180 ('Rect_ptr', 'srcRect', 'InMode'),
181 ('Rect_ptr', 'dstRect', 'InMode')],
182 [('Rect', 'r', 'InOutMode'),
183 ('Rect_ptr', 'srcRect', 'InMode'),
184 ('Rect_ptr', 'dstRect', 'InMode')]),
186 # CopyBits and friends
187 ([('RgnHandle', 'maskRgn', 'InMode')],
188 [('OptRgnHandle', 'maskRgn', 'InMode')]),
190 ('QDFlushPortBuffer',
191 [('RgnHandle', '*', 'InMode')],
192 [('OptRgnHandle', '*', 'InMode')]),
194 # Accessors with reference argument also returned.
195 ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
196 [('void', '*', 'ReturnMode')]),
198 ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
199 [('void', '*', 'ReturnMode')]),
201 ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
202 [('void', '*', 'ReturnMode')]),
204 ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
205 [('void', '*', 'ReturnMode')]),
207 ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
208 [('void', '*', 'ReturnMode')]),
210 ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
211 [('void', '*', 'ReturnMode')]),
213 ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
214 [('void', '*', 'ReturnMode')]),
216 ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
217 [('void', '*', 'ReturnMode')]),
219 ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
220 [('void', '*', 'ReturnMode')]),
222 ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
223 [('void', '*', 'ReturnMode')]),
225 ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
226 [('void', '*', 'ReturnMode')]),
228 ([('Pattern_ptr', '*', 'ReturnMode')],
229 [('void', '*', 'ReturnMode')]),
233 if __name__ == "__main__":
234 main()