Ditched '_find_SET()', since it was a no-value-added wrapper around
[python/dscho.git] / Mac / Modules / qd / qdscan.py
blob969baf3fac7fe509bfc03cbfcc813938ce525df0
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',
107 def makeblacklisttypes(self):
108 return [
109 ## 'CCrsrHandle',
110 'CIconHandle', # Obsolete
111 'CQDProcs',
112 'CSpecArray',
113 ## 'CTabHandle',
114 'ColorComplementProcPtr',
115 'ColorComplementUPP',
116 'ColorSearchProcPtr',
117 'ColorSearchUPP',
118 'ConstPatternParam',
119 'DeviceLoopDrawingProcPtr',
120 'DeviceLoopFlags',
121 ## 'FontInfo',
122 ## 'GDHandle',
123 'GrafVerb',
124 'OpenCPicParams_ptr',
125 'Ptr',
126 'QDProcs',
127 'ReqListRec',
128 'void_ptr',
131 def makerepairinstructions(self):
132 return [
133 ([('void_ptr', 'textBuf', 'InMode'),
134 ('short', 'firstByte', 'InMode'),
135 ('short', 'byteCount', 'InMode')],
136 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
138 # GetPen and SetPt use a point-pointer as output-only:
139 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
140 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
142 # All others use it as input/output:
143 ([('Point', '*', 'OutMode')],
144 [('*', '*', 'InOutMode')]),
146 # InsetRect, OffsetRect
147 ([('Rect', 'r', 'OutMode'),
148 ('short', 'dh', 'InMode'),
149 ('short', 'dv', 'InMode')],
150 [('Rect', 'r', 'InOutMode'),
151 ('short', 'dh', 'InMode'),
152 ('short', 'dv', 'InMode')]),
154 # MapRect
155 ([('Rect', 'r', 'OutMode'),
156 ('Rect_ptr', 'srcRect', 'InMode'),
157 ('Rect_ptr', 'dstRect', 'InMode')],
158 [('Rect', 'r', 'InOutMode'),
159 ('Rect_ptr', 'srcRect', 'InMode'),
160 ('Rect_ptr', 'dstRect', 'InMode')]),
162 # CopyBits and friends
163 ([('RgnHandle', 'maskRgn', 'InMode')],
164 [('OptRgnHandle', 'maskRgn', 'InMode')]),
168 if __name__ == "__main__":
169 main()