1995-11-30 11:03:09 -04:00
|
|
|
# This script generates a Python interface for an Apple Macintosh Manager.
|
|
|
|
# It uses the "bgen" package to generate C code.
|
|
|
|
# The function specifications are generated by scanning the mamager's header file,
|
|
|
|
# using the "scantools" package (customized for this particular manager).
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Declarations that change for each manager
|
2004-07-18 03:16:08 -03:00
|
|
|
MACHEADERFILE = 'Components.h' # The Apple header file
|
|
|
|
MODNAME = '_Cm' # The name of the module
|
1995-11-30 11:03:09 -04:00
|
|
|
|
|
|
|
# The following is *usually* unchanged but may still require tuning
|
2004-07-18 03:16:08 -03:00
|
|
|
MODPREFIX = 'Cm' # The prefix for module-wide routines
|
|
|
|
C_OBJECTPREFIX = 'CmpObj' # The prefix for object methods
|
1995-11-30 11:03:09 -04:00
|
|
|
CI_OBJECTPREFIX = 'CmpInstObj'
|
|
|
|
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
2004-07-18 03:16:08 -03:00
|
|
|
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
1995-11-30 11:03:09 -04:00
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
|
|
|
# Create the type objects
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2001-05-22 18:56:42 -03:00
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
2001-05-17 18:58:34 -03:00
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
extern PyObject *_CmpObj_New(Component);
|
|
|
|
extern int _CmpObj_Convert(PyObject *, Component *);
|
|
|
|
extern PyObject *_CmpInstObj_New(ComponentInstance);
|
|
|
|
extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
|
|
|
|
|
|
|
|
#define CmpObj_New _CmpObj_New
|
|
|
|
#define CmpObj_Convert _CmpObj_Convert
|
|
|
|
#define CmpInstObj_New _CmpInstObj_New
|
|
|
|
#define CmpInstObj_Convert _CmpInstObj_Convert
|
|
|
|
#endif
|
1995-11-30 11:03:09 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Parse/generate ComponentDescriptor records
|
|
|
|
*/
|
2000-07-14 19:16:45 -03:00
|
|
|
static PyObject *
|
2001-05-22 18:56:42 -03:00
|
|
|
CmpDesc_New(ComponentDescription *itself)
|
1995-11-30 11:03:09 -04:00
|
|
|
{
|
|
|
|
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("O&O&O&ll",
|
|
|
|
PyMac_BuildOSType, itself->componentType,
|
|
|
|
PyMac_BuildOSType, itself->componentSubType,
|
|
|
|
PyMac_BuildOSType, itself->componentManufacturer,
|
|
|
|
itself->componentFlags, itself->componentFlagsMask);
|
1995-11-30 11:03:09 -04:00
|
|
|
}
|
|
|
|
|
2000-07-14 19:16:45 -03:00
|
|
|
static int
|
2001-05-22 18:56:42 -03:00
|
|
|
CmpDesc_Convert(PyObject *v, ComponentDescription *p_itself)
|
1995-11-30 11:03:09 -04:00
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
return PyArg_ParseTuple(v, "O&O&O&ll",
|
|
|
|
PyMac_GetOSType, &p_itself->componentType,
|
|
|
|
PyMac_GetOSType, &p_itself->componentSubType,
|
|
|
|
PyMac_GetOSType, &p_itself->componentManufacturer,
|
|
|
|
&p_itself->componentFlags, &p_itself->componentFlagsMask);
|
1995-11-30 11:03:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2001-05-17 18:58:34 -03:00
|
|
|
initstuff = initstuff + """
|
2004-07-18 03:16:08 -03:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert);
|
2001-05-17 18:58:34 -03:00
|
|
|
"""
|
|
|
|
|
1995-11-30 11:03:09 -04:00
|
|
|
ComponentDescription = OpaqueType('ComponentDescription', 'CmpDesc')
|
|
|
|
Component = OpaqueByValueType('Component', C_OBJECTPREFIX)
|
|
|
|
ComponentInstance = OpaqueByValueType('ComponentInstance', CI_OBJECTPREFIX)
|
|
|
|
ComponentResult = Type("ComponentResult", "l")
|
|
|
|
|
|
|
|
ComponentResourceHandle = OpaqueByValueType("ComponentResourceHandle", "ResObj")
|
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class MyCIObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("""if (itself == NULL) {
|
|
|
|
PyErr_SetString(Cm_Error,"NULL ComponentInstance");
|
|
|
|
return NULL;
|
|
|
|
}""")
|
1995-11-30 11:03:09 -04:00
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class MyCObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("""if (itself == NULL) {
|
|
|
|
/* XXXX Or should we return None? */
|
|
|
|
PyErr_SetString(Cm_Error,"No such component");
|
|
|
|
return NULL;
|
|
|
|
}""")
|
|
|
|
|
|
|
|
def outputCheckConvertArg(self):
|
|
|
|
Output("""if ( v == Py_None ) {
|
|
|
|
*p_itself = 0;
|
|
|
|
return 1;
|
|
|
|
}""")
|
1995-11-30 11:03:09 -04:00
|
|
|
|
|
|
|
# Create the generator groups and link them
|
|
|
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
|
|
|
ci_object = MyCIObjectDefinition('ComponentInstance', CI_OBJECTPREFIX,
|
2004-07-18 03:16:08 -03:00
|
|
|
'ComponentInstance')
|
1995-11-30 11:03:09 -04:00
|
|
|
c_object = MyCObjectDefinition('Component', C_OBJECTPREFIX, 'Component')
|
|
|
|
module.addobject(ci_object)
|
|
|
|
module.addobject(c_object)
|
|
|
|
|
|
|
|
# Create the generator classes used to populate the lists
|
2002-03-24 20:32:17 -04:00
|
|
|
Function = OSErrWeakLinkFunctionGenerator
|
|
|
|
Method = OSErrWeakLinkMethodGenerator
|
1995-11-30 11:03:09 -04:00
|
|
|
|
|
|
|
# Create and populate the lists
|
|
|
|
functions = []
|
|
|
|
c_methods = []
|
|
|
|
ci_methods = []
|
|
|
|
execfile(INPUTFILE)
|
|
|
|
|
|
|
|
# add the populated lists to the generator groups
|
|
|
|
# (in a different wordl the scan program would generate this)
|
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in c_methods: c_object.add(f)
|
|
|
|
for f in ci_methods: ci_object.add(f)
|
|
|
|
|
|
|
|
# generate output (open the output file as late as possible)
|
|
|
|
SetOutputFileName(OUTPUTFILE)
|
|
|
|
module.generate()
|