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" |
| 11 | OBJECT = "NOTUSED" |
| 12 | |
| 13 | def main(): |
| 14 | input = LONG + ".h" |
| 15 | output = SHORT + "gen.py" |
| 16 | defsoutput = TOOLBOXDIR + LONG + ".py" |
| 17 | scanner = MyScanner(input, output, defsoutput) |
| 18 | scanner.scan() |
| 19 | scanner.close() |
| 20 | scanner.gentypetest(SHORT+"typetest.py") |
| 21 | print "=== Testing definitions output code ===" |
| 22 | execfile(defsoutput, {}, {}) |
| 23 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 24 | exec "import " + SHORT + "support" |
| 25 | print "=== Done. It's up to you to compile it now! ===" |
| 26 | |
| 27 | class MyScanner(Scanner_OSX): |
| 28 | |
| 29 | def destination(self, type, name, arglist): |
| 30 | classname = "Function" |
| 31 | listname = "functions" |
| 32 | if arglist: |
| 33 | t, n, m = arglist[0] |
| 34 | # This is non-functional today |
| 35 | if t == OBJECT and m == "InMode": |
| 36 | classname = "Method" |
| 37 | listname = "methods" |
| 38 | return classname, listname |
| 39 | |
| 40 | def makeblacklistnames(self): |
| 41 | return [ |
| 42 | # Constants with incompatible definitions |
| 43 | "kioACAccessOwnerMask", |
| 44 | "kFSCatInfoReserved", |
| 45 | "kFSIterateReserved", |
| 46 | |
| 47 | "FSRefMakePath", # Do this manually |
| 48 | |
| 49 | "FSRead", # Couldn't be bothered |
| 50 | "FSWrite", # ditto |
| 51 | "FSReadFork", # ditto |
| 52 | "FSWriteFork", # ditto |
| 53 | |
| 54 | # Old routines: |
| 55 | "GetWDInfo", |
| 56 | "OpenWD", |
| 57 | "CloseWD", |
| 58 | "FInitQueue", |
| 59 | "rstflock", |
| 60 | "setflock", |
| 61 | "setfinfo", |
| 62 | "fsrename", |
| 63 | "fsdelete", |
| 64 | "create", |
| 65 | "flushvol", |
| 66 | "eject", |
| 67 | "umountvol", |
| 68 | "setvol", |
| 69 | "getvol", |
| 70 | "getfinfo", |
| 71 | "getvinfo", |
| 72 | "fsopen", |
| 73 | "RstFLock", |
| 74 | "SetFLock", |
| 75 | "SetFInfo", |
| 76 | "Rename", |
| 77 | "OpenRF", |
| 78 | "FSDelete", |
| 79 | "Create", |
| 80 | "GetVol", |
| 81 | "GetFInfo", |
| 82 | "GetVInfo", |
| 83 | "FSOpen", |
| 84 | "Eject", |
| 85 | "SetVol", |
| 86 | "openrf", |
| 87 | "unmountvol", |
| 88 | "OpenDF", |
| 89 | |
| 90 | ] |
| 91 | |
Jack Jansen | 6d802a0 | 2002-12-13 23:16:00 +0000 | [diff] [blame^] | 92 | def makegreylist(self): |
| 93 | return [ |
| 94 | ('#if TARGET_API_MAC_OSX', [ |
| 95 | 'FNNotifyAll', |
| 96 | 'FNNotifyByPath', |
| 97 | 'FNNotify', |
| 98 | ])] |
| 99 | |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 100 | def makeblacklisttypes(self): |
| 101 | return [ |
| 102 | "CInfoPBPtr", # Old stuff |
| 103 | "CMovePBPtr", # Old stuff |
| 104 | "ParmBlkPtr", # Old stuff |
| 105 | "HParmBlkPtr", # Old stuff |
| 106 | "DTPBPtr", # Old stuff |
| 107 | "FCBPBPtr", # Old stuff |
| 108 | "QHdrPtr", # Old stuff |
| 109 | "CSParamPtr", # Old stuff |
| 110 | "FSCatalogBulkParam", # old stuff |
| 111 | "FSForkCBInfoParam", # old stuff |
| 112 | "FSForkIOParam", # old stuff |
| 113 | "FSRefParam", # old stuff |
| 114 | "FSVolumeInfoParam", # old stuff |
| 115 | "WDPBPtr", # old stuff |
| 116 | "XCInfoPBPtr", # old stuff |
| 117 | "XVolumeParamPtr", # old stuff |
| 118 | |
| 119 | |
| 120 | "CatPositionRec", # State variable, not too difficult |
| 121 | "FSCatalogInfo", # Lots of fields, difficult struct |
| 122 | "FSCatalogInfo_ptr", # Lots of fields, difficult struct |
| 123 | "FSIterator", # Should become an object |
| 124 | "FSForkInfo", # Lots of fields, difficult struct |
| 125 | "FSSearchParams", # Also catsearch stuff |
| 126 | "FSVolumeInfo", # big struct |
| 127 | "FSVolumeInfo_ptr", # big struct |
| 128 | |
| 129 | "IOCompletionProcPtr", # proc pointer |
| 130 | "IOCompletionUPP", # Proc pointer |
| 131 | |
| 132 | |
| 133 | ] |
| 134 | |
| 135 | def makerepairinstructions(self): |
| 136 | return [ |
| 137 | # Various ways to give pathnames |
Jack Jansen | e2ba873 | 2002-11-22 14:58:35 +0000 | [diff] [blame] | 138 | ([('char_ptr', '*', 'InMode')], |
| 139 | [('stringptr', '*', 'InMode')] |
| 140 | ), |
| 141 | |
| 142 | # Unicode filenames passed as length, buffer |
| 143 | ([('UniCharCount', '*', 'InMode'), |
| 144 | ('UniChar_ptr', '*', 'InMode')], |
| 145 | [('UnicodeReverseInBuffer', '*', 'InMode')] |
| 146 | ), |
| 147 | ] |
| 148 | |
| 149 | |
| 150 | def writeinitialdefs(self): |
| 151 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 152 | self.defsfile.write("true = True\n") |
| 153 | self.defsfile.write("false = False\n") |
| 154 | |
| 155 | if __name__ == "__main__": |
| 156 | main() |