Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 3 | import sys |
| 4 | import os |
Jack Jansen | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame^] | 5 | from bgenlocations import TOOLBOXDIR, BGENDIR |
Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 6 | sys.path.append(BGENDIR) |
| 7 | from scantools import Scanner |
Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 8 | |
| 9 | LONG = "Icons" |
| 10 | SHORT = "icn" |
| 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 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 21 | exec "import " + SHORT + "support" |
| 22 | print "=== Done. It's up to you to compile it now! ===" |
| 23 | |
| 24 | class MyScanner(Scanner): |
| 25 | |
| 26 | def destination(self, type, name, arglist): |
| 27 | classname = "Function" |
| 28 | listname = "functions" |
| 29 | if arglist: |
| 30 | t, n, m = arglist[0] |
| 31 | # This is non-functional today |
| 32 | if t == OBJECT and m == "InMode": |
| 33 | classname = "Method" |
| 34 | listname = "methods" |
| 35 | return classname, listname |
| 36 | |
| 37 | def makeblacklistnames(self): |
| 38 | return [ |
| 39 | "GetIconCacheData", |
| 40 | "SetIconCacheData", |
Jack Jansen | b1b78d8 | 1999-12-14 15:47:01 +0000 | [diff] [blame] | 41 | # Constants with funny definitions |
| 42 | "kSelectorAllHugeData", |
| 43 | "kSelectorAllAvailableData", |
| 44 | "svAllAvailableData", |
Jack Jansen | b55e5f1 | 2001-01-03 16:44:27 +0000 | [diff] [blame] | 45 | # Something in a comment accidentally seen as a const definition |
| 46 | "err", |
Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 47 | ] |
| 48 | |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 49 | def makegreylist(self): |
| 50 | return [ |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 51 | ('#if !TARGET_API_MAC_CARBON', [ |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 52 | 'IconServicesTerminate', |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 53 | ]), |
| 54 | ('#if TARGET_API_MAC_CARBON', [ |
| 55 | 'WriteIconFile', |
| 56 | 'ReadIconFile', |
| 57 | 'RegisterIconRefFromIconFile', |
| 58 | 'GetIconRefVariant', |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 59 | ])] |
| 60 | |
Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 61 | def makeblacklisttypes(self): |
| 62 | return [ |
| 63 | "IconActionUPP", |
| 64 | "IconGetterUPP", |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 65 | "CFragInitBlockPtr", |
Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 66 | ] |
| 67 | |
| 68 | def makerepairinstructions(self): |
| 69 | return [ |
| 70 | ] |
Jack Jansen | b1b78d8 | 1999-12-14 15:47:01 +0000 | [diff] [blame] | 71 | |
| 72 | def writeinitialdefs(self): |
| 73 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
Jack Jansen | 31000dd | 1999-01-18 09:34:50 +0000 | [diff] [blame] | 74 | |
| 75 | if __name__ == "__main__": |
| 76 | main() |