/Mac/Modules/fm/fmsupport.py

http://unladen-swallow.googlecode.com/ · Python · 81 lines · 53 code · 15 blank · 13 comment · 1 complexity · 6200f5d9afa3d5d5731c06e0dcd90c8f 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 = 'Fonts.h' # The Apple header file
  8. MODNAME = '_Fm' # The name of the module
  9. # The following is *usually* unchanged but may still require tuning
  10. MODPREFIX = 'Fm' # 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. class RevVarInputBufferType(VarInputBufferType):
  16. def passInput(self, name):
  17. return "%s__len__, %s__in__" % (name, name)
  18. TextBuffer = RevVarInputBufferType()
  19. includestuff = includestuff + """
  20. #include <Carbon/Carbon.h>
  21. /*
  22. ** Parse/generate ComponentDescriptor records
  23. */
  24. static PyObject *
  25. FMRec_New(FMetricRec *itself)
  26. {
  27. return Py_BuildValue("O&O&O&O&O&",
  28. PyMac_BuildFixed, itself->ascent,
  29. PyMac_BuildFixed, itself->descent,
  30. PyMac_BuildFixed, itself->leading,
  31. PyMac_BuildFixed, itself->widMax,
  32. ResObj_New, itself->wTabHandle);
  33. }
  34. #if 0
  35. /* Not needed... */
  36. static int
  37. FMRec_Convert(PyObject *v, FMetricRec *p_itself)
  38. {
  39. return PyArg_ParseTuple(v, "O&O&O&O&O&",
  40. PyMac_GetFixed, &itself->ascent,
  41. PyMac_GetFixed, &itself->descent,
  42. PyMac_GetFixed, &itself->leading,
  43. PyMac_GetFixed, &itself->widMax,
  44. ResObj_Convert, &itself->wTabHandle);
  45. }
  46. #endif
  47. """
  48. FMetricRecPtr = OpaqueType('FMetricRec', 'FMRec')
  49. # Create the generator groups and link them
  50. module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
  51. # Create the generator classes used to populate the lists
  52. Function = OSErrWeakLinkFunctionGenerator
  53. # Create and populate the lists
  54. functions = []
  55. execfile(INPUTFILE)
  56. # add the populated lists to the generator groups
  57. # (in a different wordl the scan program would generate this)
  58. for f in functions: module.add(f)
  59. # generate output (open the output file as late as possible)
  60. SetOutputFileName(OUTPUTFILE)
  61. module.generate()