Jack Jansen | 2aadb89 | 2001-07-13 20:56:52 +0000 | [diff] [blame^] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 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_OSX |
| 8 | from bgenlocations import TOOLBOXDIR |
| 9 | |
| 10 | LONG = "MacTextEditor" |
| 11 | SHORT = "mlte" |
| 12 | OBJECTS = ("TXNObject", "TXNFontMenuObject") |
| 13 | # ADD object typenames here |
| 14 | |
| 15 | def 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 | |
| 27 | class 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): |
| 40 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 41 | |
| 42 | def makeblacklistnames(self): |
| 43 | return [ |
| 44 | ] |
| 45 | |
| 46 | def makegreylist(self): |
| 47 | return [] |
| 48 | |
| 49 | def makeblacklisttypes(self): |
| 50 | return [ |
| 51 | "TXNTab", # TBD |
| 52 | "TXNMargins", # TBD |
| 53 | "TXNControlData", #TBD |
| 54 | "TXNATSUIFeatures", #TBD |
| 55 | "TXNATSUIVariations", #TBD |
| 56 | "TXNAttributeData", #TBD |
| 57 | "TXNTypeAttributes", #TBD |
| 58 | "TXNMatchTextRecord", #TBD |
| 59 | "TXNBackground", #TBD |
| 60 | "UniChar", #TBD |
| 61 | "TXNFindUPP", |
| 62 | ] |
| 63 | |
| 64 | def makerepairinstructions(self): |
| 65 | return [ |
| 66 | ([("void", "*", "OutMode"), ("ByteCount", "*", "InMode")], |
| 67 | [("MlteInBuffer", "*", "InMode")]), |
| 68 | ] |
| 69 | |
| 70 | if __name__ == "__main__": |
| 71 | main() |