/Mac/Modules/te/tescan.py

http://unladen-swallow.googlecode.com/ · Python · 66 lines · 52 code · 10 blank · 4 comment · 4 complexity · c92c059f026feca3ac62ea5c1fccf652 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 = "TextEdit"
  7. SHORT = "te"
  8. OBJECT = "TEHandle"
  9. def main():
  10. input = LONG + ".h"
  11. output = SHORT + "gen.py"
  12. defsoutput = TOOLBOXDIR + LONG + ".py"
  13. scanner = MyScanner(input, output, defsoutput)
  14. scanner.scan()
  15. scanner.close()
  16. print "=== Testing definitions output code ==="
  17. execfile(defsoutput, {}, {})
  18. print "=== Done scanning and generating, now importing the generated code... ==="
  19. exec "import " + SHORT + "support"
  20. print "=== Done. It's up to you to compile it now! ==="
  21. class MyScanner(Scanner):
  22. def destination(self, type, name, arglist):
  23. classname = "Function"
  24. listname = "functions"
  25. if arglist:
  26. t, n, m = arglist[-1]
  27. # This is non-functional today
  28. if t == OBJECT and m == "InMode":
  29. classname = "Method"
  30. listname = "methods"
  31. return classname, listname
  32. def makeblacklistnames(self):
  33. return [
  34. "TEDispose",
  35. "TEInit",
  36. ## "TEGetHiliteRgn",
  37. ]
  38. def makeblacklisttypes(self):
  39. return [
  40. "TEClickLoopUPP",
  41. "UniversalProcPtr",
  42. "WordBreakUPP",
  43. "TEDoTextUPP",
  44. "TERecalcUPP",
  45. "TEFindWordUPP",
  46. ]
  47. def makerepairinstructions(self):
  48. return [
  49. ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
  50. [("InBuffer", "*", "*")]),
  51. # TEContinuousStyle
  52. ([("short", "mode", "OutMode"), ("TextStyle", "aStyle", "OutMode")],
  53. [("short", "mode", "InOutMode"), ("TextStyle", "aStyle", "InOutMode")])
  54. ]
  55. if __name__ == "__main__":
  56. main()