Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | import sys |
| 3 | import os |
Jack Jansen | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame] | 4 | from bgenlocations import TOOLBOXDIR, BGENDIR |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 5 | sys.path.append(BGENDIR) |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 6 | |
| 7 | from scantools import Scanner |
| 8 | |
| 9 | def main(): |
| 10 | input = "QDOffscreen.h" |
| 11 | output = "qdoffsgen.py" |
| 12 | defsoutput = TOOLBOXDIR + "QDOffscreen.py" |
| 13 | scanner = MyScanner(input, output, defsoutput) |
| 14 | scanner.scan() |
| 15 | scanner.close() |
Jack Jansen | 87eea88 | 2002-08-15 21:48:16 +0000 | [diff] [blame] | 16 | print "=== Testing definitions output code ===" |
| 17 | execfile(defsoutput, {}, {}) |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 18 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 19 | import qdoffssupport |
| 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[0] |
| 29 | if t == "GWorldPtr" and m in ("InMode", "InOutMode"): |
| 30 | classname = "Method" |
| 31 | listname = "methods" |
| 32 | return classname, listname |
| 33 | |
| 34 | def writeinitialdefs(self): |
| 35 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 36 | |
| 37 | def makeblacklistnames(self): |
| 38 | return [ |
| 39 | 'DisposeGWorld', # Implied when the object is deleted |
| 40 | 'NewGWorldFromHBITMAP', # Don't know what the args do |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 41 | 'GetGDeviceAttributes', # Windows-only |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 42 | ] |
| 43 | |
| 44 | def makeblacklisttypes(self): |
| 45 | return [ |
| 46 | "void_ptr", # GetGDeviceSurface, blacklisted for now |
| 47 | "Ptr", # Again, for now (array is probably ok here) |
| 48 | ] |
| 49 | |
| 50 | def makerepairinstructions(self): |
| 51 | return [ |
| 52 | |
| 53 | ## ("UpdateGWorld", |
| 54 | ## [("GWorldPtr", "*", "OutMode")], |
| 55 | ## [("*", "*", "InOutMode")]), |
| 56 | |
| 57 | # This one is incorrect: we say that all input gdevices are |
| 58 | # optional, but some are not. Most are, however, so users passing |
| 59 | # None for non-optional gdevices will get a qd error, I guess, in |
| 60 | # stead of a python argument error. |
| 61 | ([("GDHandle", "*", "InMode")], |
| 62 | [("OptGDHandle", "*", "InMode")]), |
| 63 | ] |
| 64 | |
| 65 | if __name__ == "__main__": |
| 66 | main() |
| 67 | |