diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-07-18 06:16:08 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-07-18 06:16:08 (GMT) |
commit | 182b5aca27d376b08a2904bed42b751496f932f3 (patch) | |
tree | df13115820dbc879c0fe2eae488c9f8c0215a7da /Mac/Modules/snd | |
parent | e6ddc8b20b493fef2e7cffb2e1351fe1d238857e (diff) | |
download | cpython-182b5aca27d376b08a2904bed42b751496f932f3.zip cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.gz cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.bz2 |
Whitespace normalization, via reindent.py.
Diffstat (limited to 'Mac/Modules/snd')
-rw-r--r-- | Mac/Modules/snd/sndscan.py | 222 | ||||
-rw-r--r-- | Mac/Modules/snd/sndsupport.py | 356 |
2 files changed, 289 insertions, 289 deletions
diff --git a/Mac/Modules/snd/sndscan.py b/Mac/Modules/snd/sndscan.py index a287c73..c4a8266 100644 --- a/Mac/Modules/snd/sndscan.py +++ b/Mac/Modules/snd/sndscan.py @@ -10,119 +10,119 @@ sys.path.append(BGENDIR) from scantools import Scanner def main(): - input = "Sound.h" - output = "sndgen.py" - defsoutput = TOOLBOXDIR + "Sound.py" - scanner = SoundScanner(input, output, defsoutput) - scanner.scan() - scanner.close() - print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) - print "=== Done scanning and generating, now doing 'import sndsupport' ===" - import sndsupport - print "=== Done. It's up to you to compile Sndmodule.c ===" + input = "Sound.h" + output = "sndgen.py" + defsoutput = TOOLBOXDIR + "Sound.py" + scanner = SoundScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Testing definitions output code ===" + execfile(defsoutput, {}, {}) + print "=== Done scanning and generating, now doing 'import sndsupport' ===" + import sndsupport + print "=== Done. It's up to you to compile Sndmodule.c ===" class SoundScanner(Scanner): - def destination(self, type, name, arglist): - classname = "SndFunction" - listname = "functions" - if arglist: - t, n, m = arglist[0] - if t == "SndChannelPtr" and m == "InMode": - classname = "SndMethod" - listname = "sndmethods" - return classname, listname - - def writeinitialdefs(self): - self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") - - def makeblacklistnames(self): - return [ - 'SndDisposeChannel', # automatic on deallocation - 'SndAddModifier', # for internal use only - 'SndPlayDoubleBuffer', # very low level routine - # Missing from libraries (UH332) - 'SoundManagerSetInfo', - 'SoundManagerGetInfo', - # Constants with funny definitions - 'rate48khz', - 'rate44khz', - 'kInvalidSource', - # OS8 only: - 'MACEVersion', - 'SPBRecordToFile', - 'Exp1to6', - 'Comp6to1', - 'Exp1to3', - 'Comp3to1', - 'SndControl', - 'SndStopFilePlay', - 'SndStartFilePlay', - 'SndPauseFilePlay', - 'SndRecordToFile', - - ] - - def makeblacklisttypes(self): - return [ - "GetSoundVol", - "SetSoundVol", - "UnsignedFixed", - # Don't have the time to dig into this... - "Component", - "ComponentInstance", - "SoundComponentDataPtr", - "SoundComponentData", - "SoundComponentData_ptr", - "SoundConverter", - ] - - def makerepairinstructions(self): - return [ - ([("Str255", "*", "InMode")], - [("*", "*", "OutMode")]), - - ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], - [("InBuffer", "*", "*")]), - - ([("void", "*", "OutMode"), ("long", "*", "InMode"), - ("long", "*", "OutMode")], - [("VarVarOutBuffer", "*", "InOutMode")]), - - ([("SCStatusPtr", "*", "InMode")], - [("SCStatus", "*", "OutMode")]), - - ([("SMStatusPtr", "*", "InMode")], - [("SMStatus", "*", "OutMode")]), - - ([("CompressionInfoPtr", "*", "InMode")], - [("CompressionInfo", "*", "OutMode")]), - - # For SndPlay's SndListHandle argument - ([("Handle", "sndHdl", "InMode")], - [("SndListHandle", "*", "*")]), - - # For SndStartFilePlay - ([("long", "bufferSize", "InMode"), ("void", "theBuffer", "OutMode")], - [("*", "*", "*"), ("FakeType('0')", "*", "InMode")]), - - # For Comp3to1 etc. - ([("void_ptr", "inBuffer", "InMode"), - ("void", "outBuffer", "OutMode"), - ("unsigned_long", "cnt", "InMode")], - [("InOutBuffer", "buffer", "InOutMode")]), - - # Ditto -## ([("void_ptr", "inState", "InMode"), ("void", "outState", "OutMode")], -## [("InOutBuf128", "state", "InOutMode")]), - ([("StateBlockPtr", "inState", "InMode"), ("StateBlockPtr", "outState", "InMode")], - [("StateBlock", "state", "InOutMode")]), - - # Catch-all for the last couple of void pointers - ([("void", "*", "OutMode")], - [("void_ptr", "*", "InMode")]), - ] + def destination(self, type, name, arglist): + classname = "SndFunction" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "SndChannelPtr" and m == "InMode": + classname = "SndMethod" + listname = "sndmethods" + return classname, listname + + def writeinitialdefs(self): + self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") + + def makeblacklistnames(self): + return [ + 'SndDisposeChannel', # automatic on deallocation + 'SndAddModifier', # for internal use only + 'SndPlayDoubleBuffer', # very low level routine + # Missing from libraries (UH332) + 'SoundManagerSetInfo', + 'SoundManagerGetInfo', + # Constants with funny definitions + 'rate48khz', + 'rate44khz', + 'kInvalidSource', + # OS8 only: + 'MACEVersion', + 'SPBRecordToFile', + 'Exp1to6', + 'Comp6to1', + 'Exp1to3', + 'Comp3to1', + 'SndControl', + 'SndStopFilePlay', + 'SndStartFilePlay', + 'SndPauseFilePlay', + 'SndRecordToFile', + + ] + + def makeblacklisttypes(self): + return [ + "GetSoundVol", + "SetSoundVol", + "UnsignedFixed", + # Don't have the time to dig into this... + "Component", + "ComponentInstance", + "SoundComponentDataPtr", + "SoundComponentData", + "SoundComponentData_ptr", + "SoundConverter", + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("SCStatusPtr", "*", "InMode")], + [("SCStatus", "*", "OutMode")]), + + ([("SMStatusPtr", "*", "InMode")], + [("SMStatus", "*", "OutMode")]), + + ([("CompressionInfoPtr", "*", "InMode")], + [("CompressionInfo", "*", "OutMode")]), + + # For SndPlay's SndListHandle argument + ([("Handle", "sndHdl", "InMode")], + [("SndListHandle", "*", "*")]), + + # For SndStartFilePlay + ([("long", "bufferSize", "InMode"), ("void", "theBuffer", "OutMode")], + [("*", "*", "*"), ("FakeType('0')", "*", "InMode")]), + + # For Comp3to1 etc. + ([("void_ptr", "inBuffer", "InMode"), + ("void", "outBuffer", "OutMode"), + ("unsigned_long", "cnt", "InMode")], + [("InOutBuffer", "buffer", "InOutMode")]), + + # Ditto +## ([("void_ptr", "inState", "InMode"), ("void", "outState", "OutMode")], +## [("InOutBuf128", "state", "InOutMode")]), + ([("StateBlockPtr", "inState", "InMode"), ("StateBlockPtr", "outState", "InMode")], + [("StateBlock", "state", "InOutMode")]), + + # Catch-all for the last couple of void pointers + ([("void", "*", "OutMode")], + [("void_ptr", "*", "InMode")]), + ] if __name__ == "__main__": - main() + main() diff --git a/Mac/Modules/snd/sndsupport.py b/Mac/Modules/snd/sndsupport.py index 99df5be..cf0fa6c 100644 --- a/Mac/Modules/snd/sndsupport.py +++ b/Mac/Modules/snd/sndsupport.py @@ -27,12 +27,12 @@ initstuff = initstuff + """ # define types used for arguments (in addition to standard and macsupport types) class SndChannelPtrType(OpaqueByValueType): - def declare(self, name): - # Initializing all SndChannelPtr objects to 0 saves - # special-casing NewSndChannel(), where it is formally an - # input-output parameter but we treat it as output-only - # (since Python users are not supposed to allocate memory) - Output("SndChannelPtr %s = 0;", name) + def declare(self, name): + # Initializing all SndChannelPtr objects to 0 saves + # special-casing NewSndChannel(), where it is formally an + # input-output parameter but we treat it as output-only + # (since Python users are not supposed to allocate memory) + Output("SndChannelPtr %s = 0;", name) SndChannelPtr = SndChannelPtrType('SndChannelPtr', 'SndCh') @@ -49,28 +49,28 @@ ModalFilterUPP = FakeType("(ModalFilterUPP)0") void_ptr = Type("void *", "w") class SndCallBackType(InputOnlyType): - def __init__(self): - Type.__init__(self, 'PyObject*', 'O') - def getargsCheck(self, name): - Output("if (%s != Py_None && !PyCallable_Check(%s))", name, name) - OutLbrace() - Output('PyErr_SetString(PyExc_TypeError, "callback must be callable");') - Output("goto %s__error__;", name) - OutRbrace() - def passInput(self, name): - return "NewSndCallBackUPP(SndCh_UserRoutine)" - def cleanup(self, name): - # XXX This knows it is executing inside the SndNewChannel wrapper - Output("if (_res != NULL && %s != Py_None)", name) - OutLbrace() - Output("SndChannelObject *p = (SndChannelObject *)_res;") - Output("p->ob_itself->userInfo = (long)p;") - Output("Py_INCREF(%s);", name) - Output("p->ob_callback = %s;", name) - OutRbrace() - DedentLevel() - Output(" %s__error__: ;", name) - IndentLevel() + def __init__(self): + Type.__init__(self, 'PyObject*', 'O') + def getargsCheck(self, name): + Output("if (%s != Py_None && !PyCallable_Check(%s))", name, name) + OutLbrace() + Output('PyErr_SetString(PyExc_TypeError, "callback must be callable");') + Output("goto %s__error__;", name) + OutRbrace() + def passInput(self, name): + return "NewSndCallBackUPP(SndCh_UserRoutine)" + def cleanup(self, name): + # XXX This knows it is executing inside the SndNewChannel wrapper + Output("if (_res != NULL && %s != Py_None)", name) + OutLbrace() + Output("SndChannelObject *p = (SndChannelObject *)_res;") + Output("p->ob_itself->userInfo = (long)p;") + Output("Py_INCREF(%s);", name) + Output("p->ob_callback = %s;", name) + OutRbrace() + DedentLevel() + Output(" %s__error__: ;", name) + IndentLevel() SndCallBackProcPtr = SndCallBackType() SndCallBackUPP = SndCallBackProcPtr @@ -95,16 +95,16 @@ includestuff = includestuff + """ static int SndCmd_Convert(PyObject *v, SndCommand *pc) { - int len; - pc->param1 = 0; - pc->param2 = 0; - if (PyTuple_Check(v)) { - if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) - return 1; - PyErr_Clear(); - return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); - } - return PyArg_Parse(v, "H", &pc->cmd); + int len; + pc->param1 = 0; + pc->param2 = 0; + if (PyTuple_Check(v)) { + if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) + return 1; + PyErr_Clear(); + return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); + } + return PyArg_Parse(v, "H", &pc->cmd); } static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ @@ -117,62 +117,62 @@ finalstuff = finalstuff + """ static int SndCh_CallCallBack(void *arg) { - SndChannelObject *p = (SndChannelObject *)arg; - PyObject *args; - PyObject *res; - args = Py_BuildValue("(O(hhl))", - p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); - res = PyEval_CallObject(p->ob_callback, args); - Py_DECREF(args); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; + SndChannelObject *p = (SndChannelObject *)arg; + PyObject *args; + PyObject *res; + args = Py_BuildValue("(O(hhl))", + p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); + res = PyEval_CallObject(p->ob_callback, args); + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; } /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) { - SndChannelObject *p = (SndChannelObject *)(chan->userInfo); - if (p->ob_callback != NULL) { - long A5 = SetA5(p->ob_A5); - p->ob_cmd = *cmd; - Py_AddPendingCall(SndCh_CallCallBack, (void *)p); - SetA5(A5); - } + SndChannelObject *p = (SndChannelObject *)(chan->userInfo); + if (p->ob_callback != NULL) { + long A5 = SetA5(p->ob_A5); + p->ob_cmd = *cmd; + Py_AddPendingCall(SndCh_CallCallBack, (void *)p); + SetA5(A5); + } } /* SPB callbacks - Schedule callbacks to Python */ static int SPB_CallCallBack(void *arg) { - SPBObject *p = (SPBObject *)arg; - PyObject *args; - PyObject *res; - - if ( p->ob_thiscallback == 0 ) return 0; - args = Py_BuildValue("(O)", p); - res = PyEval_CallObject(p->ob_thiscallback, args); - p->ob_thiscallback = 0; - Py_DECREF(args); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; + SPBObject *p = (SPBObject *)arg; + PyObject *args; + PyObject *res; + + if ( p->ob_thiscallback == 0 ) return 0; + args = Py_BuildValue("(O)", p); + res = PyEval_CallObject(p->ob_thiscallback, args); + p->ob_thiscallback = 0; + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; } static pascal void SPB_completion(SPBPtr my_spb) { - SPBObject *p = (SPBObject *)(my_spb->userLong); - - if (p && p->ob_completion) { - long A5 = SetA5(p->ob_A5); - p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */ - Py_AddPendingCall(SPB_CallCallBack, (void *)p); - SetA5(A5); - } + SPBObject *p = (SPBObject *)(my_spb->userLong); + + if (p && p->ob_completion) { + long A5 = SetA5(p->ob_A5); + p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */ + Py_AddPendingCall(SPB_CallCallBack, (void *)p); + SetA5(A5); + } } """ @@ -182,110 +182,110 @@ SPB_completion(SPBPtr my_spb) class SndObjectDefinition(PEP252Mixin, ObjectDefinition): - def outputStructMembers(self): - ObjectDefinition.outputStructMembers(self) - Output("/* Members used to implement callbacks: */") - Output("PyObject *ob_callback;") - Output("long ob_A5;"); - Output("SndCommand ob_cmd;") - - def outputInitStructMembers(self): - ObjectDefinition.outputInitStructMembers(self) - Output("it->ob_callback = NULL;") - Output("it->ob_A5 = SetCurrentA5();"); - - def outputCleanupStructMembers(self): - ObjectDefinition.outputCleanupStructMembers(self) - Output("Py_XDECREF(self->ob_callback);") - - def outputFreeIt(self, itselfname): - Output("SndDisposeChannel(%s, 1);", itselfname) - - def outputConvert(self): - pass # Not needed - + def outputStructMembers(self): + ObjectDefinition.outputStructMembers(self) + Output("/* Members used to implement callbacks: */") + Output("PyObject *ob_callback;") + Output("long ob_A5;"); + Output("SndCommand ob_cmd;") + + def outputInitStructMembers(self): + ObjectDefinition.outputInitStructMembers(self) + Output("it->ob_callback = NULL;") + Output("it->ob_A5 = SetCurrentA5();"); + + def outputCleanupStructMembers(self): + ObjectDefinition.outputCleanupStructMembers(self) + Output("Py_XDECREF(self->ob_callback);") + + def outputFreeIt(self, itselfname): + Output("SndDisposeChannel(%s, 1);", itselfname) + + def outputConvert(self): + pass # Not needed + # class SpbObjectDefinition(PEP252Mixin, ObjectDefinition): - getsetlist = [ - ( - 'inRefNum', - 'return Py_BuildValue("l", self->ob_spb.inRefNum);', - 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);', - None, - ), ( - 'count', - 'return Py_BuildValue("l", self->ob_spb.count);', - 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);', - None - ), ( - 'milliseconds', - 'return Py_BuildValue("l", self->ob_spb.milliseconds);', - 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);', - None, - ), ( - 'error', - 'return Py_BuildValue("h", self->ob_spb.error);', - None, - None - ), ( - 'completionRoutine', - None, - """self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion); - self->ob_completion = v; - Py_INCREF(v); - return 0;""", - None, - )] - - def outputStructMembers(self): - Output("/* Members used to implement callbacks: */") - Output("PyObject *ob_completion;") - Output("PyObject *ob_interrupt;") - Output("PyObject *ob_thiscallback;"); - Output("long ob_A5;") - Output("SPB ob_spb;") - - def outputNew(self): - Output() - Output("%sPyObject *%s_New(void)", self.static, self.prefix) - OutLbrace() - Output("%s *it;", self.objecttype) - self.outputCheckNewArg() - Output("it = PyObject_NEW(%s, &%s);", self.objecttype, self.typename) - Output("if (it == NULL) return NULL;") - self.outputInitStructMembers() - Output("return (PyObject *)it;") - OutRbrace() - - def outputInitStructMembers(self): - Output("it->ob_completion = NULL;") - Output("it->ob_interrupt = NULL;") - Output("it->ob_thiscallback = NULL;") - Output("it->ob_A5 = SetCurrentA5();") - Output("memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));") - Output("it->ob_spb.userLong = (long)it;") - - def outputCleanupStructMembers(self): - ObjectDefinition.outputCleanupStructMembers(self) - Output("self->ob_spb.userLong = 0;") - Output("self->ob_thiscallback = 0;") - Output("Py_XDECREF(self->ob_completion);") - Output("Py_XDECREF(self->ob_interrupt);") - - def outputConvert(self): - Output("%sint %s_Convert(PyObject *v, %s *p_itself)", self.static, self.prefix, self.itselftype) - OutLbrace() - self.outputCheckConvertArg() - Output("if (!%s_Check(v))", self.prefix) - OutLbrace() - Output('PyErr_SetString(PyExc_TypeError, "%s required");', self.name) - Output("return 0;") - OutRbrace() - Output("*p_itself = &((%s *)v)->ob_spb;", self.objecttype) - Output("return 1;") - OutRbrace() - + getsetlist = [ + ( + 'inRefNum', + 'return Py_BuildValue("l", self->ob_spb.inRefNum);', + 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);', + None, + ), ( + 'count', + 'return Py_BuildValue("l", self->ob_spb.count);', + 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);', + None + ), ( + 'milliseconds', + 'return Py_BuildValue("l", self->ob_spb.milliseconds);', + 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);', + None, + ), ( + 'error', + 'return Py_BuildValue("h", self->ob_spb.error);', + None, + None + ), ( + 'completionRoutine', + None, + """self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion); + self->ob_completion = v; + Py_INCREF(v); + return 0;""", + None, + )] + + def outputStructMembers(self): + Output("/* Members used to implement callbacks: */") + Output("PyObject *ob_completion;") + Output("PyObject *ob_interrupt;") + Output("PyObject *ob_thiscallback;"); + Output("long ob_A5;") + Output("SPB ob_spb;") + + def outputNew(self): + Output() + Output("%sPyObject *%s_New(void)", self.static, self.prefix) + OutLbrace() + Output("%s *it;", self.objecttype) + self.outputCheckNewArg() + Output("it = PyObject_NEW(%s, &%s);", self.objecttype, self.typename) + Output("if (it == NULL) return NULL;") + self.outputInitStructMembers() + Output("return (PyObject *)it;") + OutRbrace() + + def outputInitStructMembers(self): + Output("it->ob_completion = NULL;") + Output("it->ob_interrupt = NULL;") + Output("it->ob_thiscallback = NULL;") + Output("it->ob_A5 = SetCurrentA5();") + Output("memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));") + Output("it->ob_spb.userLong = (long)it;") + + def outputCleanupStructMembers(self): + ObjectDefinition.outputCleanupStructMembers(self) + Output("self->ob_spb.userLong = 0;") + Output("self->ob_thiscallback = 0;") + Output("Py_XDECREF(self->ob_completion);") + Output("Py_XDECREF(self->ob_interrupt);") + + def outputConvert(self): + Output("%sint %s_Convert(PyObject *v, %s *p_itself)", self.static, self.prefix, self.itselftype) + OutLbrace() + self.outputCheckConvertArg() + Output("if (!%s_Check(v))", self.prefix) + OutLbrace() + Output('PyErr_SetString(PyExc_TypeError, "%s required");', self.name) + Output("return 0;") + OutRbrace() + Output("*p_itself = &((%s *)v)->ob_spb;", self.objecttype) + Output("return 1;") + OutRbrace() + sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr') spbobject = SpbObjectDefinition('SPB', 'SPBObj', 'SPBPtr') |