blob: 549d0b3b2a6d17098c1f158114784f335dd3dc14 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +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)
Jack Jansenae8a68f1995-06-06 12:55:40 +00007
Guido van Rossum17448e21995-01-30 11:53:55 +00008from scantools import Scanner
Jack Jansen46d9e791996-04-12 16:29:23 +00009from bgenlocations import TOOLBOXDIR
Guido van Rossum17448e21995-01-30 11:53:55 +000010
11LONG = "Dialogs"
12SHORT = "dlg"
13OBJECT = "DialogPtr"
14
15def main():
16 input = LONG + ".h"
17 output = SHORT + "gen.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000018 defsoutput = TOOLBOXDIR + LONG + ".py"
Guido van Rossum17448e21995-01-30 11:53:55 +000019 scanner = MyScanner(input, output, defsoutput)
20 scanner.scan()
21 scanner.close()
22 print "=== Done scanning and generating, now importing the generated code... ==="
23 exec "import " + SHORT + "support"
24 print "=== Done. It's up to you to compile it now! ==="
25
26class MyScanner(Scanner):
27
28 def destination(self, type, name, arglist):
29 classname = "Function"
30 listname = "functions"
31 if arglist:
32 t, n, m = arglist[0]
Jack Jansenae8a68f1995-06-06 12:55:40 +000033 if t in ("DialogPtr", "DialogRef") and m == "InMode":
Guido van Rossum17448e21995-01-30 11:53:55 +000034 classname = "Method"
35 listname = "methods"
36 return classname, listname
37
38 def makeblacklistnames(self):
39 return [
40 'InitDialogs',
41 'ErrorSound',
42 # Dialogs are disposed when the object is deleted
43 'CloseDialog',
44 'DisposDialog',
45 'DisposeDialog',
Guido van Rossum97842951995-02-19 15:59:49 +000046 'UpdtDialog',
47 'CouldAlert',
48 'FreeAlert',
49 'CouldDialog',
50 'FreeDialog',
Jack Jansenae8a68f1995-06-06 12:55:40 +000051 'GetStdFilterProc',
Jack Jansen1c4e6141998-04-21 15:23:55 +000052 'GetDialogParent',
Jack Jansena05ac601999-12-12 21:41:51 +000053## # Can't find these in the CW Pro 3 libraries
Jack Jansen1c4e6141998-04-21 15:23:55 +000054 'SetDialogMovableModal',
55 'GetDialogControlNotificationProc',
Guido van Rossum17448e21995-01-30 11:53:55 +000056 ]
57
Jack Jansene79dc762000-06-02 21:35:07 +000058 def makegreylist(self):
59 return [
Jack Jansen74a1e632000-07-14 22:37:27 +000060 ('#if !TARGET_API_MAC_CARBON', [
Jack Jansene79dc762000-06-02 21:35:07 +000061 'SetGrafPortOfDialog',
Jack Jansenf7d5aa62000-12-10 23:43:49 +000062 ]),
63 ('#if TARGET_API_MAC_CARBON', [
64 'InsertDialogItem',
65 'RemoveDialogItems',
66 'GetParamText',
Jack Jansene79dc762000-06-02 21:35:07 +000067 ])]
68
Guido van Rossum17448e21995-01-30 11:53:55 +000069 def makeblacklisttypes(self):
70 return [
Jack Jansen21f96871998-02-20 16:02:09 +000071 "AlertStdAlertParamPtr", # Too much work, for now
Jack Jansenf7d5aa62000-12-10 23:43:49 +000072 "AlertStdAlertParamRec", # ditto
73 "AlertStdAlertParamRec_ptr", # ditto
Jack Jansen1c4e6141998-04-21 15:23:55 +000074 "QTModelessCallbackProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000075 ]
76
77 def makerepairinstructions(self):
78 return [
79 ([("Str255", "*", "InMode")],
80 [("*", "*", "OutMode")]),
81
82 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
83 [("InBuffer", "*", "*")]),
84
85 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
86 ("long", "*", "OutMode")],
87 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansen91a63981995-08-17 14:30:52 +000088
89 # GetDialogItem return handle is optional
90 ([("Handle", "item", "OutMode")],
91 [("OptHandle", "item", "OutMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000092
93 # NewDialog ETC.
94 ([("void", "*", "OutMode")],
95 [("NullStorage", "*", "InMode")]),
96
97 ([("DialogPtr", "*", "OutMode")],
98 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenae8a68f1995-06-06 12:55:40 +000099 ([("DialogRef", "*", "OutMode")],
100 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000101 ([("WindowPtr", "*", "OutMode")],
102 [("ExistingWindowPtr", "*", "*")]),
103 ([("WindowPtr", "*", "ReturnMode")],
104 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +0000105 ]
106
Jack Jansena05ac601999-12-12 21:41:51 +0000107 def writeinitialdefs(self):
108 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
109
110
Guido van Rossum17448e21995-01-30 11:53:55 +0000111if __name__ == "__main__":
112 main()