/Mac/Modules/res/resscan.py

http://unladen-swallow.googlecode.com/ · Python · 83 lines · 60 code · 16 blank · 7 comment · 4 complexity · 2ec00692713a8ab24ceeec04f37d60bc MD5 · raw file

  1. # Scan Resources.h header file, generate resgen.py and Resources.py files.
  2. # Then run ressupport to generate Resmodule.c.
  3. # (Should learn how to tell the compiler to compile it as well.)
  4. import sys
  5. import MacOS
  6. from bgenlocations import TOOLBOXDIR, BGENDIR
  7. sys.path.append(BGENDIR)
  8. from scantools import Scanner
  9. def main():
  10. input = "Resources.h"
  11. output = "resgen.py"
  12. defsoutput = TOOLBOXDIR + "Resources.py"
  13. scanner = ResourcesScanner(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 doing 'import ressupport' ==="
  19. import ressupport
  20. print "=== Done 'import ressupport'. It's up to you to compile Resmodule.c ==="
  21. class ResourcesScanner(Scanner):
  22. def destination(self, type, name, arglist):
  23. classname = "ResFunction"
  24. listname = "functions"
  25. if arglist:
  26. t, n, m = arglist[0]
  27. if t == "Handle" and m == "InMode":
  28. classname = "ResMethod"
  29. listname = "resmethods"
  30. return classname, listname
  31. def makeblacklistnames(self):
  32. return [
  33. "ReadPartialResource",
  34. "WritePartialResource",
  35. "TempInsertROMMap",
  36. ## "RmveResource", # RemoveResource
  37. ## "SizeResource", # GetResourceSizeOnDisk
  38. ## "MaxSizeRsrc", # GetMaxResourceSize
  39. # OS8 only
  40. 'RGetResource',
  41. 'OpenResFile',
  42. 'CreateResFile',
  43. 'RsrcZoneInit',
  44. 'InitResources',
  45. 'RsrcMapEntry',
  46. ]
  47. def makeblacklisttypes(self):
  48. return [
  49. ]
  50. def makerepairinstructions(self):
  51. return [
  52. ([("Str255", "*", "InMode")],
  53. [("*", "*", "OutMode")]),
  54. ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
  55. [("InBuffer", "*", "*")]),
  56. ([("void", "*", "OutMode"), ("long", "*", "InMode")],
  57. [("InOutBuffer", "*", "*")]),
  58. ([("void", "*", "OutMode"), ("long", "*", "InMode"),
  59. ("long", "*", "OutMode")],
  60. [("OutBuffer", "*", "InOutMode")]),
  61. ([("SInt8", "*", "*")],
  62. [("SignedByte", "*", "*")]),
  63. ([("UniCharCount", "*", "InMode"), ("UniChar_ptr", "*", "InMode")],
  64. [("UnicodeReverseInBuffer", "*", "*")]),
  65. ]
  66. if __name__ == "__main__":
  67. main()