/*   to_rexx.c	*/

/*		Copyright © 1989 by Donald T. Meyer, Stormgate Software
 *		All Rights Reserved
 */



#include "rxil.h"



/* NAME
 *		RxilToRexx
 *
 * SYNOPSIS
 *		result = RxilToRexx( cmd, arg0, arg1, arg2, arg3 );
 *
 *		LONG result
 *
 *		ULONG cmd
 *		STRPTR arg0
 *		STRPTR arg1
 *		STRPTR arg2
 *		STRPTR arg3
 *
 * FUNCTION
 *		Send a command packet to the Rexx Master.
 *		This is an asynchronous send, no success or failure will be
 *		observed.
 *
 * INPUTS
 *		cmd = the command to send.
 *		arg0 = a null-terminated string to convert into an Argstring.
 *		arg1 = a null-terminated string to convert into an Argstring.
 *		arg2 = a null-terminated string to convert into an Argstring.
 *		arg3 = a null-terminated string to convert into an Argstring.
 *
 * RESULT
 *		Zero for success, non-zero to indicate failure.
 *
 * SIDES
 *
 * HISTORY
 *		01-Aug-89	Creation.
 *
 * BUGS
 *
 * SEE ALSO
 *
 */
 
LONG RxilToRexx( ULONG cmd,
	STRPTR arg0, STRPTR arg1, STRPTR arg2, STRPTR arg3 )
{
	struct MsgPort *rmast = NULL;
	struct RexxMsg *rexxmsg;
 
 
	/* Allocate a packet to send to rexxmaster */
	rexxmsg = CreateRexxMsg( NULL, NULL, NULL );
	if( rexxmsg == NULL )
	{
		return( 1 );
	}
 
	rexxmsg->rm_Action = cmd | RXFF_NONRET;
 
	rexxmsg->rm_Args[0] = arg0;
	rexxmsg->rm_Args[1] = arg1;
	rexxmsg->rm_Args[2] = arg2;
	rexxmsg->rm_Args[3] = arg3;
 
	Forbid();
	if(   (  rmast = FindPort( "REXX" )  ) != NULL   )
	{
		PutMsg( rmast, (struct Message *)rexxmsg );
	}
	Permit();
 
	if( rmast == NULL )
	{
		/* we could not find the REXX port, this failed! */
		DeleteRexxMsg( rexxmsg );
		return( 2 );
	}
 
	return( 0 );
}
 
