/Mac/Modules/icn/icnscan.py

http://unladen-swallow.googlecode.com/ · Python · 71 lines · 55 code · 10 blank · 6 comment · 4 complexity · 476368f55c172ee6642523f99f934759 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 = "Icons"
  7. SHORT = "icn"
  8. OBJECT = "NOTUSED"
  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[0]
  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. "GetIconCacheData",
  35. "SetIconCacheData",
  36. # Constants with funny definitions
  37. "kSelectorAllHugeData",
  38. "kSelectorAllAvailableData",
  39. "svAllAvailableData",
  40. # Something in a comment accidentally seen as a const definition
  41. "err",
  42. # OS8 only
  43. 'IconServicesTerminate',
  44. # Lazy, right now.
  45. "GetIconRefFromFileInfo"
  46. ]
  47. def makeblacklisttypes(self):
  48. return [
  49. "IconActionUPP",
  50. "IconGetterUPP",
  51. "CFragInitBlockPtr",
  52. "CGRect_ptr",
  53. ]
  54. def makerepairinstructions(self):
  55. return [
  56. ]
  57. def writeinitialdefs(self):
  58. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  59. self.defsfile.write("from Carbon.Files import *\n")
  60. if __name__ == "__main__":
  61. main()