blob: d9ca18b3d5311c4fc0c93305614c6d25daa0ff26 [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',
Guido van Rossum17448e21995-01-30 11:53:55 +000044 ]
45
46 def makeblacklisttypes(self):
47 return [
48 'ProcPtr',
Jack Jansenb7abb181995-11-15 15:18:47 +000049 'DragGrayRgnUPP',
Jack Jansena05ac601999-12-12 21:41:51 +000050 'Collection', # For now, to be done later
51 'DragReference', # Ditto, dragmodule doesn't export it yet.
Guido van Rossum17448e21995-01-30 11:53:55 +000052 ]
53
54 def makerepairinstructions(self):
55 return [
56
57 # GetWTitle
58 ([("Str255", "*", "InMode")],
59 [("*", "*", "OutMode")]),
60
61 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
62 [("InBuffer", "*", "*")]),
63
64 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
65 ("long", "*", "OutMode")],
66 [("VarVarOutBuffer", "*", "InOutMode")]),
67
68 ([("void", "wStorage", "OutMode")],
69 [("NullStorage", "*", "InMode")]),
70
71 ([("WindowPtr", "*", "OutMode")],
72 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +000073 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
74 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossumea39abd1995-02-28 09:49:02 +000075
76 ([("WindowPtr", "FrontWindow", "ReturnMode")],
77 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +000078 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
79 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000080 ]
81
82if __name__ == "__main__":
83 main()
Guido van Rossumea39abd1995-02-28 09:49:02 +000084