#ifndef _RCCLAUTOABORT_H_
#define _RCCLAUTOABORT_H_

/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

/*---------------------------------------------------------------------------
 *
 * DESCRIPTION:	Macros to help RCCL primitives handle the option
 *		whereby they call exit() or rciAbort() whenever they 
 *		encounter an error condition.
 *
 *		The problem here is the the code RCCL_ERROR_EXIT also
 *		implies that RCI routines will exit on error as well.
 *		This is because several RCI routines are presented
 *		directly to the RCCL programmer. The problem is that many
 *		RCCL primitives also use RCI routines internally, and
 *		in these cases we do not want to exit on error, since
 *		the RCCL routine wants to catch the error itself.
 *
 *		So these macros help us do the following:
 *
 *		rcclPrimitive()
 *		{
 *		   MASK_RCI_AUTO_ABORT() // mask EXIT_ON_ERROR for RCI calls
 *
 *		   if (error occurred)
 *		    { 			 // unmask EXIT_ON_ERROR for RCI and
 *		      RETURN_ERROR (bad) // return or exit as required 
 *		    }
 *		   else
 *		    {			 // unmask EXIT_ON_ERROR for RCI and
 *		      RETURN_NORMAL (ok) // return normally 
 *		    }
 *		 }
 *		    
 * 
 * AUTHOR/DATE:	John Lloyd, Fall 1988
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/rciOptions.h"

/* Check if we are in planning task or not */
extern int rciTaskId;
#define INSIDE_PLANNING_TASK() (rciTaskId == 0)

extern char rciAutoAbortMask[];
#define MASK_RCI_AUTO_ABORT()	rciAutoAbortMask[rciTaskId] = 1;

#define RETURN_ERROR(n)				\
	rciAutoAbortMask[rciTaskId] = 0;	\
	rcclAutoAbortCheck();			\
	return(n);

#define RETURN_NORMAL(n) 			\
	rciAutoAbortMask[rciTaskId] = 0;	\
	return(n);

#endif
