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