	
/************************************************************************/
/************************************************************************/

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

char	*portname="Multi_Player";

/***********************/
/* PROGRAMME PRINCIPAL */
/***********************/

main(argc,argv)
int   argc;
char  **argv;

{
  char buffer[100];

  if(argc>1){
	if(argc==2){
		if(send_msg(argv[1])!=0){
			exit(-1);
		}
	}else{
		sprintf(buffer,"%s %s",argv[1],argv[2]);
		if(send_msg(buffer)!=0){
			exit(-1);
		}
	}
  }else{
	printf("usage:  cmd_player <cmd_name>\n");
	printf("Cmd name can be: Play <module name>->load and play a song\n");
	printf("               : Stop              ->stop the song\n");
	printf("               : Start             ->restart a stopped song\n");
	printf("               : Select <song num> ->select a song, only with TFMX\n");
	printf("               : Quit             ->stop the player\n");
  }
  exit(0);
}

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

	code_ret=0;
	Forbid();
	if( (rexx_port=FindPort (portname)) ==NULL){
		printf("Multi player not found!\n");
		Permit();
		code_ret=-1;
	}else if((reply_port=(struct MsgPort *)CreatePort ("Reply port", 0L))==NULL){
		printf("Cannot create replay port!\n");
		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);
}
