blob: 2619d363e6e3f771f8d530af3708ed30c7d18217 [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...
78
Guido van Rossume56db431995-03-19 22:49:50 +000079 ]
80
81 def makeblacklisttypes(self):
82 return [
Jack Jansen69b43ed1997-08-15 14:35:54 +000083## 'CCrsrHandle',
84 'CIconHandle', # Obsolete
Guido van Rossume56db431995-03-19 22:49:50 +000085 'CQDProcs',
86 'CSpecArray',
Jack Jansen69b43ed1997-08-15 14:35:54 +000087## 'CTabHandle',
Guido van Rossume56db431995-03-19 22:49:50 +000088 'ColorComplementProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +000089 'ColorComplementUPP',
Guido van Rossume56db431995-03-19 22:49:50 +000090 'ColorSearchProcPtr',
Jack Jansenb81cf9d1995-06-06 13:08:40 +000091 'ColorSearchUPP',
Guido van Rossume56db431995-03-19 22:49:50 +000092 'ConstPatternParam',
Guido van Rossume56db431995-03-19 22:49:50 +000093 'DeviceLoopDrawingProcPtr',
94 'DeviceLoopFlags',
Jack Jansen3a50f8a1996-01-11 16:17:14 +000095## 'FontInfo',
Jack Jansen69b43ed1997-08-15 14:35:54 +000096## 'GDHandle',
Guido van Rossume56db431995-03-19 22:49:50 +000097 'GrafVerb',
98 'OpenCPicParams_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()