Clarify portability and main program.
[python/dscho.git] / Mac / Modules / waste / wastescan.py
blob25f8d5d38168b6adf3b1f2c69a0d29849664f50a
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 import os
5 BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6 sys.path.append(BGENDIR)
7 from scantools import Scanner_PreUH3
8 from bgenlocations import MWERKSDIR, TOOLBOXDIR
10 WASTEDIR=":::::Waste 1.3 Distribution:WASTE C/C++ Headers:"
12 OBJECT = "TEHandle"
13 SHORT = "waste"
14 OBJECT = "WEReference"
15 OBJECT2 = "WEObjectReference"
17 def main():
18 input = WASTEDIR + "WASTE.h"
19 output = SHORT + "gen.py"
20 defsoutput = TOOLBOXDIR + "WASTEconst.py"
21 scanner = MyScanner(input, output, defsoutput)
22 scanner.scan()
23 ## scanner.gentypetest(SHORT+"typetest.py")
24 scanner.close()
25 print "=== Done scanning and generating, now importing the generated code... ==="
26 exec "import " + SHORT + "support"
27 print "=== Done. It's up to you to compile it now! ==="
29 class MyScanner(Scanner_PreUH3):
31 def destination(self, type, name, arglist):
32 classname = "Function"
33 listname = "functions"
34 if arglist:
35 t, n, m = arglist[-1]
36 # This is non-functional today
37 if t == OBJECT and m == "InMode":
38 classname = "Method"
39 listname = "methods"
40 else:
41 t, n, m = arglist[0]
42 if t == OBJECT2 and m == "InMode":
43 classname = "Method2"
44 listname = "methods2"
45 return classname, listname
47 def writeinitialdefs(self):
48 self.defsfile.write("kPascalStackBased = None # workaround for header parsing\n")
49 def makeblacklistnames(self):
50 return [
51 "WEDispose",
52 "WESetInfo", # Argument type unknown...
53 "WEGetInfo",
54 "WEVersion", # Unfortunately...
57 def makeblacklisttypes(self):
58 return [
59 "DragReference", # For now...
60 "UniversalProcPtr",
61 "WEFontIDToNameUPP",
62 "WEFontNameToIDUPP",
65 def makerepairinstructions(self):
66 return [
67 ([("void_ptr", "*", "InMode"), ("SInt32", "*", "InMode")],
68 [("InBuffer", "*", "*")]),
70 # WEContinuousStyle
71 ([("WEStyleMode", "mode", "OutMode"), ("TextStyle", "ts", "OutMode")],
72 [("WEStyleMode", "mode", "InOutMode"), ("TextStyle", "ts", "OutMode")]),
74 # WECopyRange
75 ([('Handle', 'hText', 'InMode'), ('StScrpHandle', 'hStyles', 'InMode'),
76 ('WESoupHandle', 'hSoup', 'InMode')],
77 [('OptHandle', 'hText', 'InMode'), ('OptStScrpHandle', 'hStyles', 'InMode'),
78 ('OptSoupHandle', 'hSoup', 'InMode')]),
80 # WEInsert
81 ([('StScrpHandle', 'hStyles', 'InMode'), ('WESoupHandle', 'hSoup', 'InMode')],
82 [('OptStScrpHandle', 'hStyles', 'InMode'), ('OptSoupHandle', 'hSoup', 'InMode')]),
84 # WEGetObjectOwner
85 ("WEGetObjectOwner",
86 [('WEReference', '*', 'ReturnMode')],
87 [('ExistingWEReference', '*', 'ReturnMode')])
91 if __name__ == "__main__":
92 main()