• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Scan <Drag.h>, generating draggen.py.
2import sys
3from bgenlocations import TOOLBOXDIR, BGENDIR, INCLUDEDIR
4sys.path.append(BGENDIR)
5
6from scantools import Scanner
7
8MISSING_DEFINES="""
9kDragHasLeftSenderWindow        = (1 << 0)
10kDragInsideSenderApplication = (1 << 1)
11kDragInsideSenderWindow         = (1 << 2)
12kDragRegionAndImage                     = (1 << 4)
13flavorSenderOnly                        = (1 << 0)
14flavorSenderTranslated          = (1 << 1)
15flavorNotSaved                          = (1 << 2)
16flavorSystemTranslated          = (1 << 8)
17"""
18
19
20def main():
21    input = INCLUDEDIR + "Drag.h"
22    output = "draggen.py"
23    defsoutput = TOOLBOXDIR + "Dragconst.py"
24    scanner = MyScanner(input, output, defsoutput)
25    scanner.scan()
26    scanner.close()
27    print "=== Testing definitions output code ==="
28    execfile(defsoutput, {}, {})
29    print "=== Done scanning and generating, now doing 'import dragsupport' ==="
30    import dragsupport
31    print "=== Done.  It's up to you to compile Dragmodule.c ==="
32
33class MyScanner(Scanner):
34
35    def destination(self, type, name, arglist):
36        classname = "Function"
37        listname = "functions"
38        if arglist:
39            t, n, m = arglist[0]
40            if t in ('DragReference', 'DragRef') and m == "InMode":
41                classname = "Method"
42                listname = "methods"
43        return classname, listname
44
45    def writeinitialdefs(self):
46        self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
47        self.defsfile.write("from Carbon.TextEdit import *\n")
48        self.defsfile.write("from Carbon.QuickDraw import *\n")
49        self.defsfile.write("fkDragActionAll = -1\n")
50        self.defsfile.write("\n")
51        # Defines unparseable in Drag.h
52        self.defsfile.write(MISSING_DEFINES)
53
54    def makeblacklistnames(self):
55        return [
56                "kDragActionAll",
57                ]
58
59    def makeblacklisttypes(self):
60        return [
61                "DragTrackingHandlerUPP",
62                "DragReceiveHandlerUPP",
63                "DragSendDataUPP",
64                "DragInputUPP",
65                "DragDrawingUPP",
66                ]
67
68    def makerepairinstructions(self):
69        return [
70                ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
71                 [("OptionalInBuffer", "*", "*")]),
72
73                ([("void", "*", "OutMode"), ("Size", "*", "OutMode")],
74                 [("VarOutBuffer", "*", "InOutMode")]),
75
76                ]
77
78if __name__ == "__main__":
79    main()
80