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 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 3 | import addpack |
| 4 | addpack.addpack(':Tools:bgen:bgen') |
| 5 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 6 | from scantools import Scanner |
| 7 | |
| 8 | LONG = "Dialogs" |
| 9 | SHORT = "dlg" |
| 10 | OBJECT = "DialogPtr" |
| 11 | |
| 12 | def main(): |
| 13 | input = LONG + ".h" |
| 14 | output = SHORT + "gen.py" |
| 15 | defsoutput = LONG + ".py" |
| 16 | scanner = MyScanner(input, output, defsoutput) |
| 17 | scanner.scan() |
| 18 | scanner.close() |
| 19 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 20 | exec "import " + SHORT + "support" |
| 21 | print "=== Done. It's up to you to compile it now! ===" |
| 22 | |
| 23 | class MyScanner(Scanner): |
| 24 | |
| 25 | def destination(self, type, name, arglist): |
| 26 | classname = "Function" |
| 27 | listname = "functions" |
| 28 | if arglist: |
| 29 | t, n, m = arglist[0] |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 30 | if t in ("DialogPtr", "DialogRef") and m == "InMode": |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 31 | classname = "Method" |
| 32 | listname = "methods" |
| 33 | return classname, listname |
| 34 | |
| 35 | def makeblacklistnames(self): |
| 36 | return [ |
| 37 | 'InitDialogs', |
| 38 | 'ErrorSound', |
| 39 | # Dialogs are disposed when the object is deleted |
| 40 | 'CloseDialog', |
| 41 | 'DisposDialog', |
| 42 | 'DisposeDialog', |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 43 | 'UpdtDialog', |
| 44 | 'CouldAlert', |
| 45 | 'FreeAlert', |
| 46 | 'CouldDialog', |
| 47 | 'FreeDialog', |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 48 | 'GetStdFilterProc', |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 49 | ] |
| 50 | |
| 51 | def makeblacklisttypes(self): |
| 52 | return [ |
| 53 | ] |
| 54 | |
| 55 | def makerepairinstructions(self): |
| 56 | return [ |
| 57 | ([("Str255", "*", "InMode")], |
| 58 | [("*", "*", "OutMode")]), |
| 59 | |
| 60 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], |
| 61 | [("InBuffer", "*", "*")]), |
| 62 | |
| 63 | ([("void", "*", "OutMode"), ("long", "*", "InMode"), |
| 64 | ("long", "*", "OutMode")], |
| 65 | [("VarVarOutBuffer", "*", "InOutMode")]), |
| 66 | |
| 67 | # NewDialog ETC. |
| 68 | ([("void", "*", "OutMode")], |
| 69 | [("NullStorage", "*", "InMode")]), |
| 70 | |
| 71 | ([("DialogPtr", "*", "OutMode")], |
| 72 | [("ExistingDialogPtr", "*", "*")]), |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 73 | ([("DialogRef", "*", "OutMode")], |
| 74 | [("ExistingDialogPtr", "*", "*")]), |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 75 | ] |
| 76 | |
| 77 | if __name__ == "__main__": |
| 78 | main() |