Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 3 | import sys |
| 4 | import os |
| 5 | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') |
| 6 | sys.path.append(BGENDIR) |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 7 | from scantools import Scanner |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 8 | from bgenlocations import TOOLBOXDIR |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 9 | |
| 10 | LONG = "Fonts" |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 11 | SHORT = "fm" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 12 | |
| 13 | def main(): |
| 14 | input = "Fonts.h" |
| 15 | output = SHORT + "gen.py" |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 16 | defsoutput = TOOLBOXDIR + LONG + ".py" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 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 | return classname, listname |
| 30 | |
| 31 | def makeblacklistnames(self): |
| 32 | return [ |
| 33 | "OutlineMetrics", # Too complicated |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 34 | "AntiTextIsAntiAliased", # XXXX Missing from library... |
| 35 | "AntiTextGetEnabled", |
| 36 | "AntiTextSetEnabled", |
| 37 | "AntiTextGetApplicationAware", |
| 38 | "AntiTextSetApplicationAware", |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 39 | ] |
| 40 | |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 41 | def makegreylist(self): |
| 42 | return [ |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 43 | ('#if !TARGET_API_MAC_CARBON', [ |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 44 | 'InitFonts', |
| 45 | 'SetFontLock', |
| 46 | 'FlushFonts', |
| 47 | ])] |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 48 | def makeblacklisttypes(self): |
| 49 | return [ |
| 50 | "FMInput_ptr", # Not needed for now |
| 51 | "FMOutPtr", # Ditto |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 52 | "void_ptr", # Don't know how to do this right now |
| 53 | "FontInfo", # Ditto |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 54 | ] |
| 55 | |
| 56 | def makerepairinstructions(self): |
| 57 | return [ |
| 58 | ([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]), |
| 59 | ([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]), |
| 60 | ] |
| 61 | |
Jack Jansen | b55e5f1 | 2001-01-03 16:44:27 +0000 | [diff] [blame^] | 62 | def writeinitialdefs(self): |
| 63 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 64 | self.defsfile.write("kNilOptions = 0\n") |
| 65 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 66 | if __name__ == "__main__": |
| 67 | main() |