blob: 6c87ce089858c1d3847976c4d1e5867dee4296d8 [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
3import addpack
Jack Jansenb81cf9d1995-06-06 13:08:40 +00004addpack.addpack(':Tools:bgen:bgen')
Guido van Rossume56db431995-03-19 22:49:50 +00005
6from scantools import Scanner
7
8def main():
9 input = "QuickDraw.h"
10 output = "qdgen.py"
11 defsoutput = "QuickDraw.py"
12 scanner = MyScanner(input, output, defsoutput)
13 scanner.scan()
14 scanner.close()
Jack Jansenb81cf9d1995-06-06 13:08:40 +000015
16 # Grmpf. Universal Headers have Text-stuff in a different include file...
17 input = "QuickDrawText.h"
18 output = "@qdgentext.py"
19 defsoutput = "@QuickDrawText.py"
20 have_extra = 0
21 try:
22 scanner = MyScanner(input, output, defsoutput)
23 scanner.scan()
24 scanner.close()
25 have_extra = 1
26 except IOError:
27 pass
28 if have_extra:
29 print "=== Copying QuickDrawText stuff into main files... ==="
30 ifp = open("@qdgentext.py")
31 ofp = open("qdgen.py", "a")
32 ofp.write(ifp.read())
33 ifp.close()
34 ofp.close()
35 ifp = open("@QuickDrawText.py")
36 ofp = open("QuickDraw.py", "a")
37 ofp.write(ifp.read())
38 ifp.close()
39 ofp.close()
40
Guido van Rossume56db431995-03-19 22:49:50 +000041 print "=== Done scanning and generating, now importing the generated code... ==="
42 import qdsupport
43 print "=== Done. It's up to you to compile it now! ==="
44
45class MyScanner(Scanner):
46
47 def destination(self, type, name, arglist):
48 classname = "Function"
49 listname = "functions"
50 if arglist:
51 t, n, m = arglist[0]
Jack Jansen330381c1995-11-15 15:18:01 +000052## elif t == "PolyHandle" and m == "InMode":
53## classname = "Method"
54## listname = "p_methods"
55## elif t == "RgnHandle" and m == "InMode":
56## classname = "Method"
57## listname = "r_methods"
Guido van Rossume56db431995-03-19 22:49:50 +000058 return classname, listname
59
60 def makeblacklistnames(self):
61 return [
62 'InitGraf',
63 'StuffHex',
64 'StdLine',
65 'StdComment',
66 'StdGetPic',
Jack Jansen330381c1995-11-15 15:18:01 +000067 'OpenPort',
68 'InitPort',
69 'ClosePort',
70 'OpenCPort',
71 'InitCPort',
72 'CloseCPort',
Jack Jansen41058c01995-11-16 22:48:29 +000073 'BitMapToRegionGlue',
Guido van Rossume56db431995-03-19 22:49:50 +000074 ]
75
76 def makeblacklisttypes(self):
77 return [
Guido van Rossume56db431995-03-19 22:49:50 +000078 'CCrsrHandle',
Guido van Rossume56db431995-03-19 22:49:50 +000079 'CIconHandle',
80 'CQDProcs',
81 'CSpecArray',
82 'CTabHandle',
83 'ColorComplementProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +000084 'ColorComplementUPP',
Guido van Rossume56db431995-03-19 22:49:50 +000085 'ColorSearchProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +000086 'ColorSearchUPP',
Guido van Rossume56db431995-03-19 22:49:50 +000087 'ConstPatternParam',
Jack Jansen04a02e71996-01-06 17:12:58 +000088## 'Pattern_ptr',
89## 'Pattern',
Jack Jansenb5394061996-01-05 18:06:41 +000090## 'Cursor_ptr',
Guido van Rossume56db431995-03-19 22:49:50 +000091 'DeviceLoopDrawingProcPtr',
92 'DeviceLoopFlags',
93 'FontInfo',
94 'GDHandle',
95 'GrafVerb',
96 'OpenCPicParams_ptr',
Jack Jansen04a02e71996-01-06 17:12:58 +000097## 'PenState',
98## 'PenState_ptr',
Guido van Rossume56db431995-03-19 22:49:50 +000099 'Ptr',
100 'QDProcs',
Guido van Rossume56db431995-03-19 22:49:50 +0000101 'ReqListRec',
102 'void_ptr',
103 ]
104
105 def makerepairinstructions(self):
106 return [
107 ([('void_ptr', 'textBuf', 'InMode'),
108 ('short', 'firstByte', 'InMode'),
109 ('short', 'byteCount', 'InMode')],
110 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
111
Jack Jansen1d8ede71996-01-08 23:47:31 +0000112 # GetPen and SetPt use a point-pointer as output-only:
113 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
114 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
115
116 # All others use it as input/output:
Guido van Rossume56db431995-03-19 22:49:50 +0000117 ([('Point', '*', 'OutMode')],
118 [('*', '*', 'InOutMode')]),
Jack Jansen54c8f7e1995-11-14 10:46:01 +0000119
120 # InsetRect, OffsetRect
121 ([('Rect', 'r', 'OutMode'),
122 ('short', 'dh', 'InMode'),
123 ('short', 'dv', 'InMode')],
124 [('Rect', 'r', 'InOutMode'),
125 ('short', 'dh', 'InMode'),
126 ('short', 'dv', 'InMode')]),
127
128 # MapRect
129 ([('Rect', 'r', 'OutMode'),
130 ('Rect_ptr', 'srcRect', 'InMode'),
131 ('Rect_ptr', 'dstRect', 'InMode')],
132 [('Rect', 'r', 'InOutMode'),
133 ('Rect_ptr', 'srcRect', 'InMode'),
134 ('Rect_ptr', 'dstRect', 'InMode')]),
Jack Jansen425e9eb1995-12-12 15:02:03 +0000135
136 # CopyBits and friends
137 ([('RgnHandle', 'maskRgn', 'InMode')],
138 [('OptRgnHandle', 'maskRgn', 'InMode')]),
Guido van Rossume56db431995-03-19 22:49:50 +0000139
140 ]
141
142if __name__ == "__main__":
143 main()