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 |
Jack Jansen | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame] | 4 | from bgenlocations import TOOLBOXDIR, BGENDIR |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 5 | sys.path.append(BGENDIR) |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 6 | from scantools import Scanner |
| 7 | |
| 8 | LONG = "Fonts" |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 9 | SHORT = "fm" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 10 | |
| 11 | def main(): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 12 | input = "Fonts.h" |
| 13 | output = SHORT + "gen.py" |
| 14 | defsoutput = TOOLBOXDIR + LONG + ".py" |
| 15 | scanner = MyScanner(input, output, defsoutput) |
| 16 | scanner.scan() |
| 17 | scanner.close() |
| 18 | print "=== Testing definitions output code ===" |
| 19 | execfile(defsoutput, {}, {}) |
| 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! ===" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 23 | |
| 24 | class MyScanner(Scanner): |
| 25 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 26 | def destination(self, type, name, arglist): |
| 27 | classname = "Function" |
| 28 | listname = "functions" |
| 29 | return classname, listname |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 30 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 31 | def makeblacklistnames(self): |
| 32 | return [ |
| 33 | "OutlineMetrics", # Too complicated |
| 34 | "AntiTextIsAntiAliased", # XXXX Missing from library... |
| 35 | "AntiTextGetEnabled", |
| 36 | "AntiTextSetEnabled", |
| 37 | "AntiTextGetApplicationAware", |
| 38 | "AntiTextSetApplicationAware", |
| 39 | # These are tricky: they're not Carbon dependent or anything, but they |
| 40 | # exist only on 8.6 or later (both in Carbon and Classic). |
| 41 | # Disabling them is the easiest path. |
| 42 | 'SetAntiAliasedTextEnabled', |
| 43 | 'IsAntiAliasedTextEnabled', |
| 44 | # OS8-only |
| 45 | 'InitFonts', |
| 46 | 'SetFontLock', |
| 47 | 'FlushFonts', |
| 48 | ] |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 49 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 50 | def makeblacklisttypes(self): |
| 51 | return [ |
| 52 | "FMInput_ptr", # Not needed for now |
| 53 | "FMOutPtr", # Ditto |
| 54 | ## "void_ptr", # Don't know how to do this right now |
| 55 | "FontInfo", # Ditto |
| 56 | ] |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 57 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 58 | def makerepairinstructions(self): |
| 59 | return [ |
| 60 | ([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]), |
| 61 | ([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]), |
| 62 | ([('short', 'byteCount', 'InMode'), ('void_ptr', 'textAddr', 'InMode'),], |
| 63 | [('TextBuffer', 'inText', 'InMode')]), |
| 64 | ] |
| 65 | |
| 66 | def writeinitialdefs(self): |
| 67 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 68 | self.defsfile.write("kNilOptions = 0\n") |
Jack Jansen | b55e5f1 | 2001-01-03 16:44:27 +0000 | [diff] [blame] | 69 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 70 | if __name__ == "__main__": |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 71 | main() |