Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Mac / Modules / ae / aescan.py
blobb2174a88c17e43358d3f1f3639f29bf5cfa5beaa
1 # Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files.
2 # Then run aesupport to generate AEmodule.c.
3 # (Should learn how to tell the compiler to compile it as well.)
5 import sys
6 import os
7 import string
8 import regex
9 import regsub
10 import MacOS
12 BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
13 sys.path.append(BGENDIR)
14 from bgenlocations import TOOLBOXDIR
16 from scantools import Scanner
18 def main():
19 print "=== Scanning AERegistry.h for defines ==="
20 input = "AERegistry.h"
21 output = "@dummy-registry.py"
22 defsoutput = TOOLBOXDIR + "AERegistry.py"
23 scanner = AppleEventsRegScanner(input, output, defsoutput)
24 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"
32 defsoutput = TOOLBOXDIR + "AEObjects.py"
33 scanner = AppleEventsScanner(input, output, defsoutput)
34 scanner.scan()
35 scanner.close()
36 print "=== Scanning AEDataModel.h ==="
37 input = "AEDataModel.h"
38 output = "aedatamodelgen.py"
39 defsoutput = TOOLBOXDIR + "AEDataModel.py"
40 scanner = AppleEventsScanner(input, output, defsoutput)
42 scanner.scan()
43 scanner.close()
44 print "=== Scanning AppleEvents.h ==="
45 input = "AppleEvents.h"
46 output = "aegen.py"
47 defsoutput = TOOLBOXDIR + "AppleEvents.py"
48 scanner = AppleEventsRegScanner(input, output, defsoutput)
49 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 ==="
55 class AppleEventsScanner(Scanner):
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
69 def makeblacklistnames(self):
70 return [
71 "AEDisposeDesc",
72 # "AEGetEventHandler",
73 # Constants with funny definitions
74 "kAEDontDisposeOnResume",
75 "kAEUseStandardDispatch",
78 def makeblacklisttypes(self):
79 return [
80 "ProcPtr",
81 "AEArrayType",
82 "AECoercionHandlerUPP",
83 "UniversalProcPtr",
86 def makerepairinstructions(self):
87 return [
88 ([("Boolean", "isSysHandler", "InMode")],
89 [("AlwaysFalse", "*", "*")]),
91 ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
92 [("InBuffer", "*", "*")]),
94 ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
95 [("EventHandler", "*", "*")]),
97 ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
98 [("EventHandler", "*", "*")]),
100 ([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
101 [("EventHandler", "*", "*")]),
103 ([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
104 [("EventHandler", "*", "*")]),
106 ([("void", "*", "OutMode"), ("Size", "*", "InMode"),
107 ("Size", "*", "OutMode")],
108 [("VarVarOutBuffer", "*", "InOutMode")]),
110 ([("AppleEvent", "theAppleEvent", "OutMode")],
111 [("AppleEvent_ptr", "*", "InMode")]),
113 ([("AEDescList", "theAEDescList", "OutMode")],
114 [("AEDescList_ptr", "*", "InMode")]),
117 def writeinitialdefs(self):
118 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
120 class AppleEventsRegScanner(AppleEventsScanner):
121 def writeinitialdefs(self):
122 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
123 self.defsfile.write("from AEDataModel import *\n")
125 if __name__ == "__main__":
126 main()