blob: b0f0fb3021919ba48dfc4f2537f2fbfae25a0b4b [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# Scan an Apple header file, generating a Python file of generator calls.
Jack Jansen0c4d9471998-04-17 14:07:56 +00002import sys
3import os
4BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
5sys.path.append(BGENDIR)
Jack Jansen46d9e791996-04-12 16:29:23 +00006from bgenlocations import TOOLBOXDIR
Guido van Rossum17448e21995-01-30 11:53:55 +00007
8from scantools import Scanner
9
10def main():
Jack Jansen21f96871998-02-20 16:02:09 +000011 input = "MacWindows.h"
Guido van Rossum17448e21995-01-30 11:53:55 +000012 output = "wingen.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000013 defsoutput = TOOLBOXDIR + "Windows.py"
Guido van Rossum17448e21995-01-30 11:53:55 +000014 scanner = MyScanner(input, output, defsoutput)
15 scanner.scan()
16 scanner.close()
17 print "=== Done scanning and generating, now importing the generated code... ==="
18 import winsupport
19 print "=== Done. It's up to you to compile it now! ==="
20
21class MyScanner(Scanner):
22
23 def destination(self, type, name, arglist):
24 classname = "Function"
25 listname = "functions"
26 if arglist:
27 t, n, m = arglist[0]
Jack Jansenb81cf9d1995-06-06 13:08:40 +000028 if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
Guido van Rossum17448e21995-01-30 11:53:55 +000029 classname = "Method"
30 listname = "methods"
31 return classname, listname
32
Jack Jansen21f96871998-02-20 16:02:09 +000033 def writeinitialdefs(self):
34 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
35
Guido van Rossum17448e21995-01-30 11:53:55 +000036 def makeblacklistnames(self):
37 return [
38 'DisposeWindow', # Implied when the object is deleted
39 'CloseWindow',
Jack Jansena05ac601999-12-12 21:41:51 +000040 'SetWindowProperty', # For the moment
41 'GetWindowProperty',
42 'GetWindowPropertySize',
43 'RemoveWindowProperty',
Jack Jansene79dc762000-06-02 21:35:07 +000044 'MacCloseWindow',
Jack Jansenb1b78d81999-12-14 15:47:01 +000045 # Constants with funny definitions
46 'kMouseUpOutOfSlop',
Guido van Rossum17448e21995-01-30 11:53:55 +000047 ]
Jack Jansene79dc762000-06-02 21:35:07 +000048
49 def makegreylist(self):
50 return [
51 ('#ifndef TARGET_API_MAC_CARBON', [
52 'GetAuxWin',
53 'GetWindowDataHandle',
54 'SaveOld',
55 'DrawNew',
56 'SetWinColor',
57 'SetDeskCPat',
58 'InitWindows',
59 'InitFloatingWindows',
60 'GetWMgrPort',
61 'GetCWMgrPort',
62 'ValidRgn', # Use versions with Window in their name
63 'ValidRect',
64 'InvalRgn',
65 'InvalRect',
66 ]),
67 ('#ifndef TARGET_API_MAC_CARBON_NOTYET', [
68 'IsValidWindowPtr',
69 ])]
70
Guido van Rossum17448e21995-01-30 11:53:55 +000071 def makeblacklisttypes(self):
72 return [
73 'ProcPtr',
Jack Jansenb7abb181995-11-15 15:18:47 +000074 'DragGrayRgnUPP',
Jack Jansena05ac601999-12-12 21:41:51 +000075 'Collection', # For now, to be done later
76 'DragReference', # Ditto, dragmodule doesn't export it yet.
Guido van Rossum17448e21995-01-30 11:53:55 +000077 ]
78
79 def makerepairinstructions(self):
80 return [
81
82 # GetWTitle
83 ([("Str255", "*", "InMode")],
84 [("*", "*", "OutMode")]),
85
86 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
87 [("InBuffer", "*", "*")]),
88
89 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
90 ("long", "*", "OutMode")],
91 [("VarVarOutBuffer", "*", "InOutMode")]),
92
93 ([("void", "wStorage", "OutMode")],
94 [("NullStorage", "*", "InMode")]),
95
96 ([("WindowPtr", "*", "OutMode")],
97 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +000098 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
99 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossumea39abd1995-02-28 09:49:02 +0000100
101 ([("WindowPtr", "FrontWindow", "ReturnMode")],
102 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000103 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
104 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +0000105 ]
106
107if __name__ == "__main__":
108 main()
Guido van Rossumea39abd1995-02-28 09:49:02 +0000109