blob: b744489c60bf22c7726222005642917f129aff8c [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files.
2# Then run aesupport to generate AEmodule.c.
Jack Jansen0c4d9471998-04-17 14:07:56 +00003# (Should learn how to tell the compiler to compile it as well.)
Guido van Rossum17448e21995-01-30 11:53:55 +00004
5import sys
6import os
7import string
8import regex
9import regsub
10import MacOS
Jack Jansen0c4d9471998-04-17 14:07:56 +000011
12BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
13sys.path.append(BGENDIR)
Jack Jansen46d9e791996-04-12 16:29:23 +000014from bgenlocations import TOOLBOXDIR
Guido van Rossum17448e21995-01-30 11:53:55 +000015
16from scantools import Scanner
17
18def main():
Jack Jansen74335681995-07-17 11:39:04 +000019 print "=== Scanning AERegistry.h for defines ==="
20 input = "AERegistry.h"
21 output = "@dummy-registry.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000022 defsoutput = TOOLBOXDIR + "AERegistry.py"
Jack Jansen21f96871998-02-20 16:02:09 +000023 scanner = AppleEventsRegScanner(input, output, defsoutput)
Jack Jansen74335681995-07-17 11:39:04 +000024 scanner.scan()
25 scanner.close()
26 print "=== Scanning AEObjects.h for defines ==="
27 # XXXX This isn't correct. We only scan AEObjects.h for defines, but there
28 # are some functions in there that are probably useful (the accessor stuff)
29 # once we start writing servers in python.
30 input = "AEObjects.h"
31 output = "@dummy-objects.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000032 defsoutput = TOOLBOXDIR + "AEObjects.py"
Jack Jansen74335681995-07-17 11:39:04 +000033 scanner = AppleEventsScanner(input, output, defsoutput)
34 scanner.scan()
35 scanner.close()
Jack Jansen21f96871998-02-20 16:02:09 +000036 print "=== Scanning AEDataModel.h ==="
37 input = "AEDataModel.h"
38 output = "aedatamodelgen.py"
39 defsoutput = TOOLBOXDIR + "AEDataModel.py"
40 scanner = AppleEventsScanner(input, output, defsoutput)
41
42 scanner.scan()
43 scanner.close()
44 print "=== Scanning AppleEvents.h ==="
Guido van Rossum17448e21995-01-30 11:53:55 +000045 input = "AppleEvents.h"
46 output = "aegen.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000047 defsoutput = TOOLBOXDIR + "AppleEvents.py"
Jack Jansen21f96871998-02-20 16:02:09 +000048 scanner = AppleEventsRegScanner(input, output, defsoutput)
Guido van Rossum17448e21995-01-30 11:53:55 +000049 scanner.scan()
50 scanner.close()
51 print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
52 import aesupport
53 print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ==="
54
55class AppleEventsScanner(Scanner):
56
57 def destination(self, type, name, arglist):
58 classname = "AEFunction"
59 listname = "functions"
60 if arglist:
61 t, n, m = arglist[0]
62 if t[-4:] == "_ptr" and m == "InMode" and \
63 t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList",
64 "AERecord", "AppleEvent"):
65 classname = "AEMethod"
66 listname = "aedescmethods"
67 return classname, listname
68
69 def makeblacklistnames(self):
70 return [
71 "AEDisposeDesc",
Jack Jansen50501991995-07-29 13:58:41 +000072# "AEGetEventHandler",
Jack Jansenf7d5aa62000-12-10 23:43:49 +000073 "AEGetDescData", # Use object.data
74 "AEGetSpecialHandler",
Jack Jansenb1b78d81999-12-14 15:47:01 +000075 # Constants with funny definitions
76 "kAEDontDisposeOnResume",
77 "kAEUseStandardDispatch",
Guido van Rossum17448e21995-01-30 11:53:55 +000078 ]
79
Jack Jansenf7d5aa62000-12-10 23:43:49 +000080 def makegreylist(self):
81 return [
82 ('#if TARGET_API_MAC_CARBON', [
83 'AEGetDescDataSize',
84 'AEReplaceDescData',
85 ])]
Guido van Rossum17448e21995-01-30 11:53:55 +000086 def makeblacklisttypes(self):
87 return [
88 "ProcPtr",
89 "AEArrayType",
Jack Jansenc7cfb951995-06-05 22:34:12 +000090 "AECoercionHandlerUPP",
91 "UniversalProcPtr",
Guido van Rossum17448e21995-01-30 11:53:55 +000092 ]
93
94 def makerepairinstructions(self):
95 return [
96 ([("Boolean", "isSysHandler", "InMode")],
97 [("AlwaysFalse", "*", "*")]),
98
99 ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
100 [("InBuffer", "*", "*")]),
101
102 ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
103 [("EventHandler", "*", "*")]),
104
105 ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
106 [("EventHandler", "*", "*")]),
107
Jack Jansen50501991995-07-29 13:58:41 +0000108 ([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
109 [("EventHandler", "*", "*")]),
110
111 ([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
112 [("EventHandler", "*", "*")]),
113
Guido van Rossum17448e21995-01-30 11:53:55 +0000114 ([("void", "*", "OutMode"), ("Size", "*", "InMode"),
115 ("Size", "*", "OutMode")],
116 [("VarVarOutBuffer", "*", "InOutMode")]),
Jack Jansenc7cfb951995-06-05 22:34:12 +0000117
118 ([("AppleEvent", "theAppleEvent", "OutMode")],
119 [("AppleEvent_ptr", "*", "InMode")]),
Jack Jansen74335681995-07-17 11:39:04 +0000120
121 ([("AEDescList", "theAEDescList", "OutMode")],
122 [("AEDescList_ptr", "*", "InMode")]),
Guido van Rossum17448e21995-01-30 11:53:55 +0000123 ]
124
Jack Jansen21f96871998-02-20 16:02:09 +0000125 def writeinitialdefs(self):
126 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
127
128class AppleEventsRegScanner(AppleEventsScanner):
129 def writeinitialdefs(self):
130 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
131 self.defsfile.write("from AEDataModel import *\n")
132
Guido van Rossum17448e21995-01-30 11:53:55 +0000133if __name__ == "__main__":
134 main()