blob: b1f9a1477976a981155618d1c0b9a65843824061 [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',
Jack Jansenbd008842001-11-05 16:16:39 +000056 'SetGrafPortOfDialog', # Funny, and probably not useful
Jack Jansen2168e9d2001-12-16 20:18:40 +000057 # Can't find these:
58 'CloseStandardSheet',
59 'RunStandardAlert',
Guido van Rossum17448e21995-01-30 11:53:55 +000060 ]
61
Jack Jansene79dc762000-06-02 21:35:07 +000062 def makegreylist(self):
63 return [
Jack Jansenf7d5aa62000-12-10 23:43:49 +000064 ('#if TARGET_API_MAC_CARBON', [
65 'InsertDialogItem',
66 'RemoveDialogItems',
67 'GetParamText',
Jack Jansen2168e9d2001-12-16 20:18:40 +000068 'CloseStandardSheet',
69 'RunStandardAlert',
Jack Jansene79dc762000-06-02 21:35:07 +000070 ])]
71
Guido van Rossum17448e21995-01-30 11:53:55 +000072 def makeblacklisttypes(self):
73 return [
Jack Jansen21f96871998-02-20 16:02:09 +000074 "AlertStdAlertParamPtr", # Too much work, for now
Jack Jansenf7d5aa62000-12-10 23:43:49 +000075 "AlertStdAlertParamRec", # ditto
76 "AlertStdAlertParamRec_ptr", # ditto
Jack Jansen2168e9d2001-12-16 20:18:40 +000077 "AlertStdCFStringAlertParamPtr", # ditto
78 "AlertStdCFStringAlertParamRec",
79 "AlertStdCFStringAlertParamRec_ptr",
Jack Jansen1c4e6141998-04-21 15:23:55 +000080 "QTModelessCallbackProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000081 ]
82
83 def makerepairinstructions(self):
84 return [
85 ([("Str255", "*", "InMode")],
86 [("*", "*", "OutMode")]),
87
88 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
89 [("InBuffer", "*", "*")]),
90
91 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
92 ("long", "*", "OutMode")],
93 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansen91a63981995-08-17 14:30:52 +000094
95 # GetDialogItem return handle is optional
96 ([("Handle", "item", "OutMode")],
97 [("OptHandle", "item", "OutMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000098
99 # NewDialog ETC.
100 ([("void", "*", "OutMode")],
101 [("NullStorage", "*", "InMode")]),
102
103 ([("DialogPtr", "*", "OutMode")],
104 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenae8a68f1995-06-06 12:55:40 +0000105 ([("DialogRef", "*", "OutMode")],
106 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000107 ([("WindowPtr", "*", "OutMode")],
108 [("ExistingWindowPtr", "*", "*")]),
109 ([("WindowPtr", "*", "ReturnMode")],
110 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +0000111 ]
112
Jack Jansena05ac601999-12-12 21:41:51 +0000113 def writeinitialdefs(self):
114 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
115
116
Guido van Rossum17448e21995-01-30 11:53:55 +0000117if __name__ == "__main__":
118 main()