/*********************************************************
 * Gotcha library example code.
 * (c)1995 Thomas Bickel. All rights reserved.
 *
 * Send a ARexx command and show result
 *********************************************************/

#include <stdio.h>
#include <stdlib.h>

#include <rexx/storage.h>
#include <exec/types.h>

#include <clib/exec_protos.h>
#include <pragmas/exec_pragmas.h>

#include <clib/gotchalib_protos.h>
#include <pragmas/gotchalib_pragmas.h>
#include <libraries/gotchalib.h>

struct Library *GotchaLibBase=0;

UBYTE rrx[1048];
UBYTE *port="GOTCHA";
UBYTE *com;

/***********************************************************************/
int main(long argc, char *argv[])
{
	if ((argc==1) || (argc>3) || (argv[1][0]=='?')) {
		printf("Usage: %s [portname] \"command string\"\n",argv[0]);
		exit(5);
	}

	if (GotchaLibBase = OpenLibrary("gotcha.library",1)) {

		if (argc==2) com=argv[1];
		else { com=argv[2]; port=argv[1]; }

		if (GL_SendRxCmd(port,com,rrx,sizeof(rrx),RXFF_RESULT)) {
			if (*rrx) puts(rrx);
		} else
			puts("Failed to send command!");

		CloseLibrary(GotchaLibBase);
	} else
		puts("Could not open 'gotcha.library'!");
}
