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 | |
| 92 | def makeblacklisttypes(self): |
| 93 | return [ |
| 94 | "CInfoPBPtr", # Old stuff |
| 95 | "CMovePBPtr", # Old stuff |
| 96 | "ParmBlkPtr", # Old stuff |
| 97 | "HParmBlkPtr", # Old stuff |
| 98 | "DTPBPtr", # Old stuff |
| 99 | "FCBPBPtr", # Old stuff |
| 100 | "QHdrPtr", # Old stuff |
| 101 | "CSParamPtr", # Old stuff |
| 102 | "FSCatalogBulkParam", # old stuff |
| 103 | "FSForkCBInfoParam", # old stuff |
| 104 | "FSForkIOParam", # old stuff |
| 105 | "FSRefParam", # old stuff |
| 106 | "FSVolumeInfoParam", # old stuff |
| 107 | "WDPBPtr", # old stuff |
| 108 | "XCInfoPBPtr", # old stuff |
| 109 | "XVolumeParamPtr", # old stuff |
| 110 | |
| 111 | |
| 112 | "CatPositionRec", # State variable, not too difficult |
| 113 | "FSCatalogInfo", # Lots of fields, difficult struct |
| 114 | "FSCatalogInfo_ptr", # Lots of fields, difficult struct |
| 115 | "FSIterator", # Should become an object |
| 116 | "FSForkInfo", # Lots of fields, difficult struct |
| 117 | "FSSearchParams", # Also catsearch stuff |
| 118 | "FSVolumeInfo", # big struct |
| 119 | "FSVolumeInfo_ptr", # big struct |
| 120 | |
| 121 | "IOCompletionProcPtr", # proc pointer |
| 122 | "IOCompletionUPP", # Proc pointer |
| 123 | |
| 124 | |
| 125 | ] |
| 126 | |
| 127 | def makerepairinstructions(self): |
| 128 | return [ |
| 129 | # Various ways to give pathnames |
| 130 | ([('UInt8_ptr', 'path', 'InMode')], |
| 131 | [('stringptr', 'path', 'InMode')] |
| 132 | ), |
| 133 | |
| 134 | ([('char_ptr', '*', 'InMode')], |
| 135 | [('stringptr', '*', 'InMode')] |
| 136 | ), |
| 137 | |
| 138 | # Unicode filenames passed as length, buffer |
| 139 | ([('UniCharCount', '*', 'InMode'), |
| 140 | ('UniChar_ptr', '*', 'InMode')], |
| 141 | [('UnicodeReverseInBuffer', '*', 'InMode')] |
| 142 | ), |
| 143 | ] |
| 144 | |
| 145 | |
| 146 | def writeinitialdefs(self): |
| 147 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 148 | self.defsfile.write("true = True\n") |
| 149 | self.defsfile.write("false = False\n") |
| 150 | |
| 151 | if __name__ == "__main__": |
| 152 | main() |