 /* Fichier star.dark.c				*/
/* Module appele par le programme principal	*/
/* pour effectuer un effet defini..appele par	*/
/* loadseg					*/

#include	<exec/types.h>
#include	<dos/dos.h>

#include <rexx/storage.h>
#include <rexx/errors.h>

#include	"/includes/struct.h"
#include	"/includes/tom_gadget.h"

char	*p_text_info="   ' ARexx handler'\n\nWith this module, you can send an ARexx cmd\nto a programm to make a blanking effect!\n\nArexxPort is the name of the Port!\n\nStart is the Arexx cmd send at the begining of the blank\nStop is the cmd send at the end (can be null)\n\nPar T.Landspurg";
#define	TAILLE_BUF	100
char	buffer_deb[TAILLE_BUF]="";
char	buffer_end[TAILLE_BUF]="";

char  *p_names[]={"Arexx","CLI",NULL};
struct tom_gadget my_gadg[]={
	{"Arexx_Port",STRING,120,20,144,14,0,20,0,0,"                     "},
	{"Cmd",	STRING,120,40,144,14,0,TAILLE_BUF,0,0,buffer_deb},
	{"EndCmd",STRING,120,60,144,14,0,TAILLE_BUF,0,0,buffer_end},
/*	{"Type:", CYCLE, 120,80,100,50,0,0,0,0,(char *)p_names},*/
	{0,		END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
};


send_msg(buf)
char *buf;
{
	struct	RexxMsg	rx_message;
	struct	MsgPort *rexx_port = NULL;
	struct	MsgPort *reply_port = NULL;
	int	code_ret;

   if(mystrlen(buf)!=0){
	code_ret=0;
	Forbid();
	if( (rexx_port=FindPort (my_gadg[0].p_data)) ==NULL){
		Permit();
		code_ret=-1;
	}else if((reply_port=(struct MsgPort *)CreatePort ("Reply port", 0L))==NULL){
		Permit();
		code_ret=-1;
	}else{
		rx_message.rm_Args[0]=buf;
		rx_message.rm_Args[1]=NULL;
		rx_message.rm_Args[2]=NULL;
		rx_message.rm_Action=RXCOMM;
		rx_message.rm_Node.mn_ReplyPort=reply_port;
		rx_message.rm_Node.mn_Node.ln_Type=NT_MESSAGE;

		PutMsg(rexx_port,&rx_message);
		Permit();
		WaitPort(reply_port);
		DeletePort(reply_port);
		if(rx_message.rm_Result1!=RC_OK)code_ret=-1;
	}
	return(code_ret);
   }
}

/********************************************************** dark ***/

void	__saveds	dark()
{
	if(my_gadg[3].value==0){
		send_msg(my_gadg[1].p_data);
		wait_end();
		send_msg(my_gadg[2].p_data);
	}else{
		if(Execute(my_gadg[1].p_data,NULL,NULL)){
			wait_end();
			Signal(FindTask("showanim4.2"),SIGBREAKF_CTRL_C);
		}
	}
}

void	proc_init()
{
}
void	proc_save()
{
}

void	proc_end()
{
}

