• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4from bgenlocations import TOOLBOXDIR, BGENDIR
5sys.path.append(BGENDIR)
6from scantools import Scanner_OSX
7
8LONG = "Files"
9SHORT = "file"
10
11def main():
12    input = ["Files.h", "Aliases.h", "Finder.h"]
13    output = SHORT + "gen.py"
14    defsoutput = TOOLBOXDIR + LONG + ".py"
15    scanner = MyScanner(input, output, defsoutput)
16    scanner.scan()
17    scanner.close()
18    scanner.gentypetest(SHORT+"typetest.py")
19    print "=== Testing definitions output code ==="
20    execfile(defsoutput, {}, {})
21    print "=== Done scanning and generating, now importing the generated code... ==="
22    exec "import " + SHORT + "support"
23    print "=== Done.  It's up to you to compile it now! ==="
24
25class MyScanner(Scanner_OSX):
26
27    def destination(self, type, name, arglist):
28        classname = "Function"
29        listname = "functions"
30        if arglist:
31            # Funny special case
32            if len(arglist) > 2:
33                t, n, m = arglist[1]
34                if t == "AliasHandle" and m == "InMode":
35                    classname = "Arg2MethodGenerator"
36                    listname = "alias_methods"
37                    return classname, listname
38            # Normal cases
39            t, n, m = arglist[0]
40            if t == "AliasHandle" and m == "InMode":
41                classname = "Method"
42                listname = "alias_methods"
43            if t == "FSSpec_ptr" and m == "InMode":
44                classname = "Method"
45                listname = "fsspec_methods"
46            if t == "FSRef_ptr" and m == "InMode":
47                classname = "Method"
48                listname = "fsref_methods"
49        return classname, listname
50
51    def makeblacklistnames(self):
52        return [
53                # Constants with incompatible definitions
54                "kioACAccessOwnerMask",
55                "kFSCatInfoReserved",
56                "kFSIterateReserved",
57                "kSystemFolderType",
58
59                "FSRefMakePath", # Do this manually
60#                       "ResolveAlias", # Do this manually
61#                       "ResolveAliasWithMountFlags", # Do this manually
62#                       "FollowFinderAlias", # Do this manually
63
64                "FSRead", # Couldn't be bothered
65                "FSWrite", # ditto
66                "FSReadFork", # ditto
67                "FSWriteFork", # ditto
68
69                # Old routines:
70                "GetWDInfo",
71                "OpenWD",
72                "CloseWD",
73                "FInitQueue",
74                "rstflock",
75                "setflock",
76                "setfinfo",
77                "fsrename",
78                "fsdelete",
79                "create",
80                "flushvol",
81                "eject",
82                "umountvol",
83                "setvol",
84                "getvol",
85                "getfinfo",
86                "getvinfo",
87                "fsopen",
88                "RstFLock",
89                "SetFLock",
90                "SetFInfo",
91                "Rename",
92                "OpenRF",
93                "FSDelete",
94                "Create",
95                "GetVol",
96                "GetFInfo",
97                "GetVInfo",
98                "FSOpen",
99                "Eject",
100                "SetVol",
101                "openrf",
102                "unmountvol",
103                "OpenDF",
104
105                ]
106
107    def makeblacklisttypes(self):
108        return [
109                "CInfoPBPtr", # Old stuff
110                "CMovePBPtr", # Old stuff
111                "ParmBlkPtr", # Old stuff
112                "HParmBlkPtr", # Old stuff
113                "DTPBPtr", # Old stuff
114                "FCBPBPtr", # Old stuff
115                "QHdrPtr", # Old stuff
116                "CSParamPtr", # Old stuff
117                "FSCatalogBulkParam", # old stuff
118                "FSForkCBInfoParam", # old stuff
119                "FSForkIOParam", # old stuff
120                "FSRefParam",  # old stuff
121                "FSVolumeInfoParam", # old stuff
122                "WDPBPtr", # old stuff
123                "XCInfoPBPtr", # old stuff
124                "XVolumeParamPtr", # old stuff
125
126
127                "CatPositionRec", # State variable, not too difficult
128                "FSIterator", # Should become an object
129                "FSForkInfo", # Lots of fields, difficult struct
130                "FSSearchParams", # Also catsearch stuff
131                "FSVolumeInfo", # big struct
132                "FSVolumeInfo_ptr", # big struct
133
134                "IOCompletionProcPtr", # proc pointer
135                "IOCompletionUPP", # Proc pointer
136                "AliasFilterProcPtr",
137                "AliasFilterUPP",
138                "FNSubscriptionUPP",
139
140                "FNSubscriptionRef", # Lazy, for now.
141                ]
142
143    def makerepairinstructions(self):
144        return [
145                # Various ways to give pathnames
146                ([('char_ptr', '*', 'InMode')],
147                 [('stringptr', '*', 'InMode')]
148                ),
149
150                # Unicode filenames passed as length, buffer
151                ([('UniCharCount', '*', 'InMode'),
152                  ('UniChar_ptr', '*', 'InMode')],
153                 [('UnicodeReverseInBuffer', '*', 'InMode')]
154                ),
155                # Wrong guess
156                ([('Str63', 'theString', 'InMode')],
157                 [('Str63', 'theString', 'OutMode')]),
158
159                # Yet another way to give a pathname:-)
160                ([('short', 'fullPathLength', 'InMode'),
161                  ('void_ptr', 'fullPath', 'InMode')],
162                 [('FullPathName', 'fullPath', 'InMode')]),
163
164                # Various ResolveAliasFileXXXX functions
165                ([('FSSpec', 'theSpec', 'OutMode')],
166                 [('FSSpec_ptr', 'theSpec', 'InOutMode')]),
167
168                ([('FSRef', 'theRef', 'OutMode')],
169                 [('FSRef_ptr', 'theRef', 'InOutMode')]),
170
171                # The optional FSSpec to all ResolveAlias and NewAlias methods
172                ([('FSSpec_ptr', 'fromFile', 'InMode')],
173         [('OptFSSpecPtr', 'fromFile', 'InMode')]),
174
175                ([('FSRef_ptr', 'fromFile', 'InMode')],
176         [('OptFSRefPtr', 'fromFile', 'InMode')]),
177
178##              # FSCatalogInfo input handling
179##                      ([('FSCatalogInfoBitmap', 'whichInfo', 'InMode'),
180##                ('FSCatalogInfo_ptr', 'catalogInfo', 'InMode')],
181##               [('FSCatalogInfoAndBitmap_in', 'catalogInfo', 'InMode')]),
182##
183##              # FSCatalogInfo output handling
184##                      ([('FSCatalogInfoBitmap', 'whichInfo', 'InMode'),
185##                ('FSCatalogInfo', 'catalogInfo', 'OutMode')],
186##               [('FSCatalogInfoAndBitmap_out', 'catalogInfo', 'InOutMode')]),
187##
188
189        ]
190
191
192    def writeinitialdefs(self):
193        self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
194        self.defsfile.write("true = True\n")
195        self.defsfile.write("false = False\n")
196
197if __name__ == "__main__":
198    main()
199