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 | def main(): |
| 6 | input = "Windows.h" |
| 7 | output = "wingen.py" |
| 8 | defsoutput = "Windows.py" |
| 9 | scanner = MyScanner(input, output, defsoutput) |
| 10 | scanner.scan() |
| 11 | scanner.close() |
| 12 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 13 | import winsupport |
| 14 | print "=== Done. It's up to you to compile it now! ===" |
| 15 | |
| 16 | class MyScanner(Scanner): |
| 17 | |
| 18 | def destination(self, type, name, arglist): |
| 19 | classname = "Function" |
| 20 | listname = "functions" |
| 21 | if arglist: |
| 22 | t, n, m = arglist[0] |
| 23 | if t in ("WindowPtr", "WindowPeek") and m == "InMode": |
| 24 | classname = "Method" |
| 25 | listname = "methods" |
| 26 | return classname, listname |
| 27 | |
| 28 | def makeblacklistnames(self): |
| 29 | return [ |
| 30 | 'DisposeWindow', # Implied when the object is deleted |
| 31 | 'CloseWindow', |
| 32 | ] |
| 33 | |
| 34 | def makeblacklisttypes(self): |
| 35 | return [ |
| 36 | 'ProcPtr', |
| 37 | 'GrafPtr', |
| 38 | 'CGrafPtr', |
| 39 | 'RgnHandle', |
| 40 | 'PicHandle', |
| 41 | 'WCTabHandle', |
| 42 | 'AuxWinHandle', |
| 43 | 'PixPatHandle', |
| 44 | ] |
| 45 | |
| 46 | def makerepairinstructions(self): |
| 47 | return [ |
| 48 | |
| 49 | # GetWTitle |
| 50 | ([("Str255", "*", "InMode")], |
| 51 | [("*", "*", "OutMode")]), |
| 52 | |
| 53 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], |
| 54 | [("InBuffer", "*", "*")]), |
| 55 | |
| 56 | ([("void", "*", "OutMode"), ("long", "*", "InMode"), |
| 57 | ("long", "*", "OutMode")], |
| 58 | [("VarVarOutBuffer", "*", "InOutMode")]), |
| 59 | |
| 60 | ([("void", "wStorage", "OutMode")], |
| 61 | [("NullStorage", "*", "InMode")]), |
| 62 | |
| 63 | ([("WindowPtr", "*", "OutMode")], |
| 64 | [("ExistingWindowPtr", "*", "*")]), |
Guido van Rossum | ea39abd | 1995-02-28 09:49:02 +0000 | [diff] [blame] | 65 | |
| 66 | ([("WindowPtr", "FrontWindow", "ReturnMode")], |
| 67 | [("ExistingWindowPtr", "*", "*")]), |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 68 | ] |
| 69 | |
| 70 | if __name__ == "__main__": |
| 71 | main() |
Guido van Rossum | ea39abd | 1995-02-28 09:49:02 +0000 | [diff] [blame] | 72 | |