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