/Mac/Modules/fm/fmscan.py

http://unladen-swallow.googlecode.com/ · Python · 71 lines · 55 code · 10 blank · 6 comment · 1 complexity · 443b183bc6bbf6b17922bab4540995df MD5 · raw file

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2. import sys
  3. from bgenlocations import TOOLBOXDIR, BGENDIR
  4. sys.path.append(BGENDIR)
  5. from scantools import Scanner
  6. LONG = "Fonts"
  7. SHORT = "fm"
  8. def main():
  9. input = "Fonts.h"
  10. output = SHORT + "gen.py"
  11. defsoutput = TOOLBOXDIR + LONG + ".py"
  12. scanner = MyScanner(input, output, defsoutput)
  13. scanner.scan()
  14. scanner.close()
  15. print "=== Testing definitions output code ==="
  16. execfile(defsoutput, {}, {})
  17. print "=== Done scanning and generating, now importing the generated code... ==="
  18. exec "import " + SHORT + "support"
  19. print "=== Done. It's up to you to compile it now! ==="
  20. class MyScanner(Scanner):
  21. def destination(self, type, name, arglist):
  22. classname = "Function"
  23. listname = "functions"
  24. return classname, listname
  25. def makeblacklistnames(self):
  26. return [
  27. "OutlineMetrics", # Too complicated
  28. "AntiTextIsAntiAliased", # XXXX Missing from library...
  29. "AntiTextGetEnabled",
  30. "AntiTextSetEnabled",
  31. "AntiTextGetApplicationAware",
  32. "AntiTextSetApplicationAware",
  33. # These are tricky: they're not Carbon dependent or anything, but they
  34. # exist only on 8.6 or later (both in Carbon and Classic).
  35. # Disabling them is the easiest path.
  36. 'SetAntiAliasedTextEnabled',
  37. 'IsAntiAliasedTextEnabled',
  38. # OS8-only
  39. 'InitFonts',
  40. 'SetFontLock',
  41. 'FlushFonts',
  42. ]
  43. def makeblacklisttypes(self):
  44. return [
  45. "FMInput_ptr", # Not needed for now
  46. "FMOutPtr", # Ditto
  47. ## "void_ptr", # Don't know how to do this right now
  48. "FontInfo", # Ditto
  49. ]
  50. def makerepairinstructions(self):
  51. return [
  52. ([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]),
  53. ([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]),
  54. ([('short', 'byteCount', 'InMode'), ('void_ptr', 'textAddr', 'InMode'),],
  55. [('TextBuffer', 'inText', 'InMode')]),
  56. ]
  57. def writeinitialdefs(self):
  58. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  59. self.defsfile.write("kNilOptions = 0\n")
  60. if __name__ == "__main__":
  61. main()