blob: bf37129b9e93a472ac3f4371f076f15f3d834b3a [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():
Tim Peters182b5ac2004-07-18 06:16:08 +000015 input = LONG + ".h"
16 output = SHORT + "gen.py"
17 defsoutput = TOOLBOXDIR + LONG + ".py"
18 scanner = MyScanner(input, output, defsoutput)
19 scanner.scan()
20 scanner.close()
21 print "=== Testing definitions output code ==="
Neal Norwitz01688022007-08-12 00:43:29 +000022 exec(open(defsoutput).read(), {}, {})
Tim Peters182b5ac2004-07-18 06:16:08 +000023 print "=== Done scanning and generating, now importing the generated code... ==="
24 exec "import " + SHORT + "support"
25 print "=== Done. It's up to you to compile it now! ==="
Guido van Rossum17448e21995-01-30 11:53:55 +000026
27class MyScanner(Scanner):
28
Tim Peters182b5ac2004-07-18 06:16:08 +000029 def destination(self, type, name, arglist):
30 classname = "Function"
31 listname = "functions"
32 if arglist:
33 t, n, m = arglist[0]
34 if t in ("DialogPtr", "DialogRef") and m == "InMode":
35 classname = "Method"
36 listname = "methods"
37 return classname, listname
Guido van Rossum17448e21995-01-30 11:53:55 +000038
Tim Peters182b5ac2004-07-18 06:16:08 +000039 def makeblacklistnames(self):
40 return [
41 'InitDialogs',
42 'ErrorSound',
43 # Dialogs are disposed when the object is deleted
44 'CloseDialog',
45 'DisposDialog',
46 'DisposeDialog',
47 'UpdtDialog',
48 'CouldAlert',
49 'FreeAlert',
50 'CouldDialog',
51 'FreeDialog',
52 'GetStdFilterProc',
53 'GetDialogParent',
54## # Can't find these in the CW Pro 3 libraries
55 'SetDialogMovableModal',
56 'GetDialogControlNotificationProc',
57 'SetGrafPortOfDialog', # Funny, and probably not useful
58 # Can't find these:
59 'CloseStandardSheet',
60 'RunStandardAlert',
61 ]
Guido van Rossum17448e21995-01-30 11:53:55 +000062
Tim Peters182b5ac2004-07-18 06:16:08 +000063 def makeblacklisttypes(self):
64 return [
65 "AlertStdAlertParamPtr", # Too much work, for now
66 "AlertStdAlertParamRec", # ditto
67 "AlertStdAlertParamRec_ptr", # ditto
68 "AlertStdCFStringAlertParamPtr", # ditto
69 "AlertStdCFStringAlertParamRec",
70 "AlertStdCFStringAlertParamRec_ptr",
71 "QTModelessCallbackProcPtr",
72 ]
Guido van Rossum17448e21995-01-30 11:53:55 +000073
Tim Peters182b5ac2004-07-18 06:16:08 +000074 def makerepairinstructions(self):
75 return [
76 ([("Str255", "*", "InMode")],
77 [("*", "*", "OutMode")]),
Jack Jansenf92ec2d2003-02-27 22:50:50 +000078
Tim Peters182b5ac2004-07-18 06:16:08 +000079 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
80 [("InBuffer", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000081
Tim Peters182b5ac2004-07-18 06:16:08 +000082 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
83 ("long", "*", "OutMode")],
84 [("VarVarOutBuffer", "*", "InOutMode")]),
85
86 # GetDialogItem return handle is optional
87 ([("Handle", "item", "OutMode")],
88 [("OptHandle", "item", "OutMode")]),
89
90 # NewDialog ETC.
91 ([("void", "*", "OutMode")],
92 [("NullStorage", "*", "InMode")]),
93
94 ([("DialogPtr", "*", "OutMode")],
95 [("ExistingDialogPtr", "*", "*")]),
96 ([("DialogRef", "*", "OutMode")],
97 [("ExistingDialogPtr", "*", "*")]),
98 ([("WindowPtr", "*", "OutMode")],
99 [("ExistingWindowPtr", "*", "*")]),
100 ([("WindowPtr", "*", "ReturnMode")],
101 [("ExistingWindowPtr", "*", "*")]),
102
103 # StdFilterProc
104 ([('EventRecord', 'event', 'OutMode'),
105 ('DialogItemIndex', 'itemHit', 'OutMode')],
106 [('EventRecord', 'event', 'InOutMode'),
107 ('DialogItemIndex', 'itemHit', 'InOutMode')])
108
109 ]
110
111 def writeinitialdefs(self):
112 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
Jack Jansena05ac601999-12-12 21:41:51 +0000113
114
Guido van Rossum17448e21995-01-30 11:53:55 +0000115if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +0000116 main()