/Mac/Modules/ah/ahsupport.py

http://unladen-swallow.googlecode.com/ · Python · 45 lines · 19 code · 12 blank · 14 comment · 1 complexity · 343df06f1253e6f7b23847495598301d MD5 · raw file

  1. # This script generates a Python interface for an Apple Macintosh Manager.
  2. # It uses the "bgen" package to generate C code.
  3. # The function specifications are generated by scanning the mamager's header file,
  4. # using the "scantools" package (customized for this particular manager).
  5. import string
  6. # Declarations that change for each manager
  7. MACHEADERFILE = 'AppleHelp.h' # The Apple header file
  8. MODNAME = '_AH' # The name of the module
  9. # The following is *usually* unchanged but may still require tuning
  10. MODPREFIX = 'Ah' # The prefix for module-wide routines
  11. INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
  12. OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
  13. from macsupport import *
  14. # Create the type objects
  15. AHTOCType = Type("AHTOCType", "h")
  16. includestuff = includestuff + """
  17. #include <Carbon/Carbon.h>
  18. """
  19. # From here on it's basically all boiler plate...
  20. # Create the generator groups and link them
  21. module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
  22. # Create the generator classes used to populate the lists
  23. Function = OSErrFunctionGenerator
  24. # Create and populate the lists
  25. functions = []
  26. execfile(INPUTFILE)
  27. # add the populated lists to the generator groups
  28. # (in a different wordl the scan program would generate this)
  29. for f in functions: module.add(f)
  30. # generate output (open the output file as late as possible)
  31. SetOutputFileName(OUTPUTFILE)
  32. module.generate()