ToolChain/bin/targets/m68k-amigaos/ndk/Tutorials/ARexx/Host/Host.c
LONG
DoRexxCommand(const STRPTR Command)
{
	struct MsgPort *ReplyPort;
	struct MsgPort *RexxPort;
	struct RexxMsg *RexxMsg;
	LONG Error;

		/* Create a temporary reply port for the RexxMsg
		 * to build.
		 */

	if(ReplyPort = CreateMsgPort())
	{
			/* Build a RexxMsg we can use. */

		if(RexxMsg = CreateRexxMsg(ReplyPort,NULL,NULL))
		{
				/* The command goes into the first
				 * message argument.
				 */

			if(RexxMsg->rm_Args[0] = CreateArgstring(Command,strlen(Command)))
			{
					/* Mark the message as a command. */

				RexxMsg->rm_Action = RXCOMM;

					/* Now try to find the resident process
					 * communications port. We need to
					 * turn off multitasking while we look
					 * for it and send the message.
					 */

				Forbid();

				if(RexxPort = FindPort(RXSDIR))
				{
					PutMsg(RexxPort,RexxMsg);

					WaitPort(ReplyPort);
					GetMsg(ReplyPort);

					Error = 0;
				}
				else
					Error = ERROR_OBJECT_NOT_FOUND;

				Permit();

				DeleteArgstring(RexxMsg->rm_Args[0]);
			}
			else
				Error = ERROR_NO_FREE_STORE;

			DeleteRexxMsg(RexxMsg);
		}
		else
			Error = ERROR_NO_FREE_STORE;

		DeleteMsgPort(ReplyPort);
	}
	else
		Error = ERROR_NO_FREE_STORE;

	return(Error);
}
/****** Host/DoRexxCommand ***************************************************
*
*   NAME
*       DoRexxCommand -- Send a command to the Rexx resident process.
*
*   SYNOPSIS
*       Error = DoRexxCommand(Command)
*
*       LONG DoRexxCommand(const STRPTR Command);
*
*   FUNCTION
*       A command is sent to the Rexx resident process. In this context
*       "command" either means the name of an ARexx script the resident
*       process is to load and execute or a small one-line program.
*
*   INPUTS
*       Command - Name of command to execute.
*
*   RESULT
*       Error - 0 for success, otherwise an error code.
*
*   SEE ALSO
*       rexxsyslib.library/CreateArgstring
*       rexxsyslib.library/DeleteArgstring
*       rexxsyslib.library/CreateRexxMsg
*       rexxsyslib.library/DeleteRexxMsg
*       exec.library/CreateMsgPort
*       exec.library/DeleteMsgPort
*       exec.library/FindPort
*       exec.library/PutMsg
*       exec.library/WaitPort
*
******************************************************************************
*
*/
Host/DoRexxCommand
NAME
DoRexxCommand -- Send a command to the Rexx resident process.





FUNCTION
A command is sent to the Rexx resident process. In this context
"command" either means the name of an ARexx script the resident
process is to load and execute or a small one-line program.

INPUTS
Command - Name of command to execute.

RESULT
Error - 0 for success, otherwise an error code.


Host / DoRexxCommand NAME DoRexxCommand -- Send a command to the Rexx resident process . FUNCTION A command is sent to the Rexx resident process . In this context " command " either means the name of an ARexx script the resident process is to load and execute or a small one - line program . INPUTS Command - Name of command to execute . RESULT Error - 0 for success otherwise an error code .
LONG
DoRexxCommand(const STRPTR Command)
{
	struct MsgPort *ReplyPort;
	struct MsgPort *RexxPort;
	struct RexxMsg *RexxMsg;
	LONG Error;
	if(ReplyPort = CreateMsgPort())
	{
		if(RexxMsg = CreateRexxMsg(ReplyPort,NULL,NULL))
		{
			if(RexxMsg->rm_Args[0] = CreateArgstring(Command,strlen(Command)))
			{
				RexxMsg->rm_Action = RXCOMM;
				Forbid();
				if(RexxPort = FindPort(RXSDIR))
				{
					PutMsg(RexxPort,RexxMsg);
					WaitPort(ReplyPort);
					GetMsg(ReplyPort);
					Error = 0;
				}
				else
					Error = ERROR_OBJECT_NOT_FOUND;
				Permit();
				DeleteArgstring(RexxMsg->rm_Args[0]);
			}
			else
				Error = ERROR_NO_FREE_STORE;
			DeleteRexxMsg(RexxMsg);
		}
		else
			Error = ERROR_NO_FREE_STORE;
		DeleteMsgPort(ReplyPort);
	}
	else
		Error = ERROR_NO_FREE_STORE;
	return(Error);
}
LONG DoRexxCommand ( const STRPTR Command ) { struct MsgPort * ReplyPort ; struct MsgPort * RexxPort ; struct RexxMsg * RexxMsg ; LONG Error ; if ( ReplyPort = CreateMsgPort ( ) ) { if ( RexxMsg = CreateRexxMsg ( ReplyPort , NULL , NULL ) ) { if ( RexxMsg -> rm_Args [ 0 ] = CreateArgstring ( Command , strlen ( Command ) ) ) { RexxMsg -> rm_Action = RXCOMM ; Forbid ( ) ; if ( RexxPort = FindPort ( RXSDIR ) ) { PutMsg ( RexxPort , RexxMsg ) ; WaitPort ( ReplyPort ) ; GetMsg ( ReplyPort ) ; Error = 0 ; } else Error = ERROR_OBJECT_NOT_FOUND ; Permit ( ) ; DeleteArgstring ( RexxMsg -> rm_Args [ 0 ] ) ; } else Error = ERROR_NO_FREE_STORE ; DeleteRexxMsg ( RexxMsg ) ; } else Error = ERROR_NO_FREE_STORE ; DeleteMsgPort ( ReplyPort ) ; } else Error = ERROR_NO_FREE_STORE ; return ( Error ) ; }
Host/DoRexxCommand
NAME
DoRexxCommand -- Send a command to the Rexx resident process.
Host / DoRexxCommand NAME DoRexxCommand -- Send a command to the Rexx resident process .
/* Create a temporary reply port for the RexxMsg
		 * to build.
		 */ /* Build a RexxMsg we can use. */ /* The command goes into the first
				 * message argument.
				 */ /* Mark the message as a command. */ /* Now try to find the resident process
					 * communications port. We need to
					 * turn off multitasking while we look
					 * for it and send the message.
					 */