blob: 770d4d21892141e519f55f112e2cb1f6b6c2c879 [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()
Jack Jansen87eea882002-08-15 21:48:16 +000021 print "=== Testing definitions output code ==="
22 execfile(defsoutput, {}, {})
Guido van Rossum17448e21995-01-30 11:53:55 +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! ==="
26
27class MyScanner(Scanner):
28
29 def destination(self, type, name, arglist):
30 classname = "Function"
31 listname = "functions"
32 if arglist:
33 t, n, m = arglist[0]
Jack Jansenae8a68f1995-06-06 12:55:40 +000034 if t in ("DialogPtr", "DialogRef") and m == "InMode":
Guido van Rossum17448e21995-01-30 11:53:55 +000035 classname = "Method"
36 listname = "methods"
37 return classname, listname
38
39 def makeblacklistnames(self):
40 return [
41 'InitDialogs',
42 'ErrorSound',
43 # Dialogs are disposed when the object is deleted
44 'CloseDialog',
45 'DisposDialog',
46 'DisposeDialog',
Guido van Rossum97842951995-02-19 15:59:49 +000047 'UpdtDialog',
48 'CouldAlert',
49 'FreeAlert',
50 'CouldDialog',
51 'FreeDialog',
Jack Jansenae8a68f1995-06-06 12:55:40 +000052 'GetStdFilterProc',
Jack Jansen1c4e6141998-04-21 15:23:55 +000053 'GetDialogParent',
Jack Jansena05ac601999-12-12 21:41:51 +000054## # Can't find these in the CW Pro 3 libraries
Jack Jansen1c4e6141998-04-21 15:23:55 +000055 'SetDialogMovableModal',
56 'GetDialogControlNotificationProc',
Jack Jansenbd008842001-11-05 16:16:39 +000057 'SetGrafPortOfDialog', # Funny, and probably not useful
Jack Jansen2168e9d2001-12-16 20:18:40 +000058 # Can't find these:
59 'CloseStandardSheet',
60 'RunStandardAlert',
Guido van Rossum17448e21995-01-30 11:53:55 +000061 ]
62
Jack Jansene79dc762000-06-02 21:35:07 +000063 def makegreylist(self):
64 return [
Jack Jansenf7d5aa62000-12-10 23:43:49 +000065 ('#if TARGET_API_MAC_CARBON', [
66 'InsertDialogItem',
67 'RemoveDialogItems',
68 'GetParamText',
Jack Jansen2168e9d2001-12-16 20:18:40 +000069 'CloseStandardSheet',
70 'RunStandardAlert',
Jack Jansene79dc762000-06-02 21:35:07 +000071 ])]
72
Guido van Rossum17448e21995-01-30 11:53:55 +000073 def makeblacklisttypes(self):
74 return [
Jack Jansen21f96871998-02-20 16:02:09 +000075 "AlertStdAlertParamPtr", # Too much work, for now
Jack Jansenf7d5aa62000-12-10 23:43:49 +000076 "AlertStdAlertParamRec", # ditto
77 "AlertStdAlertParamRec_ptr", # ditto
Jack Jansen2168e9d2001-12-16 20:18:40 +000078 "AlertStdCFStringAlertParamPtr", # ditto
79 "AlertStdCFStringAlertParamRec",
80 "AlertStdCFStringAlertParamRec_ptr",
Jack Jansen1c4e6141998-04-21 15:23:55 +000081 "QTModelessCallbackProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000082 ]
83
84 def makerepairinstructions(self):
85 return [
86 ([("Str255", "*", "InMode")],
87 [("*", "*", "OutMode")]),
88
89 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
90 [("InBuffer", "*", "*")]),
91
92 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
93 ("long", "*", "OutMode")],
94 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansen91a63981995-08-17 14:30:52 +000095
96 # GetDialogItem return handle is optional
97 ([("Handle", "item", "OutMode")],
98 [("OptHandle", "item", "OutMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000099
100 # NewDialog ETC.
101 ([("void", "*", "OutMode")],
102 [("NullStorage", "*", "InMode")]),
103
104 ([("DialogPtr", "*", "OutMode")],
105 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenae8a68f1995-06-06 12:55:40 +0000106 ([("DialogRef", "*", "OutMode")],
107 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000108 ([("WindowPtr", "*", "OutMode")],
109 [("ExistingWindowPtr", "*", "*")]),
110 ([("WindowPtr", "*", "ReturnMode")],
111 [("ExistingWindowPtr", "*", "*")]),
Guido van Rossum17448e21995-01-30 11:53:55 +0000112 ]
113
Jack Jansena05ac601999-12-12 21:41:51 +0000114 def writeinitialdefs(self):
115 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
116
117
Guido van Rossum17448e21995-01-30 11:53:55 +0000118if __name__ == "__main__":
119 main()