blob: 828fd540692193445e6cfbe9f6afe5733c92cba4 [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
Jack Jansenaaebdd62002-08-05 15:39:30 +00005from bgenlocations import TOOLBOXDIR, BGENDIR
Jack Jansen0c4d9471998-04-17 14:07:56 +00006sys.path.append(BGENDIR)
Jack Jansenae8a68f1995-06-06 12:55:40 +00007
Guido van Rossum17448e21995-01-30 11:53:55 +00008from scantools import Scanner
9
10LONG = "Dialogs"
11SHORT = "dlg"
12OBJECT = "DialogPtr"
13
14def main():
15 input = LONG + ".h"
16 output = SHORT + "gen.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000017 defsoutput = TOOLBOXDIR + LONG + ".py"
Guido van Rossum17448e21995-01-30 11:53:55 +000018 scanner = MyScanner(input, output, defsoutput)
19 scanner.scan()
20 scanner.close()
21 print "=== Done scanning and generating, now importing the generated code... ==="
22 exec "import " + SHORT + "support"
23 print "=== Done. It's up to you to compile it now! ==="
24
25class MyScanner(Scanner):
26
27 def destination(self, type, name, arglist):
28 classname = "Function"
29 listname = "functions"
30 if arglist:
31 t, n, m = arglist[0]
Jack Jansenae8a68f1995-06-06 12:55:40 +000032 if t in ("DialogPtr", "DialogRef") and m == "InMode":
Guido van Rossum17448e21995-01-30 11:53:55 +000033 classname = "Method"
34 listname = "methods"
35 return classname, listname
36
37 def makeblacklistnames(self):
38 return [
39 'InitDialogs',
40 'ErrorSound',
41 # Dialogs are disposed when the object is deleted
42 'CloseDialog',
43 'DisposDialog',
44 'DisposeDialog',
Guido van Rossum97842951995-02-19 15:59:49 +000045 'UpdtDialog',
46 'CouldAlert',
47 'FreeAlert',
48 'CouldDialog',
49 'FreeDialog',
Jack Jansenae8a68f1995-06-06 12:55:40 +000050 'GetStdFilterProc',
Jack Jansen1c4e6141998-04-21 15:23:55 +000051 'GetDialogParent',
Jack Jansena05ac601999-12-12 21:41:51 +000052## # Can't find these in the CW Pro 3 libraries
Jack Jansen1c4e6141998-04-21 15:23:55 +000053 'SetDialogMovableModal',
54 'GetDialogControlNotificationProc',
Jack Jansenbd008842001-11-05 16:16:39 +000055 'SetGrafPortOfDialog', # Funny, and probably not useful
Jack Jansen2168e9d2001-12-16 20:18:40 +000056 # Can't find these:
57 'CloseStandardSheet',
58 'RunStandardAlert',
Guido van Rossum17448e21995-01-30 11:53:55 +000059 ]
60
Jack Jansene79dc762000-06-02 21:35:07 +000061 def makegreylist(self):
62 return [
Jack Jansenf7d5aa62000-12-10 23:43:49 +000063 ('#if TARGET_API_MAC_CARBON', [
64 'InsertDialogItem',
65 'RemoveDialogItems',
66 'GetParamText',
Jack Jansen2168e9d2001-12-16 20:18:40 +000067 'CloseStandardSheet',
68 'RunStandardAlert',
Jack Jansene79dc762000-06-02 21:35:07 +000069 ])]
70
Guido van Rossum17448e21995-01-30 11:53:55 +000071 def makeblacklisttypes(self):
72 return [
Jack Jansen21f96871998-02-20 16:02:09 +000073 "AlertStdAlertParamPtr", # Too much work, for now
Jack Jansenf7d5aa62000-12-10 23:43:49 +000074 "AlertStdAlertParamRec", # ditto
75 "AlertStdAlertParamRec_ptr", # ditto
Jack Jansen2168e9d2001-12-16 20:18:40 +000076 "AlertStdCFStringAlertParamPtr", # ditto
77 "AlertStdCFStringAlertParamRec",
78 "AlertStdCFStringAlertParamRec_ptr",
Jack Jansen1c4e6141998-04-21 15:23:55 +000079 "QTModelessCallbackProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000080 ]
81
82 def makerepairinstructions(self):
83 return [
84 ([("Str255", "*", "InMode")],
85 [("*", "*", "OutMode")]),
86
87 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
88 [("InBuffer", "*", "*")]),
89
90 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
91 ("long", "*", "OutMode")],
92 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansen91a63981995-08-17 14:30:52 +000093
94 # GetDialogItem return handle is optional
95 ([("Handle", "item", "OutMode")],
96 [("OptHandle", "item", "OutMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000097
98 # NewDialog ETC.
99 ([("void", "*", "OutMode")],
100 [("NullStorage", "*", "InMode")]),
101
102 ([("DialogPtr", "*", "OutMode")],
103 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenae8a68f1995-06-06 12:55:40 +0000104 ([("DialogRef", "*", "OutMode")],
105 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000106 ([("WindowPtr", "*", "OutMode")],
107 [("ExistingWindowPtr", "*", "*")]),
108 ([("WindowPtr", "*", "ReturnMode")],
109 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +0000110 ]
111
Jack Jansena05ac601999-12-12 21:41:51 +0000112 def writeinitialdefs(self):
113 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
114
115
Guido van Rossum17448e21995-01-30 11:53:55 +0000116if __name__ == "__main__":
117 main()