blob: 3710d5d00091adef6b60688f5229cb3ac99373d2 [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
63 def makeblacklisttypes(self):
64 return [
Jack Jansen21f96871998-02-20 16:02:09 +000065 "AlertStdAlertParamPtr", # Too much work, for now
Jack Jansenf7d5aa62000-12-10 23:43:49 +000066 "AlertStdAlertParamRec", # ditto
67 "AlertStdAlertParamRec_ptr", # ditto
Jack Jansen2168e9d2001-12-16 20:18:40 +000068 "AlertStdCFStringAlertParamPtr", # ditto
69 "AlertStdCFStringAlertParamRec",
70 "AlertStdCFStringAlertParamRec_ptr",
Jack Jansen1c4e6141998-04-21 15:23:55 +000071 "QTModelessCallbackProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000072 ]
73
74 def makerepairinstructions(self):
75 return [
76 ([("Str255", "*", "InMode")],
77 [("*", "*", "OutMode")]),
78
79 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
80 [("InBuffer", "*", "*")]),
81
82 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
83 ("long", "*", "OutMode")],
84 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansen91a63981995-08-17 14:30:52 +000085
86 # GetDialogItem return handle is optional
87 ([("Handle", "item", "OutMode")],
88 [("OptHandle", "item", "OutMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +000089
90 # NewDialog ETC.
91 ([("void", "*", "OutMode")],
92 [("NullStorage", "*", "InMode")]),
93
94 ([("DialogPtr", "*", "OutMode")],
95 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenae8a68f1995-06-06 12:55:40 +000096 ([("DialogRef", "*", "OutMode")],
97 [("ExistingDialogPtr", "*", "*")]),
Jack Jansenb8c4c7b2000-08-25 22:25:54 +000098 ([("WindowPtr", "*", "OutMode")],
99 [("ExistingWindowPtr", "*", "*")]),
100 ([("WindowPtr", "*", "ReturnMode")],
101 [("ExistingWindowPtr", "*", "*")]),
Jack Jansenf92ec2d2003-02-27 22:50:50 +0000102
103 # StdFilterProc
104 ([('EventRecord', 'event', 'OutMode'),
105 ('DialogItemIndex', 'itemHit', 'OutMode')],
106 [('EventRecord', 'event', 'InOutMode'),
107 ('DialogItemIndex', 'itemHit', 'InOutMode')])
108
Guido van Rossum17448e21995-01-30 11:53:55 +0000109 ]
110
Jack Jansena05ac601999-12-12 21:41:51 +0000111 def writeinitialdefs(self):
112 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
113
114
Guido van Rossum17448e21995-01-30 11:53:55 +0000115if __name__ == "__main__":
116 main()