diff options
Diffstat (limited to 'Mac/Contrib/osam')
-rw-r--r-- | Mac/Contrib/osam/OSAm.c | 277 | ||||
-rw-r--r-- | Mac/Contrib/osam/OSAm.exp | 1 | ||||
-rw-r--r-- | Mac/Contrib/osam/OSAm.h | 30 | ||||
-rw-r--r-- | Mac/Contrib/osam/OSAm.prj | bin | 71523 -> 0 bytes | |||
-rw-r--r-- | Mac/Contrib/osam/ScriptRunner.c | 310 | ||||
-rw-r--r-- | Mac/Contrib/osam/ScriptRunner.h | 30 |
6 files changed, 0 insertions, 648 deletions
diff --git a/Mac/Contrib/osam/OSAm.c b/Mac/Contrib/osam/OSAm.c deleted file mode 100644 index aa9a5da..0000000 --- a/Mac/Contrib/osam/OSAm.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * - * This is a simple module to allow the - * user to compile and execute an applescript - * which is passed in as a text item. - * - * Sean Hummel <seanh@prognet.com> - * 1/20/98 - * RealNetworks - * - * Jay Painter <jpaint@serv.net> <jpaint@gimp.org> <jpaint@real.com> - * - * - */ -#include "OSAm.h" -#include "ScriptRunner.h" -#include <AppleEvents.h> - - - -/* - * Boiler plate generated from "genmodule.py" - */ -static PyObject *ErrorObject; -static char OSAm_DoCommand__doc__[] = ""; - - - -static PyObject * -OSAm_RunCompiledScript (self, args) - PyObject *self; - PyObject *args; -{ - char *commandStr = NULL; - char *outpath = NULL; - OSErr myErr; - AEDesc temp; - EventRecord event; - - temp.dataHandle = NULL; - - if (!PyArg_ParseTuple (args, "s", &commandStr)) - return NULL; - - myErr = ExecuteScriptFile (commandStr, NULL, &temp); - - if (temp.dataHandle != NULL && temp.descriptorType == 'TEXT') - { - char *line; - DescType typeCode; - long dataSize = 0; - OSErr err; - - dataSize = AEGetDescDataSize (&temp); - - if (dataSize > 0) - { - PyObject *result = PyString_FromStringAndSize (NULL, - dataSize); - - - if (!result) - { - printf ("OSAm.error Out of memory.\n"); - Py_INCREF (Py_None); - AEDisposeDesc (&temp); - return Py_None; - } - if ( (err=AEGetDescData(&temp, PyString_AS_STRING(result), dataSize)) < 0 ) - { - AEDisposeDesc(&temp); - return PyMac_Error(err); - } - - AEDisposeDesc(&temp); - return result; - } - } - - if (myErr != noErr) - { - PyErr_Mac (ErrorObject, myErr); - return NULL; - } - - - Py_INCREF (Py_None); - return Py_None; -} - - - - -static PyObject * -OSAm_CompileAndSave (self, args) - PyObject *self; - PyObject *args; -{ - char *commandStr = NULL; - char *outpath = NULL; - OSErr myErr; - AEDesc temp; - EventRecord event; - - temp.dataHandle = NULL; - - if (!PyArg_ParseTuple (args, "ss", &commandStr, &outpath)) - return NULL; - - myErr = CompileAndSave (commandStr, outpath, NULL, &temp); - - - if (temp.dataHandle != NULL && temp.descriptorType == 'TEXT') - { - char *line; - DescType typeCode; - long dataSize = 0; - OSErr err; - - dataSize = AEGetDescDataSize (&temp); - - if (dataSize > 0) - { - PyObject *result = PyString_FromStringAndSize (NULL, - dataSize); - - - if (!result) - { - printf ("OSAm.error Out of memory.\n"); - Py_INCREF (Py_None); - AEDisposeDesc (&temp); - return Py_None; - } - if ( (err=AEGetDescData(&temp, PyString_AS_STRING(result), dataSize)) < 0 ) - { - AEDisposeDesc(&temp); - return PyMac_Error(err); - } - - AEDisposeDesc(&temp); - return result; - } - } - - if (myErr != noErr) - { - - PyErr_Mac (ErrorObject, myErr); - return NULL; - } - - - Py_INCREF (Py_None); - return Py_None; -} - - - -static PyObject * -OSAm_CompileAndExecute (self, args) - PyObject *self; - PyObject *args; -{ - char *commandStr; - OSErr myErr; - AEDesc temp; - EventRecord event; - - temp.dataHandle = NULL; - - if (!PyArg_ParseTuple (args, "s", &commandStr)) - return NULL; - - myErr = CompileAndExecute (commandStr, &temp, NULL); - - if (temp.dataHandle != NULL && temp.descriptorType == 'TEXT') - { - char *line; - DescType typeCode; - long dataSize = 0; - OSErr err; - - dataSize = AEGetDescDataSize (&temp); - - if (dataSize > 0) - { - PyObject *result = PyString_FromStringAndSize (NULL, - dataSize); - - - if (!result) - { - printf ("OSAm.error Out of memory.\n"); - Py_INCREF (Py_None); - AEDisposeDesc (&temp); - return Py_None; - } - if ( (err=AEGetDescData(&temp, PyString_AS_STRING(result), dataSize)) < 0 ) - { - AEDisposeDesc(&temp); - return PyMac_Error(err); - } - - AEDisposeDesc(&temp); - return result; - } - } - - if (myErr != noErr) - { - - PyErr_Mac (ErrorObject, myErr); - return NULL; - } - - - Py_INCREF (Py_None); - return Py_None; -} - - - -/* - * List of methods defined in the module - */ -static struct PyMethodDef OSAm_methods[] = -{ - {"CompileAndExecute", - (PyCFunction) OSAm_CompileAndExecute, - METH_VARARGS, - OSAm_DoCommand__doc__}, -#if 0 - {"CompileAndSave", - (PyCFunction) OSAm_CompileAndSave, - METH_VARARGS, - OSAm_DoCommand__doc__}, - - {"RunCompiledScript", - (PyCFunction) OSAm_RunCompiledScript, - METH_VARARGS, - OSAm_DoCommand__doc__}, -#endif - - {NULL, (PyCFunction) NULL, 0, NULL} -}; - - - -static char OSAm_module_documentation[] = ""; - - -/* - * PYTHON Module Initalization - */ -void -initOSAm () -{ - PyObject *m, *d; - - /* Create the module and add the functions */ - m = Py_InitModule4 ("OSAm", - OSAm_methods, - OSAm_module_documentation, - (PyObject *) NULL, PYTHON_API_VERSION); - - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict (m); - ErrorObject = PyString_FromString ("OSAm.error"); - PyDict_SetItemString (d, "error", ErrorObject); - - - /* Check for errors */ - if (PyErr_Occurred ()) - Py_FatalError ("can't initialize module OSAm"); -} diff --git a/Mac/Contrib/osam/OSAm.exp b/Mac/Contrib/osam/OSAm.exp deleted file mode 100644 index d567a95..0000000 --- a/Mac/Contrib/osam/OSAm.exp +++ /dev/null @@ -1 +0,0 @@ -initOSAm diff --git a/Mac/Contrib/osam/OSAm.h b/Mac/Contrib/osam/OSAm.h deleted file mode 100644 index 2fd0469..0000000 --- a/Mac/Contrib/osam/OSAm.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * This is a simple module to allow the - * user to compile and execute an applescript - * which is passed in as a text item. - * - * Sean Hummel <seanh@prognet.com> - * 1/20/98 - * RealNetworks - * - * Jay Painter <jpaint@serv.net> <jpaint@gimp.org> <jpaint@real.com> - * - * - */ - -#pragma once - - -/* Python API */ -#include "Python.h" -#include "macglue.h" - - -/* Macintosh API */ -#include <Types.h> -#include <AppleEvents.h> -#include <Processes.h> -#include <Files.h> -#include <Gestalt.h> -#include <Events.h> diff --git a/Mac/Contrib/osam/OSAm.prj b/Mac/Contrib/osam/OSAm.prj Binary files differdeleted file mode 100644 index 527563c..0000000 --- a/Mac/Contrib/osam/OSAm.prj +++ /dev/null diff --git a/Mac/Contrib/osam/ScriptRunner.c b/Mac/Contrib/osam/ScriptRunner.c deleted file mode 100644 index 6f7d9ce..0000000 --- a/Mac/Contrib/osam/ScriptRunner.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * - * This is a simple module to allow the - * user to compile and execute an applescript - * which is passed in as a text item. - * - * Sean Hummel <seanh@prognet.com> - * 1/20/98 - * RealNetworks - * - * Jay Painter <jpaint@serv.net> <jpaint@gimp.org> <jpaint@real.com> - * - * - */ - -#include <Resources.h> -#include <Files.h> -#include <OSA.h> -#include <string.h> -#include "ScriptRunner.h" -#include <script.h> -#include <resources.h> - -#ifdef TARGET_API_MAC_CARBON -static -p2cstr(StringPtr p) -{ - unsigned char *c = p; - int len = c[0]; - strncpy((char *)c+1, (char *)c, len); - c[len] = 0; -} - -static c2pstr(const char *cc) -{ - char *c = (char *)cc; /* Ouch */ - int len = strlen(c); - - if ( len > 255 ) len = 255; - strncpy(c, c+1, len); - c[0] = len; -} -#endif - -OSAError LoadScriptingComponent (ComponentInstance * scriptingComponent); - -#if 0 -/* - * store the script as a compile script so that OSA - * components may load and execute the script easily - */ -OSAError -CompileAndSave (const char *text, - const char *outfile, - OSAActiveUPP proc, - AEDesc * result) -{ - - OSAError err2 = 0; - AEDesc theScript; - OSAID compiledScriptID = 0; - ComponentInstance scriptingComponent; - FSSpec outfilespec; - AEDesc theCompiledScript; - OSAID scriptid = kOSANullScript; - short saveres = 0; - - - - /* Initialize theScript here because it is a struct */ - theScript.dataHandle = NULL; - theCompiledScript.dataHandle = NULL; - - - /* open the component manager */ - err2 = LoadScriptingComponent (&scriptingComponent); - if (err2) - return err2; /* <<< Fail quietly?? */ - - - /* construct the AppleEvent Descriptor to contain the text of script */ - AECreateDesc ('TEXT', text, strlen (text), &theScript); - - err2 = OSACompile (scriptingComponent, - &theScript, - kOSAModeCompileIntoContext, - &scriptid); - if (err2) - { - OSAScriptError (scriptingComponent, kOSAErrorMessage, 'TEXT', result); - goto CleanUp; - } - - - err2 = OSAStore (scriptingComponent, - scriptid, - typeOSAGenericStorage, - kOSAModeCompileIntoContext, - &theCompiledScript); - if (err2) - { - OSAScriptError (scriptingComponent, kOSAErrorMessage, 'TEXT', result); - goto CleanUp; - } - - - c2pstr (outfile); - FSMakeFSSpec (0, 0, (StringPtr) outfile, &outfilespec); - p2cstr ((StringPtr) outfile); - - FSpDelete (&outfilespec); - - FSpCreateResFile (&outfilespec, 'ToyS', 'osas', smRoman); - - saveres = CurResFile (); - - if (saveres) - { - short myres = 0; - myres = FSpOpenResFile (&outfilespec, fsWrPerm); - - UseResFile (myres); - AddResource (theCompiledScript.dataHandle, 'scpt', 128, "\p"); - CloseResFile (myres); - UseResFile (saveres); - } - - -CleanUp: - - if (theScript.dataHandle) - AEDisposeDesc (&theScript); - - if (theCompiledScript.dataHandle) - AEDisposeDesc (&theCompiledScript); - - if (scriptid) - OSADispose (scriptingComponent, scriptid); - - if (scriptingComponent != 0) - CloseComponent (scriptingComponent); - - - return err2; -} -#endif - - -OSAError -CompileAndExecute (const char *text, - AEDesc * result, - OSAActiveUPP proc) -{ - OSAError err2 = 0; - AEDesc theScript; - OSAID compiledScriptID = 0; - ComponentInstance scriptingComponent; - - - /* initialize theScript here because it is a struct */ - theScript.dataHandle = NULL; - - /* Open the component manager */ - err2 = LoadScriptingComponent (&scriptingComponent); - if (err2) - return err2; /* <<< Fail quietly?? */ - - - /* construct the AppleEvent Descriptor to contain the text of script */ - AECreateDesc ('TEXT', text, strlen (text), &theScript); - - - err2 = OSASetActiveProc (scriptingComponent, proc, NULL); - if (err2) - goto CleanUp; - - - err2 = OSADoScript (scriptingComponent, &theScript, kOSANullScript, 'TEXT', 0, result); - if (err2) - { - OSAScriptError (scriptingComponent, kOSAErrorMessage, 'TEXT', result); - goto CleanUp; - } - - -CleanUp: - - if (theScript.dataHandle) - AEDisposeDesc (&theScript); - - if (scriptingComponent != 0) - CloseComponent (scriptingComponent); - - - return err2; -} - -#if 0 -/* - * This routine reads in a saved script file and executes - * the script contained within (from a 'scpt' resource.) - */ -OSAError -ExecuteScriptFile (const char *theFilePath, - OSAActiveUPP proc, - AEDesc * result) -{ - OSAError err2; - short resRefCon; - AEDesc theScript; - OSAID compiledScriptID, scriptResultID; - ComponentInstance scriptingComponent; - FSSpec theFile; - - - c2pstr (theFilePath); - FSMakeFSSpec (0, 0, (StringPtr) theFilePath, &theFile); - p2cstr ((StringPtr) theFilePath); - - - /* open a connection to the OSA */ - err2 = LoadScriptingComponent (&scriptingComponent); - if (err2) - return err2; /* <<< Fail quietly?? */ - - - err2 = OSASetActiveProc (scriptingComponent, proc, NULL); - if (err2) - goto error; - - - /* now, try and read in the script - * Open the script file and get the resource - */ - resRefCon = FSpOpenResFile (&theFile, fsRdPerm); - if (resRefCon == -1) - return ResError (); - - theScript.dataHandle = Get1IndResource (typeOSAGenericStorage, 1); - - if ((err2 = ResError ()) || (err2 = resNotFound, theScript.dataHandle == NULL)) - { - CloseResFile (resRefCon); - return err2; - } - - theScript.descriptorType = typeOSAGenericStorage; - DetachResource (theScript.dataHandle); - CloseResFile (resRefCon); - err2 = noErr; - - - /* give a copy of the script to AppleScript */ - err2 = OSALoad (scriptingComponent, - &theScript, - 0L, - &compiledScriptID); - if (err2) - goto error; - - AEDisposeDesc (&theScript); - theScript.dataHandle = NULL; - - - err2 = OSAExecute (scriptingComponent, - compiledScriptID, - kOSANullScript, - 0, - &scriptResultID); - - if (compiledScriptID) - OSAScriptError (scriptingComponent, kOSAErrorMessage, 'TEXT', result); - - if (err2) - goto error; - - /* If there was an error, return it. If there was a result, return it. */ - (void) OSADispose (scriptingComponent, compiledScriptID); - - if (err2) - goto error; - else - goto done; - -error: - if (theScript.dataHandle) - AEDisposeDesc (&theScript); - - -done: - - - return err2; -} -#endif - - -OSAError -LoadScriptingComponent (ComponentInstance * scriptingComponent) -{ - OSAError err2; - - /* Open a connection to the Open Scripting Architecture */ - *scriptingComponent = OpenDefaultComponent (kOSAComponentType, - kOSAGenericScriptingComponentSubtype); - - err2 = GetComponentInstanceError (*scriptingComponent); - - return err2; -} diff --git a/Mac/Contrib/osam/ScriptRunner.h b/Mac/Contrib/osam/ScriptRunner.h deleted file mode 100644 index dda7bbb..0000000 --- a/Mac/Contrib/osam/ScriptRunner.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * This is a simple module to allow the - * user to compile and execute an applescript - * which is passed in as a text item. - * - * Sean Hummel <seanh@prognet.com> - * 1/20/98 - * RealNetworks - * - * Jay Painter <jpaint@serv.net> <jpaint@gimp.org> <jpaint@real.com> - * - * - */ -#pragma once - -#include <OSA.h> - -OSAError CompileAndExecute (const char *text, - AEDesc *result, - OSAActiveUPP proc); - -OSAError CompileAndSave (const char *text, - const char *outfile, - OSAActiveUPP proc, - AEDesc *result); - -OSAError ExecuteScriptFile (const char *theFile, - OSAActiveUPP proc, - AEDesc *result); |