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