blob: 0195fea1fb2b5a72d542ee6016c0324e355e686e [file] [log] [blame]
Jack Jansene2ba8732002-11-22 14:58:35 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4import os
5from bgenlocations import TOOLBOXDIR, BGENDIR
6sys.path.append(BGENDIR)
7from scantools import Scanner_OSX
8
9LONG = "Files"
10SHORT = "file"
Jack Jansene2ba8732002-11-22 14:58:35 +000011
12def main():
Jack Jansene3a1c8f2002-12-15 19:55:07 +000013 input = ["Files.h", "Aliases.h"]
Jack Jansene2ba8732002-11-22 14:58:35 +000014 output = SHORT + "gen.py"
15 defsoutput = TOOLBOXDIR + LONG + ".py"
16 scanner = MyScanner(input, output, defsoutput)
17 scanner.scan()
18 scanner.close()
19 scanner.gentypetest(SHORT+"typetest.py")
20 print "=== Testing definitions output code ==="
21 execfile(defsoutput, {}, {})
22 print "=== Done scanning and generating, now importing the generated code... ==="
23 exec "import " + SHORT + "support"
24 print "=== Done. It's up to you to compile it now! ==="
25
26class MyScanner(Scanner_OSX):
27
28 def destination(self, type, name, arglist):
29 classname = "Function"
30 listname = "functions"
31 if arglist:
Jack Jansene3a1c8f2002-12-15 19:55:07 +000032 # Funny special case
33 if len(arglist) > 2:
34 t, n, m = arglist[1]
35 if t == "AliasHandle" and m == "InMode":
36 classname = "Arg2MethodGenerator"
37 listname = "alias_methods"
38 return classname, listname
39 # Normal cases
Jack Jansene2ba8732002-11-22 14:58:35 +000040 t, n, m = arglist[0]
Jack Jansene3a1c8f2002-12-15 19:55:07 +000041 if t == "AliasHandle" and m == "InMode":
Jack Jansene2ba8732002-11-22 14:58:35 +000042 classname = "Method"
Jack Jansene3a1c8f2002-12-15 19:55:07 +000043 listname = "alias_methods"
44 if t == "FSSpec_ptr" and m == "InMode":
45 classname = "Method"
46 listname = "fsspec_methods"
47 if t == "FSRef_ptr" and m == "InMode":
48 classname = "Method"
49 listname = "fsref_methods"
Jack Jansene2ba8732002-11-22 14:58:35 +000050 return classname, listname
51
52 def makeblacklistnames(self):
53 return [
54 # Constants with incompatible definitions
55 "kioACAccessOwnerMask",
56 "kFSCatInfoReserved",
57 "kFSIterateReserved",
58
59 "FSRefMakePath", # Do this manually
Jack Jansene3a1c8f2002-12-15 19:55:07 +000060# "ResolveAlias", # Do this manually
61# "ResolveAliasWithMountFlags", # Do this manually
62# "FollowFinderAlias", # Do this manually
Jack Jansene2ba8732002-11-22 14:58:35 +000063
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
Jack Jansen6d802a02002-12-13 23:16:00 +0000107 def makegreylist(self):
108 return [
109 ('#if TARGET_API_MAC_OSX', [
110 'FNNotifyAll',
111 'FNNotifyByPath',
112 'FNNotify',
113 ])]
114
Jack Jansene2ba8732002-11-22 14:58:35 +0000115 def makeblacklisttypes(self):
116 return [
117 "CInfoPBPtr", # Old stuff
118 "CMovePBPtr", # Old stuff
119 "ParmBlkPtr", # Old stuff
120 "HParmBlkPtr", # Old stuff
121 "DTPBPtr", # Old stuff
122 "FCBPBPtr", # Old stuff
123 "QHdrPtr", # Old stuff
124 "CSParamPtr", # Old stuff
125 "FSCatalogBulkParam", # old stuff
126 "FSForkCBInfoParam", # old stuff
127 "FSForkIOParam", # old stuff
128 "FSRefParam", # old stuff
129 "FSVolumeInfoParam", # old stuff
130 "WDPBPtr", # old stuff
131 "XCInfoPBPtr", # old stuff
132 "XVolumeParamPtr", # old stuff
133
134
135 "CatPositionRec", # State variable, not too difficult
136 "FSCatalogInfo", # Lots of fields, difficult struct
137 "FSCatalogInfo_ptr", # Lots of fields, difficult struct
138 "FSIterator", # Should become an object
139 "FSForkInfo", # Lots of fields, difficult struct
140 "FSSearchParams", # Also catsearch stuff
141 "FSVolumeInfo", # big struct
142 "FSVolumeInfo_ptr", # big struct
143
144 "IOCompletionProcPtr", # proc pointer
145 "IOCompletionUPP", # Proc pointer
Jack Jansene3a1c8f2002-12-15 19:55:07 +0000146 "AliasFilterProcPtr",
147 "AliasFilterUPP",
Jack Jansene2ba8732002-11-22 14:58:35 +0000148
149 ]
150
151 def makerepairinstructions(self):
152 return [
153 # Various ways to give pathnames
Jack Jansene2ba8732002-11-22 14:58:35 +0000154 ([('char_ptr', '*', 'InMode')],
155 [('stringptr', '*', 'InMode')]
156 ),
157
158 # Unicode filenames passed as length, buffer
159 ([('UniCharCount', '*', 'InMode'),
160 ('UniChar_ptr', '*', 'InMode')],
161 [('UnicodeReverseInBuffer', '*', 'InMode')]
162 ),
Jack Jansene3a1c8f2002-12-15 19:55:07 +0000163 # Wrong guess
164 ([('Str63', 'theString', 'InMode')],
165 [('Str63', 'theString', 'OutMode')]),
166
167 # Yet another way to give a pathname:-)
168 ([('short', 'fullPathLength', 'InMode'),
169 ('void_ptr', 'fullPath', 'InMode')],
170 [('FullPathName', 'fullPath', 'InMode')]),
171
172 # Various ResolveAliasFileXXXX functions
173 ([('FSSpec', 'theSpec', 'OutMode')],
174 [('FSSpec_ptr', 'theSpec', 'InOutMode')]),
Jack Jansene2ba8732002-11-22 14:58:35 +0000175 ]
176
177
178 def writeinitialdefs(self):
179 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
180 self.defsfile.write("true = True\n")
181 self.defsfile.write("false = False\n")
182
183if __name__ == "__main__":
184 main()