| 1 | # Scan an Apple header file, generating a Python file of generator calls.
|
|---|
| 2 | import sys
|
|---|
| 3 | import os
|
|---|
| 4 | from bgenlocations import TOOLBOXDIR, BGENDIR
|
|---|
| 5 | sys.path.append(BGENDIR)
|
|---|
| 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()
|
|---|
| 16 | print "=== Testing definitions output code ==="
|
|---|
| 17 | execfile(defsoutput, {}, {})
|
|---|
| 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
|
|---|
| 41 | 'GetGDeviceAttributes', # Windows-only
|
|---|
| 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()
|
|---|