home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Send ARexx Command
- *
- */
-
-
- #include <exec/types.h>
- #include <exec/libraries.h>
- #include <exec/memory.h>
-
- #include <rexx/rxslib.h>
- #include <rexx/errors.h>
-
- #include <proto/exec.h>
- #include <proto/rexxsyslib.h>
-
- #include <string.h>
-
- #include "Arexx.h"
- #include "Requesters.h"
- #include "yak_locale_strings.h"
-
- struct Library *RexxSysBase;
-
-
-
- /*
- * Send an ARexx command
- * This function is slightly modified from Stefan Becker's one used in ToolManager
- */
- LONG
- SendARexxCommand(char *PortName, char *command)
- {
- LONG rc=RC_ERROR;
- struct MsgPort *DummyPort;
-
- /* Open ARexx system library */
- if ((RexxSysBase = (struct Library *)OpenLibrary(RXSNAME,0)) &&
- (DummyPort = CreateMsgPort ()))
- {
- struct RexxMsg *rxmsg;
-
- if (rxmsg=CreateRexxMsg(DummyPort,NULL,NULL))
- {
- if (rxmsg->rm_Args[0]=CreateArgstring(command,strlen(command)))
- {
- struct MsgPort *AREXXPort; /* Port of ARexx resident process */
-
- /* Init Rexx message */
- rxmsg->rm_Action=RXCOMM|RXFF_NOIO;
-
-
- /* Find port and send message */
- Forbid();
-
- if (PortName)
- {
- AREXXPort=FindPort(PortName);
- }
- else
- {
- AREXXPort=FindPort("AREXX");
- }
-
- if (AREXXPort)
- {
- PutMsg(AREXXPort,(struct Message *) rxmsg);
- }
- Permit();
-
- /* Success? */
- if (AREXXPort)
- {
- /* Yes, wait on reply and remove it */
- WaitPort(DummyPort);
- GetMsg(DummyPort);
-
- /* Check return code */
- rc=rxmsg->rm_Result1;
- }
- else
- {
- PostError(getString(AREXX_port_not_found_ERR), PortName);
- }
-
- ClearRexxMsg(rxmsg,1);
- }
- DeleteRexxMsg(rxmsg);
- }
- DeleteMsgPort(DummyPort);
- CloseLibrary(RexxSysBase);
- }
- return(rc);
- }
-
-