Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 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" |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 11 | |
| 12 | def main(): |
Jack Jansen | ae63756 | 2002-12-17 22:22:57 +0000 | [diff] [blame] | 13 | input = ["Files.h", "Aliases.h", "Finder.h"] |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 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: |
Jack Jansen | e3a1c8f | 2002-12-15 19:55:07 +0000 | [diff] [blame] | 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 |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 40 | t, n, m = arglist[0] |
Jack Jansen | e3a1c8f | 2002-12-15 19:55:07 +0000 | [diff] [blame] | 41 | if t == "AliasHandle" and m == "InMode": |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 42 | classname = "Method" |
Jack Jansen | e3a1c8f | 2002-12-15 19:55:07 +0000 | [diff] [blame] | 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" |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 50 | return classname, listname |
| 51 | |
| 52 | def makeblacklistnames(self): |
| 53 | return [ |
| 54 | # Constants with incompatible definitions |
| 55 | "kioACAccessOwnerMask", |
| 56 | "kFSCatInfoReserved", |
| 57 | "kFSIterateReserved", |
Jack Jansen | ae63756 | 2002-12-17 22:22:57 +0000 | [diff] [blame] | 58 | "kSystemFolderType", |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 59 | |
| 60 | "FSRefMakePath", # Do this manually |
Jack Jansen | e3a1c8f | 2002-12-15 19:55:07 +0000 | [diff] [blame] | 61 | # "ResolveAlias", # Do this manually |
| 62 | # "ResolveAliasWithMountFlags", # Do this manually |
| 63 | # "FollowFinderAlias", # Do this manually |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 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 | |
Jack Jansen | 6d802a0 | 2002-12-13 23:16:00 +0000 | [diff] [blame] | 108 | def makegreylist(self): |
| 109 | return [ |
| 110 | ('#if TARGET_API_MAC_OSX', [ |
| 111 | 'FNNotifyAll', |
| 112 | 'FNNotifyByPath', |
| 113 | 'FNNotify', |
| 114 | ])] |
| 115 | |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 116 | def makeblacklisttypes(self): |
| 117 | return [ |
| 118 | "CInfoPBPtr", # Old stuff |
| 119 | "CMovePBPtr", # Old stuff |
| 120 | "ParmBlkPtr", # Old stuff |
| 121 | "HParmBlkPtr", # Old stuff |
| 122 | "DTPBPtr", # Old stuff |
| 123 | "FCBPBPtr", # Old stuff |
| 124 | "QHdrPtr", # Old stuff |
| 125 | "CSParamPtr", # Old stuff |
| 126 | "FSCatalogBulkParam", # old stuff |
| 127 | "FSForkCBInfoParam", # old stuff |
| 128 | "FSForkIOParam", # old stuff |
| 129 | "FSRefParam", # old stuff |
| 130 | "FSVolumeInfoParam", # old stuff |
| 131 | "WDPBPtr", # old stuff |
| 132 | "XCInfoPBPtr", # old stuff |
| 133 | "XVolumeParamPtr", # old stuff |
| 134 | |
| 135 | |
| 136 | "CatPositionRec", # State variable, not too difficult |
| 137 | "FSCatalogInfo", # Lots of fields, difficult struct |
| 138 | "FSCatalogInfo_ptr", # Lots of fields, difficult struct |
| 139 | "FSIterator", # Should become an object |
| 140 | "FSForkInfo", # Lots of fields, difficult struct |
| 141 | "FSSearchParams", # Also catsearch stuff |
| 142 | "FSVolumeInfo", # big struct |
| 143 | "FSVolumeInfo_ptr", # big struct |
| 144 | |
| 145 | "IOCompletionProcPtr", # proc pointer |
| 146 | "IOCompletionUPP", # Proc pointer |
Jack Jansen | e3a1c8f | 2002-12-15 19:55:07 +0000 | [diff] [blame] | 147 | "AliasFilterProcPtr", |
| 148 | "AliasFilterUPP", |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 149 | |
| 150 | ] |
| 151 | |
| 152 | def makerepairinstructions(self): |
| 153 | return [ |
| 154 | # Various ways to give pathnames |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 155 | ([('char_ptr', '*', 'InMode')], |
| 156 | [('stringptr', '*', 'InMode')] |
| 157 | ), |
| 158 | |
| 159 | # Unicode filenames passed as length, buffer |
| 160 | ([('UniCharCount', '*', 'InMode'), |
| 161 | ('UniChar_ptr', '*', 'InMode')], |
| 162 | [('UnicodeReverseInBuffer', '*', 'InMode')] |
| 163 | ), |
Jack Jansen | e3a1c8f | 2002-12-15 19:55:07 +0000 | [diff] [blame] | 164 | # Wrong guess |
| 165 | ([('Str63', 'theString', 'InMode')], |
| 166 | [('Str63', 'theString', 'OutMode')]), |
| 167 | |
| 168 | # Yet another way to give a pathname:-) |
| 169 | ([('short', 'fullPathLength', 'InMode'), |
| 170 | ('void_ptr', 'fullPath', 'InMode')], |
| 171 | [('FullPathName', 'fullPath', 'InMode')]), |
| 172 | |
| 173 | # Various ResolveAliasFileXXXX functions |
| 174 | ([('FSSpec', 'theSpec', 'OutMode')], |
| 175 | [('FSSpec_ptr', 'theSpec', 'InOutMode')]), |
Jack Jansen | 543c925 | 2002-12-18 23:17:26 +0000 | [diff] [blame^] | 176 | |
| 177 | # The optional FSSpec to all ResolveAlias and NewAlias methods |
| 178 | ([('FSSpec_ptr', 'fromFile', 'InMode')], |
| 179 | [('OptFSSpecPtr', 'fromFile', 'InMode')]), |
| 180 | |
| 181 | ([('FSRef_ptr', 'fromFile', 'InMode')], |
| 182 | [('OptFSRefPtr', 'fromFile', 'InMode')]), |
| 183 | |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 184 | ] |
| 185 | |
| 186 | |
| 187 | def writeinitialdefs(self): |
| 188 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 189 | self.defsfile.write("true = True\n") |
| 190 | self.defsfile.write("false = False\n") |
| 191 | |
| 192 | if __name__ == "__main__": |
| 193 | main() |