Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame^] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 3 | from scantools import Scanner |
| 4 | |
| 5 | LONG = "Events" |
| 6 | SHORT = "evt" |
| 7 | OBJECT = "NOTUSED" |
| 8 | |
| 9 | def main(): |
| 10 | input = LONG + ".h" |
| 11 | output = SHORT + "gen.py" |
| 12 | defsoutput = LONG + ".py" |
| 13 | scanner = MyScanner(input, output, defsoutput) |
| 14 | scanner.scan() |
| 15 | scanner.close() |
| 16 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 17 | exec "import " + SHORT + "support" |
| 18 | print "=== Done. It's up to you to compile it now! ===" |
| 19 | |
| 20 | class MyScanner(Scanner): |
| 21 | |
| 22 | def destination(self, type, name, arglist): |
| 23 | classname = "Function" |
| 24 | listname = "functions" |
| 25 | if arglist: |
| 26 | t, n, m = arglist[0] |
| 27 | # This is non-functional today |
| 28 | if t == OBJECT and m == "InMode": |
| 29 | classname = "Method" |
| 30 | listname = "methods" |
| 31 | return classname, listname |
| 32 | |
| 33 | def makeblacklistnames(self): |
| 34 | return [ |
| 35 | ] |
| 36 | |
| 37 | def makeblacklisttypes(self): |
| 38 | return [ |
| 39 | ] |
| 40 | |
| 41 | def makerepairinstructions(self): |
| 42 | return [ |
| 43 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], |
| 44 | [("InBuffer", "*", "*")]), |
| 45 | |
| 46 | ([("void", "*", "OutMode"), ("long", "*", "InMode"), |
| 47 | ("long", "*", "OutMode")], |
| 48 | [("VarVarOutBuffer", "*", "InOutMode")]), |
| 49 | |
| 50 | ([("void", "wStorage", "OutMode")], |
| 51 | [("NullStorage", "*", "InMode")]), |
| 52 | |
| 53 | # GetKeys |
| 54 | ([('KeyMap', 'theKeys', 'InMode')], |
| 55 | [('*', '*', 'OutMode')]), |
| 56 | ] |
| 57 | |
| 58 | if __name__ == "__main__": |
| 59 | main() |