blob: 86f69aaee7431596e5f92e5f8b3f55802d8c00f9 [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
63 def makeblacklistnames(self):
64 return [
65 'InitGraf',
66 'StuffHex',
67 'StdLine',
68 'StdComment',
69 'StdGetPic',
Jack Jansen330381c1995-11-15 15:18:01 +000070 'OpenPort',
71 'InitPort',
72 'ClosePort',
73 'OpenCPort',
74 'InitCPort',
75 'CloseCPort',
Jack Jansen41058c01995-11-16 22:48:29 +000076 'BitMapToRegionGlue',
Jack Jansen21f96871998-02-20 16:02:09 +000077 'StdOpcode', # XXXX Missing from library...
Jack Jansen1c4e6141998-04-21 15:23:55 +000078 # The following are for non-macos use:
79 'LockPortBits',
80 'UnlockPortBits',
81 'UpdatePort',
82 'GetPortNativeWindow',
83 'GetNativeWindowPort',
84 'NativeRegionToMacRegion',
85 'MacRegionToNativeRegion',
86 'GetPortHWND',
87 'GetHWNDPort',
88 'GetPICTFromDIB',
89
Jack Jansen21f96871998-02-20 16:02:09 +000090
Guido van Rossume56db431995-03-19 22:49:50 +000091 ]
92
93 def makeblacklisttypes(self):
94 return [
Jack Jansen69b43ed1997-08-15 14:35:54 +000095## 'CCrsrHandle',
96 'CIconHandle', # Obsolete
Guido van Rossume56db431995-03-19 22:49:50 +000097 'CQDProcs',
98 'CSpecArray',
Jack Jansen69b43ed1997-08-15 14:35:54 +000099## 'CTabHandle',
Guido van Rossume56db431995-03-19 22:49:50 +0000100 'ColorComplementProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000101 'ColorComplementUPP',
Guido van Rossume56db431995-03-19 22:49:50 +0000102 'ColorSearchProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000103 'ColorSearchUPP',
Guido van Rossume56db431995-03-19 22:49:50 +0000104 'ConstPatternParam',
Guido van Rossume56db431995-03-19 22:49:50 +0000105 'DeviceLoopDrawingProcPtr',
106 'DeviceLoopFlags',
Jack Jansen3a50f8a1996-01-11 16:17:14 +0000107## 'FontInfo',
Jack Jansen69b43ed1997-08-15 14:35:54 +0000108## 'GDHandle',
Guido van Rossume56db431995-03-19 22:49:50 +0000109 'GrafVerb',
110 'OpenCPicParams_ptr',
Guido van Rossume56db431995-03-19 22:49:50 +0000111 'Ptr',
112 'QDProcs',
Guido van Rossume56db431995-03-19 22:49:50 +0000113 'ReqListRec',
114 'void_ptr',
115 ]
116
117 def makerepairinstructions(self):
118 return [
119 ([('void_ptr', 'textBuf', 'InMode'),
120 ('short', 'firstByte', 'InMode'),
121 ('short', 'byteCount', 'InMode')],
122 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
123
Jack Jansen1d8ede71996-01-08 23:47:31 +0000124 # GetPen and SetPt use a point-pointer as output-only:
125 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
126 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
127
128 # All others use it as input/output:
Guido van Rossume56db431995-03-19 22:49:50 +0000129 ([('Point', '*', 'OutMode')],
130 [('*', '*', 'InOutMode')]),
Jack Jansen54c8f7e1995-11-14 10:46:01 +0000131
132 # InsetRect, OffsetRect
133 ([('Rect', 'r', 'OutMode'),
134 ('short', 'dh', 'InMode'),
135 ('short', 'dv', 'InMode')],
136 [('Rect', 'r', 'InOutMode'),
137 ('short', 'dh', 'InMode'),
138 ('short', 'dv', 'InMode')]),
139
140 # MapRect
141 ([('Rect', 'r', 'OutMode'),
142 ('Rect_ptr', 'srcRect', 'InMode'),
143 ('Rect_ptr', 'dstRect', 'InMode')],
144 [('Rect', 'r', 'InOutMode'),
145 ('Rect_ptr', 'srcRect', 'InMode'),
146 ('Rect_ptr', 'dstRect', 'InMode')]),
Jack Jansen425e9eb1995-12-12 15:02:03 +0000147
148 # CopyBits and friends
149 ([('RgnHandle', 'maskRgn', 'InMode')],
150 [('OptRgnHandle', 'maskRgn', 'InMode')]),
Guido van Rossume56db431995-03-19 22:49:50 +0000151
152 ]
153
154if __name__ == "__main__":
155 main()