blob: a9d6fc4c8dcb021446d685e6b81620a088b69fb4 [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 [
60 ('#ifndef TARGET_API_MAC_CARBON', [
61 'SetGrafPortOfDialog',
62 ])]
63
Guido van Rossum17448e21995-01-30 11:53:55 +000064 def makeblacklisttypes(self):
65 return [
Jack Jansen21f96871998-02-20 16:02:09 +000066 "AlertStdAlertParamPtr", # Too much work, for now
Jack Jansen1c4e6141998-04-21 15:23:55 +000067 "QTModelessCallbackProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000068 ]
69
70 def makerepairinstructions(self):
71 return [
72 ([("Str255", "*", "InMode")],
73 [("*", "*", "OutMode")]),
74
75 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
76 [("InBuffer", "*", "*")]),
77
78 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
79 ("long", "*", "OutMode")],
80 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansen91a63981995-08-17 14:30:52 +000081
82 # GetDialogItem return handle is optional
83 ([("Handle", "item", "OutMode")],
84 [("OptHandle", "item", "OutMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000085
86 # NewDialog ETC.
87 ([("void", "*", "OutMode")],
88 [("NullStorage", "*", "InMode")]),
89
90 ([("DialogPtr", "*", "OutMode")],
91 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenae8a68f1995-06-06 12:55:40 +000092 ([("DialogRef", "*", "OutMode")],
93 [("ExistingDialogPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000094 ]
95
Jack Jansena05ac601999-12-12 21:41:51 +000096 def writeinitialdefs(self):
97 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
98
99
Guido van Rossum17448e21995-01-30 11:53:55 +0000100if __name__ == "__main__":
101 main()