/*
 *	File:					EasyRexx.h
 *	Description:	Headerfile for the easyrexx.library
 *
 *	(C) 1994,1995 Ketil Hunn
 *
 *	Set Tab=2 for best readability
 *
 */

#ifndef LIBRARIES_EASYREXX_H
#define LIBRARIES_EASYREXX_H

/*** PRIVATE INCLUDES ****************************************************************/
#ifndef	EXEC_PORTS_H
#include <exec/ports.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

#ifndef REXX_ERRORS_H
#include <rexx/errors.h>
#endif

#ifndef INTUITION_INTUITION_H
#include <intuition/intuition.h>
#endif

/*** DEFINES *************************************************************************/
#define	EASYREXXNAME				"easyrexx.library"
#define	EASYREXXVERSION			2L

#ifndef EASYREXX_NOMACROS

#define	ER_SHELLSIGNALS(c)	(c->shell ? (1L<<c->shell->readPort->mp_SigBit | 1L<<c->shell->commandWindow->UserPort->mp_SigBit): 0)
#define	ER_SIGNALS(c)				(	1L<<c->port->mp_SigBit | \
															1L<<c->asynchport->mp_SigBit | \
															ER_SHELLSIGNALS(c))
#define	ER_SIGNAL(c)				(c ? ER_SIGNALS(c):0L)
#define	ER_SAFETOQUIT(c)		(c ? (c->Queue==0):0)
#define	ER_SETSIGNALS(c,s)	if(c) c->signals=s
#define	ER_ISSHELLOPEN(c)		(c->shell==NULL ? 0:1)

#define ARG(c,i)						(c->argv[i])
#define	ARGNUMBER(c,i)			(*((LONG *)c->argv[i]))
#define	ARGSTRING(c,i)			((UBYTE *)c->argv[i])
#define	ARGBOOL(c,i)				(c->argv[i]==NULL ? FALSE:TRUE)

#define	GETRC(c)						(c ? c->Result1:NULL)
#define	GETRESULT1(c)				GETRC(c)
#define	GETRESULT2(c)				(c ? c->Result2:NULL)

#define	TABLE_END						NULL,NULL,NULL,NULL

#endif

/*** GLOBALS *************************************************************************/

struct ARexxCommandTable
{
	LONG	id;
	UBYTE *command,
				*template;
	APTR userdata;
};

struct ARexxCommandShell
{
	struct Window		*commandWindow;
	struct MsgPort	*readPort,
									*writePort;
	struct IOStdReq	*readReq,
									*writeReq;
	UBYTE						*prompt,
									buffer[256],
									ibuf,
									inbuffer;
	BYTE						cursor;
	struct TextFont	*font;
};

struct ARexxContext
{
/*** PRIVATE ****************************/
	struct MsgPort						*port;
	struct ARexxCommandTable	*table;
	UBYTE											*argcopy,
														*portname,
														maxargs;
	struct RDArgs							*rdargs;
	struct RexxMsg						*msg;
	ULONG											flags;

/*** PUBLIC ****************************/
	LONG											id,
														*argv;
	ULONG											Queue;			/* FROM HERE AND DOWN: ONLY AVAILABLE FROM V2 */

/*** PRIVATE ***************************/
	UBYTE											*author,
														*copyright,
														*version,
														*lasterror;
	struct ARexxCommandTable	*reservedcommands;
	struct ARexxCommandShell	*shell;
	ULONG											signals;
	LONG											Result1,
														Result2;
	struct MsgPort						*asynchport;
};

#ifndef CLIB_EASYREXX_PROTOS_H
#include <clib/easyrexx_protos.h>
#endif

/***** TAGS *************************************************************************/
#define	ER_TagBase					(TAG_USER)
#define	ER_Portname					(ER_TagBase+1)	/* Name of AREXX port									*/
#define	ER_CommandTable			(ER_TagBase+2)	/* Table of supported AREXX commands	*/
#define	ER_ReturnCode				(ER_TagBase+3)	/* Primary result (return code)				*/
#define	ER_Result						(ER_ReturnCode)	/* Alias for ER_ReturnCode						*/
#define	ER_Result1					(ER_ReturnCode)	/* Alias for ER_ReturnCode						*/
#define	ER_Result2					(ER_TagBase+4)	/* Secondary result (string)					*/
#define	ER_Port							(ER_TagBase+5)	/* Use already created port						*/
#define	ER_ResultString			(ER_TagBase+6)	/* Secondary result (string)					*/
#define	ER_ResultLong				(ER_TagBase+7)	/* Secondary result (long)						*/

/***** EASYREXX V2 TAGS ***********************************************************/
#define	ER_Asynch						(ER_TagBase+8)	/* Send ARexx command asyncronously		*/
#define	ER_Context					(ER_TagBase+9)	/* Pointer to an ARexxContext					*/
#define	ER_Author						(ER_TagBase+10)	/* Pointer to an author string				*/
#define	ER_Copyright				(ER_TagBase+11)	/* Pointer to an copyright string			*/
#define	ER_Version					(ER_TagBase+12)	/* Pointer to an version string				*/
#define	ER_Prompt						(ER_TagBase+13)	/* Pointer to a prompt string					*/
#define	ER_Close						(ER_TagBase+14)	/* Close CommandShell									*/
#define	ER_ErrorMessage			(ER_TagBase+15)	/* Pointer to an error message				*/
#define	ER_Flags						(ER_TagBase+16)	/* LONG of flags											*/
#define ER_Font							(ER_TagBase+17) /* Pointer to a struct TextFont *			*/

#endif
