/************************************************************************
 * RasterLink sample ARexx script					*
 * Simple File Conversion.						*
 * By Eric Lavitsky, 8/10/89 - updated 9/3/90				*
 ************************************************************************/

/************************************************************************
 *									*
 * Change the value of depth to reflect the number of bitplanes in the	*
 * output image (e.g: 24, 8, 4 etc.).					*
 *									*
 ************************************************************************/
depth = 32;

/************************************************************************
 *									*
 * Change the value of dithmethod to reflect the type of dithering you	*
 * require. Valid values would be 'none' or 'floyd'.			*
 *									*
 ************************************************************************/
dithmethod = 'none';

/************************************************************************
 *									*
 * Change the value of compression to reflect the type of file 		*
 * compression you require. Valid values depend on the output module	*
 * and can be either 'none', 'method1', or 'method2'.			*
 *									*
 ************************************************************************/
compression = 'method1';

/************************************************************************
 * The only other changes you may have to make would be specifically	*
 * related to the input and output modules being used (see below)	*
 ************************************************************************/

arg arg1

cur_dir = pragma(d,'')

/* Turn on result code passing */
options results;
options failat 20

call addlib 'rexxsupport.library',0,-30;
list = showlist(p);
beg = pos('ILINK',list);

if (beg = 0) then
	/* Need to start RasterLink */
        address command 'cd "' || cur_dir || '"' || '0A'x,
	'run RasterLink'

/* Make sure WaitForPort is in your path! */
address command 'WaitForPort ILINK';

/* Find RasterLink's ARexx port and attempt to lock a */
/* private communications channel with it */
address 'ILINK' lock;

if (rc ~= 0) then do;
	say 'Could not lock RasterLink.';
	exit;
end;

/* Result contains the private communications channel */
address value result;

signal on error;
signal on syntax;
signal on break_c;

main:
	/* Assure the initial state */
	INIT;

	/* Get the version number for RasterLink */
	version;
	say 'RasterLink version is: 'result;

	/* Select initial modules */
	INPMOD 'IFF ILBM File';
	OUTMOD 'Truevision TARGA File';

	/* Link the modules together */
	LINK;

	/* Select the file names */
	INPFIL 'PICS:IFF24/seat.24';
	OUTFIL 'RAM:out.tga';

	/* Select the conversion parameters */
	DITHER dithmethod;
	COLOR cval depth;
	COMPRESS compression;

	/* Start the conversion */
	START;

finish:
	/* Unlink the modules */
	UNLINK;

	/* Free the channel for others to use */
	UNLOCK;

	/* Tell RasterLink to exit */
	signal off error;
	options failat 101
	QUIT;
	options failat 20

	exit;

error:
	say 'RasterLink/ARexx Error:'
	select
	 when rc = 80 then say ' LOCK: RasterLink already Locked';
	 when rc = 81 then say ' UNLOCK: Nothing to UnLock';
	 when rc = 82 then say ' LINK: No Input Module Selected';
	 when rc = 83 then say ' LINK: No Output Module Selected';
	 when rc = 84 then say ' START: No Input File';
	 when rc = 85 then say ' START: No Output File';
	 when rc = 96 then say ' Transfer Already In Progress';
	 when rc = 97 then say ' No Such Module Exists';
	 when rc = 98 then say " No Such File or Can't Create File";
	 when rc = 99 then say ' RECORD: Problem with Transport Controller';
	end;
	/* Tell RasterLink to exit */
	signal off error;
	unlock;
	options failat 101
	quit;
	options failat 20
	exit;

syntax:
	unlock;
	say 'RasterLink aborted script: syntax error'
	exit;

break_c:
	say 'Halted by ^C';
	unlock;
	exit;
