blob: 6da7267ac4c9d00d3a76bcaa75a5834e3a37d9ed [file] [log] [blame]
Jack Jansen2aadb892001-07-13 20:56:52 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4import os
5BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6sys.path.append(BGENDIR)
7from scantools import Scanner_OSX
8from bgenlocations import TOOLBOXDIR
9
10LONG = "MacTextEditor"
11SHORT = "mlte"
12OBJECTS = ("TXNObject", "TXNFontMenuObject")
13# ADD object typenames here
14
15def main():
16 input = "MacTextEditor.h"
17 output = SHORT + "gen.py"
18 defsoutput = TOOLBOXDIR + LONG + ".py"
19 scanner = MyScanner(input, output, defsoutput)
20 scanner.scan()
21 scanner.gentypetest(SHORT+"typetest.py")
22 scanner.close()
23 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_OSX):
28
29 def destination(self, type, name, arglist):
30 classname = "Function"
31 listname = "functions"
32 if arglist:
33 t, n, m = arglist[0]
34 if t in OBJECTS and m == "InMode":
35 classname = "Method"
36 listname = t + "_methods"
37 return classname, listname
38
39 def writeinitialdefs(self):
Jack Jansenf0ded2f2001-07-14 14:00:50 +000040 self.defsfile.write("""
41def FOUR_CHAR_CODE(x): return x
42false = 0
43true = 1
44kTXNClearThisControl = 0xFFFFFFFF
45kTXNClearTheseFontFeatures = 0x80000000
46kTXNDontCareTypeSize = 0xFFFFFFFF
47kTXNDecrementTypeSize = 0x80000000
48kTXNUseCurrentSelection = 0xFFFFFFFF
49kTXNStartOffset = 0
50kTXNEndOffset = 0x7FFFFFFF
51MovieFileType = FOUR_CHAR_CODE('moov')
52""")
Jack Jansen2aadb892001-07-13 20:56:52 +000053
54 def makeblacklistnames(self):
55 return [
Jack Jansend4b83612001-07-13 22:27:20 +000056 "TXNGetFontDefaults", # Arg is too difficult
57 "TXNSetFontDefaults", # Arg is too difficult
58 "TXNInitTextension", # done manually
Jack Jansenf0ded2f2001-07-14 14:00:50 +000059
60 # Constants with funny definitions
61 "kTXNClearThisControl",
62 "kTXNClearTheseFontFeatures",
63 "kTXNDontCareTypeSize",
64 "kTXNDecrementTypeSize",
65 "kTXNUseCurrentSelection",
66 "kTXNStartOffset",
67 "kTXNEndOffset",
68 "kTXNQDFontNameAttributeSize",
69 "kTXNQDFontFamilyIDAttributeSize",
70 "kTXNQDFontSizeAttributeSize",
71 "kTXNQDFontStyleAttributeSize",
72 "kTXNQDFontColorAttributeSize",
73 "kTXNTextEncodingAttributeSize",
74 "status",
75 "justification",
Jack Jansen2aadb892001-07-13 20:56:52 +000076 ]
77
78 def makegreylist(self):
79 return []
80
81 def makeblacklisttypes(self):
82 return [
83 "TXNTab", # TBD
84 "TXNMargins", # TBD
85 "TXNControlData", #TBD
86 "TXNATSUIFeatures", #TBD
87 "TXNATSUIVariations", #TBD
88 "TXNAttributeData", #TBD
89 "TXNTypeAttributes", #TBD
90 "TXNMatchTextRecord", #TBD
91 "TXNBackground", #TBD
92 "UniChar", #TBD
93 "TXNFindUPP",
94 ]
95
96 def makerepairinstructions(self):
97 return [
Jack Jansend4b83612001-07-13 22:27:20 +000098 # TXNNewObject has a lot of optional parameters
99 ([("FSSpec_ptr", "iFileSpec", "InMode")],
100 [("OptFSSpecPtr", "*", "*")]),
101 ([("Rect", "iFrame", "OutMode")],
102 [("OptRectPtr", "*", "InMode")]),
103
104 # In UH 332 some of the "const" are missing for input parameters passed
105 # by reference. We fix that up here.
106 ([("EventRecord", "iEvent", "OutMode")],
107 [("EventRecord_ptr", "*", "InMode")]),
108 ([("FSSpec", "iFileSpecification", "OutMode")],
109 [("FSSpec_ptr", "*", "InMode")]),
110 ([("TXNMacOSPreferredFontDescription", "iFontDefaults", "OutMode")],
111 [("TXNMacOSPreferredFontDescription_ptr", "*", "InMode")]),
112
113 # In buffers are passed as void *
Jack Jansen2aadb892001-07-13 20:56:52 +0000114 ([("void", "*", "OutMode"), ("ByteCount", "*", "InMode")],
115 [("MlteInBuffer", "*", "InMode")]),
Jack Jansenf0ded2f2001-07-14 14:00:50 +0000116
117 # The AdjustCursor region handle is optional
118 ([("RgnHandle", "ioCursorRgn", "InMode")],
119 [("OptRgnHandle", "*", "*")])
Jack Jansen2aadb892001-07-13 20:56:52 +0000120 ]
121
122if __name__ == "__main__":
123 main()