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 |
| 4 | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') |
| 5 | sys.path.append(BGENDIR) |
| 6 | from bgenlocations import TOOLBOXDIR |
| 7 | |
| 8 | from scantools import Scanner |
| 9 | |
| 10 | def main(): |
| 11 | input = "QDOffscreen.h" |
| 12 | output = "qdoffsgen.py" |
| 13 | defsoutput = TOOLBOXDIR + "QDOffscreen.py" |
| 14 | scanner = MyScanner(input, output, defsoutput) |
| 15 | scanner.scan() |
| 16 | scanner.close() |
| 17 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 18 | import qdoffssupport |
| 19 | print "=== Done. It's up to you to compile it now! ===" |
| 20 | |
| 21 | class MyScanner(Scanner): |
| 22 | |
| 23 | def destination(self, type, name, arglist): |
| 24 | classname = "Function" |
| 25 | listname = "functions" |
| 26 | if arglist: |
| 27 | t, n, m = arglist[0] |
| 28 | if t == "GWorldPtr" and m in ("InMode", "InOutMode"): |
| 29 | classname = "Method" |
| 30 | listname = "methods" |
| 31 | return classname, listname |
| 32 | |
| 33 | def writeinitialdefs(self): |
| 34 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 35 | |
| 36 | def makeblacklistnames(self): |
| 37 | return [ |
| 38 | 'DisposeGWorld', # Implied when the object is deleted |
| 39 | 'NewGWorldFromHBITMAP', # Don't know what the args do |
| 40 | 'GetGDeviceAttributes', # Doesn't seem to exist |
| 41 | ] |
| 42 | |
| 43 | def makeblacklisttypes(self): |
| 44 | return [ |
| 45 | "void_ptr", # GetGDeviceSurface, blacklisted for now |
| 46 | "Ptr", # Again, for now (array is probably ok here) |
| 47 | ] |
| 48 | |
| 49 | def makerepairinstructions(self): |
| 50 | return [ |
| 51 | |
| 52 | ## ("UpdateGWorld", |
| 53 | ## [("GWorldPtr", "*", "OutMode")], |
| 54 | ## [("*", "*", "InOutMode")]), |
| 55 | |
| 56 | # This one is incorrect: we say that all input gdevices are |
| 57 | # optional, but some are not. Most are, however, so users passing |
| 58 | # None for non-optional gdevices will get a qd error, I guess, in |
| 59 | # stead of a python argument error. |
| 60 | ([("GDHandle", "*", "InMode")], |
| 61 | [("OptGDHandle", "*", "InMode")]), |
| 62 | ] |
| 63 | |
| 64 | if __name__ == "__main__": |
| 65 | main() |
| 66 | |