Jack Jansen | 8a452d6 | 1996-04-10 14:41:08 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 3 | import addpack |
| 4 | addpack.addpack(':tools:bgen:bgen') |
| 5 | from scantools import Scanner |
| 6 | |
| 7 | LONG = "TextEdit" |
| 8 | SHORT = "te" |
| 9 | OBJECT = "TEHandle" |
| 10 | |
| 11 | def main(): |
| 12 | input = LONG + ".h" |
| 13 | output = SHORT + "gen.py" |
| 14 | defsoutput = LONG + ".py" |
| 15 | scanner = MyScanner(input, output, defsoutput) |
| 16 | scanner.scan() |
| 17 | scanner.close() |
| 18 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 19 | exec "import " + SHORT + "support" |
| 20 | print "=== Done. It's up to you to compile it now! ===" |
| 21 | |
| 22 | class MyScanner(Scanner): |
| 23 | |
| 24 | def destination(self, type, name, arglist): |
| 25 | classname = "Function" |
| 26 | listname = "functions" |
| 27 | if arglist: |
| 28 | t, n, m = arglist[-1] |
| 29 | # This is non-functional today |
| 30 | if t == OBJECT and m == "InMode": |
| 31 | classname = "Method" |
| 32 | listname = "methods" |
| 33 | return classname, listname |
| 34 | |
| 35 | def makeblacklistnames(self): |
| 36 | return [ |
| 37 | "TEDispose", |
| 38 | "TEInit", |
| 39 | "TEGetHiliteRgn", |
| 40 | ] |
| 41 | |
| 42 | def makeblacklisttypes(self): |
| 43 | return [ |
| 44 | "TEClickLoopUPP", |
| 45 | "UniversalProcPtr", |
| 46 | "WordBreakUPP" |
| 47 | ] |
| 48 | |
| 49 | def makerepairinstructions(self): |
| 50 | return [ |
| 51 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], |
| 52 | [("InBuffer", "*", "*")]), |
| 53 | |
| 54 | # TEContinuousStyle |
| 55 | ([("short", "mode", "OutMode"), ("TextStyle", "aStyle", "OutMode")], |
| 56 | [("short", "mode", "InOutMode"), ("TextStyle", "aStyle", "InOutMode")]) |
| 57 | ] |
| 58 | |
| 59 | if __name__ == "__main__": |
| 60 | main() |