blob: f15fb168cc04e9aecfd5bd57ed74d6c9bbd11c89 [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',
40 ]
41
42 def makeblacklisttypes(self):
43 return [
44 'ProcPtr',
Jack Jansenb7abb181995-11-15 15:18:47 +000045 'DragGrayRgnUPP',
Guido van Rossum17448e21995-01-30 11:53:55 +000046 ]
47
48 def makerepairinstructions(self):
49 return [
50
51 # GetWTitle
52 ([("Str255", "*", "InMode")],
53 [("*", "*", "OutMode")]),
54
55 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
56 [("InBuffer", "*", "*")]),
57
58 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
59 ("long", "*", "OutMode")],
60 [("VarVarOutBuffer", "*", "InOutMode")]),
61
62 ([("void", "wStorage", "OutMode")],
63 [("NullStorage", "*", "InMode")]),
64
65 ([("WindowPtr", "*", "OutMode")],
66 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +000067 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
68 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossumea39abd1995-02-28 09:49:02 +000069
70 ([("WindowPtr", "FrontWindow", "ReturnMode")],
71 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +000072 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
73 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000074 ]
75
76if __name__ == "__main__":
77 main()
Guido van Rossumea39abd1995-02-28 09:49:02 +000078