/* check_result.c */

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



#include "rxil.h"



/* NAME
 *		RxilCheckResult
 *
 * SYNOPSIS
 *		RxilCheckResult( rexxmsg );
 *
 *		struct RexxMsg *rexxmsg;
 *
 * FUNCTION
 *		Verify that the secondary result field in a RexxMsg is
 *		appropriatly set.
 *		This should be called for a RexxMsg just prior to replying
 *		it.  This will deal with the case of a result string being
 *		set when the calling program did not request it.
 *		It will be freed, and an error code
 *		set to indicate to the calling program that it should be
 *		requesting a result for this command.
 *
 * INPUTS
 *		rexxmsg = pointer to the RexxMsg structure to be checked.
 *
 * RESULT
 *		None
 *
 * SIDES
 *
 * HISTORY
 *		01-Aug-89	Creation.
 *
 * BUGS
 *
 * SEE ALSO
 *
 */
/* This function will ensure that we have not set a result string
 * to be returned back to ARexx if one was not requested.
 */

void RxilCheckResult( struct RexxMsg *rexxmsg )
{
	/* Make sure that we don't return an argstring
	 * if one was not requested
	 */
	if(  FlagIsSet( rexxmsg->rm_Action, RXFF_RESULT )  )
	{
		/* Result string wanted */
		return;
	}


	/* A result string was not requested.  Let's see if there is one */

	if( (rexxmsg->rm_Result1==0) && (rexxmsg->rm_Result2!=0) )
	{
		/* There is one, so we need to delete it. */
		DeleteArgstring( (struct RexxArg *)(rexxmsg->rm_Result2) );
		rexxmsg->rm_Result2 = 0;

		/* Then send an error back to the ARexx program, telling it
		 * that it needs to request a result, since this command
		 * wants to return one!
		 */
		rexxmsg->rm_Result1 = RXERR_REQUIRES_RESULT_FLAG;
	}
}

