1 | # Scan an Apple header file, generating a Python file of generator calls.
|
---|
2 |
|
---|
3 | import sys
|
---|
4 | from bgenlocations import TOOLBOXDIR, BGENDIR
|
---|
5 | sys.path.append(BGENDIR)
|
---|
6 |
|
---|
7 | from scantools import Scanner
|
---|
8 |
|
---|
9 | LONG = "Dialogs"
|
---|
10 | SHORT = "dlg"
|
---|
11 | OBJECT = "DialogPtr"
|
---|
12 |
|
---|
13 | def main():
|
---|
14 | input = LONG + ".h"
|
---|
15 | output = SHORT + "gen.py"
|
---|
16 | defsoutput = TOOLBOXDIR + LONG + ".py"
|
---|
17 | scanner = MyScanner(input, output, defsoutput)
|
---|
18 | scanner.scan()
|
---|
19 | scanner.close()
|
---|
20 | print "=== Testing definitions output code ==="
|
---|
21 | execfile(defsoutput, {}, {})
|
---|
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 |
|
---|
26 | class 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]
|
---|
33 | if t in ("DialogPtr", "DialogRef") and m == "InMode":
|
---|
34 | 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',
|
---|
46 | 'UpdtDialog',
|
---|
47 | 'CouldAlert',
|
---|
48 | 'FreeAlert',
|
---|
49 | 'CouldDialog',
|
---|
50 | 'FreeDialog',
|
---|
51 | 'GetStdFilterProc',
|
---|
52 | 'GetDialogParent',
|
---|
53 | ## # Can't find these in the CW Pro 3 libraries
|
---|
54 | 'SetDialogMovableModal',
|
---|
55 | 'GetDialogControlNotificationProc',
|
---|
56 | 'SetGrafPortOfDialog', # Funny, and probably not useful
|
---|
57 | # Can't find these:
|
---|
58 | 'CloseStandardSheet',
|
---|
59 | 'RunStandardAlert',
|
---|
60 | ]
|
---|
61 |
|
---|
62 | def makeblacklisttypes(self):
|
---|
63 | return [
|
---|
64 | "AlertStdAlertParamPtr", # Too much work, for now
|
---|
65 | "AlertStdAlertParamRec", # ditto
|
---|
66 | "AlertStdAlertParamRec_ptr", # ditto
|
---|
67 | "AlertStdCFStringAlertParamPtr", # ditto
|
---|
68 | "AlertStdCFStringAlertParamRec",
|
---|
69 | "AlertStdCFStringAlertParamRec_ptr",
|
---|
70 | "QTModelessCallbackProcPtr",
|
---|
71 | ]
|
---|
72 |
|
---|
73 | def makerepairinstructions(self):
|
---|
74 | return [
|
---|
75 | ([("Str255", "*", "InMode")],
|
---|
76 | [("*", "*", "OutMode")]),
|
---|
77 |
|
---|
78 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
|
---|
79 | [("InBuffer", "*", "*")]),
|
---|
80 |
|
---|
81 | ([("void", "*", "OutMode"), ("long", "*", "InMode"),
|
---|
82 | ("long", "*", "OutMode")],
|
---|
83 | [("VarVarOutBuffer", "*", "InOutMode")]),
|
---|
84 |
|
---|
85 | # GetDialogItem return handle is optional
|
---|
86 | ([("Handle", "item", "OutMode")],
|
---|
87 | [("OptHandle", "item", "OutMode")]),
|
---|
88 |
|
---|
89 | # NewDialog ETC.
|
---|
90 | ([("void", "*", "OutMode")],
|
---|
91 | [("NullStorage", "*", "InMode")]),
|
---|
92 |
|
---|
93 | ([("DialogPtr", "*", "OutMode")],
|
---|
94 | [("ExistingDialogPtr", "*", "*")]),
|
---|
95 | ([("DialogRef", "*", "OutMode")],
|
---|
96 | [("ExistingDialogPtr", "*", "*")]),
|
---|
97 | ([("WindowPtr", "*", "OutMode")],
|
---|
98 | [("ExistingWindowPtr", "*", "*")]),
|
---|
99 | ([("WindowPtr", "*", "ReturnMode")],
|
---|
100 | [("ExistingWindowPtr", "*", "*")]),
|
---|
101 |
|
---|
102 | # StdFilterProc
|
---|
103 | ([('EventRecord', 'event', 'OutMode'),
|
---|
104 | ('DialogItemIndex', 'itemHit', 'OutMode')],
|
---|
105 | [('EventRecord', 'event', 'InOutMode'),
|
---|
106 | ('DialogItemIndex', 'itemHit', 'InOutMode')])
|
---|
107 |
|
---|
108 | ]
|
---|
109 |
|
---|
110 | def writeinitialdefs(self):
|
---|
111 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
|
---|
112 |
|
---|
113 |
|
---|
114 | if __name__ == "__main__":
|
---|
115 | main()
|
---|