define MWC_2_2			0		* Set to 1 for MWC ver 2.2 *

* RemoteGPS.c			Queue a file from remote system for printing by GPS

version 1.0
	DAV	19 Jan 90		Initial
version 1.01
	DAV	07 Feb 90		Change > to _ , add params, write errors to plog
						rename params file to paramx on error
version 1.1
	DAV	12 Feb 90		Change from GPS to GPAM for mode = 0 (ascii)
						Formfeed between files in the same job mode = 0
						Add params for mode = 0:
							:Orientation:	[Portrait, Landscape]
							:FontName:		[Times, Courier, etc]
							:Fontsize:		[In points]
							:SLD:			[In points] (single line distance)

	Original version by Sirius.  Andrew Savige (Convergent Solutions)
	updated program to Workstation C 2.2 and added various other
	fiddles.  Oct 1990.  (original is orig.RemoteGPS.c).
	Added new params 8 (timedelay) and 9 (noisy).
	Also added SERVER_PRIORITY

version 2.2
	DAV	03 May 91		Added in changes made by Andrew Savige.
						Change Mode 0 to GPS, Mode 3 to GPAM

version 2.3
	DAV	27 Aug 91		Added Mode 4 = ByteStreams
	
version 2.3
	DAV	30 Sep 91		Fixed Mode 4 = ByteStreams  of copies

version 2.4
	DRH 920427			In remote_job() :Mode: 4 was not converted to integer 
						value in remote.mode. Therefore, you could not 
						override with Mode:4	
version 2.60
	DAV	 1 Mar 93		Change to allow node specification in device.
*

if( MWC_2_2)
include <stub.h>
endif

include music.h

*   Create Directory [Sys]<RemoteGPS>                                  *
*                                                                       *
*  Create FTP User in [Sys]<INetCT>FTPUsers                            *
*  name = ????                                                          *
*  password = ????                                                      *
*  path = [Sys]<RemoteGPS>                                             *
*  permissions = 7                                                      *
*                                                                       *
*  Example:   GPS spooler [Sys]<RemoteGPS> 7                           *
*                                                                       *
*   Install This program with param 1 = [Sys]<RemoteGPS>               *
*                                                                       *
*   NOTE: GPS request codes have been installed on workstation          *
*                                                                       *

*						Param 1 is Directory to scan (required) *
*						Param 2 is Directory Password *
*						Param 3 is Default printer (required) *
*						Param 4 is Default printer Password *
*						Param 5 is Default mode *
*						Param 6 is Default priority *
*						Param 7 is convert to sys *
*			AJS: Param 8 is timedelay (secs.) to wait between looking	*
*				 for files (default 60)									*
*			AJS: Param 9 is noisy (default N).  If noisy, then			*
*				 warbles when file found and phasers when successfully	*
*				 sent to GPS.  Handy for debugging.						*

define	min(x,y)		((x)<(y)?(x):(y))
define	max(x,y)		((x)>(y)?(x):(y))

define SERVER_PRIORITY	32

define TRUE			1
define FALSE			0

define NULLCHAR		(unsigned char *)0

define ERC_OK			0

define MODE_MODIFY		0x6D6D
define MODE_READ		0x6D72
define MODE_WRITE		0x6D77

define LOG_USER_TYPE	0xFFF7

define SIZE_BSWA		130

typedef struct gps_page_type {
	unsigned char		bclass;
	unsigned			wcpages;
	unsigned char		sbsection[13];
	unsigned char		sbpage[13];
} GPS_PAGE;

typedef struct gpam_page_type {
	unsigned char		bsides;
	unsigned char		fstagger;
	unsigned			wbinin;
	unsigned char		formname[13];
	unsigned char		falign;
	unsigned char		baspect;
	unsigned char		sbpage[13];
	unsigned char		reserved[13];
	unsigned char		bquality;
	unsigned			wpglength;
	unsigned			wpgwidth;
} GPAM_PAGE;

typedef struct gps_job_type {
	unsigned char		sbdocname[93];
	unsigned char		sbusername[31];
	unsigned char		fsecurity;
	unsigned char		fsuppresspage;
	unsigned char		fsuppressbanner;
	unsigned char		ftypethrough;
	unsigned char		fimmediate;
	unsigned long		qdoccreationtime;
	unsigned long		qreqoutputstarttime;
	unsigned			wccount;
	GPS_PAGE			rgbstartlocation;
	GPS_PAGE			rgbendlocation;
	unsigned char		fsinglesheet;
	unsigned			wtimetoprint;
	unsigned char		bpriority;
} GPS_JOB;

typedef struct gpam_open_type {
	unsigned char		sbdocname[93];
	unsigned char		sbusername[31];
	unsigned char		fsecurity;
	unsigned char		fsuppresspage;
	unsigned char		fsuppressbanner;
	unsigned char		ftypethrough;
	unsigned char		fimmediate;
	unsigned long		qdoccreationtime;
	unsigned long		qreqoutputstarttime;
	unsigned			wccount;
	unsigned			timeout;
	unsigned char		fsinglesheet;
	unsigned			wtimetoprint;
	unsigned char		bpriority;
} GPAM_OPEN;

typedef struct gps_doc_type {
	unsigned char		fdelaftptr;
	unsigned char		sbfilespec[92];
	unsigned char		sbformname[13];
	unsigned char		sbfontname[13];
	unsigned			ccopies;
	unsigned char		bprintmode;
	unsigned char		falignforms;
	unsigned char		fsecuritymode;
	unsigned char		reservedforwp_1[5];
	unsigned char		sbdocname[92];
	unsigned char		sbusername[31];
	unsigned			wtimetoprint;
	unsigned char		reservedforwp_2[2];
	unsigned long		timequeued;
	unsigned char		fsuppressnewpage;
	unsigned char		fwppaging;
	unsigned char		fsuppressbanner;
	unsigned char		fimmediate;
	unsigned char		fsinglesheet;
	unsigned long		qfilesize;
	GPS_PAGE			rgstartpage;
	GPS_PAGE			rgendpage;
	unsigned char		priority;
	unsigned char		fmarked;
} GPS_DOC;

typedef struct pbcb_type {
	char				* pb;
	unsigned int		cb;
} PBCB;

typedef struct log_type {
	unsigned			type;
	unsigned			cbmessage;
	char				message[124];
} LOG;

typedef struct remote_type {
	unsigned char		host[16];
	unsigned char		printer[16];
	unsigned char		job[16];
	unsigned char		owner[16];
	unsigned char		title[100];
	unsigned			copies;
	unsigned char		mode;
	unsigned char		orientation;
	unsigned char		fontname[41];
	unsigned			fontsize;
	unsigned			sld;
	unsigned char		device[101];
	unsigned			files;
define MAX_FILES		20
define MAX_FILES_SIZE	50
	unsigned char		file[MAX_FILES][MAX_FILES_SIZE];
} REMOTE;

REMOTE					remote;

GPS_JOB					job;

GPAM_OPEN				gpam_open;

GPAM_PAGE				gpam_page;

unsigned char			gpam_wa[300];

unsigned char			gpam_buffer[4096];

unsigned char			gps_specification[120];

extern unsigned			fdevelopement;

unsigned char			device[101];
unsigned char			dev_password[13];

unsigned char			directory[43];
unsigned char			dir_password[13];

unsigned char			mode = 3;

unsigned char			priority = 9;

unsigned char			wild[800];

unsigned char			specification[80];

int						timedelay;	* tenths of secs *
int						noisy;		* boolean *

define SIZE_FIELD		80
define SIZE_VALUE		80
define SIZE_BUFFER		1024

unsigned char			lookup_buffer[SIZE_BUFFER];
unsigned				lookup_fh;

unsigned char			lookup_field[SIZE_FIELD];
unsigned				lookup_sfield;

unsigned char			lookup_val[SIZE_VALUE];
unsigned				lookup_svalue;

unsigned char			* lookup_value;

unsigned char			file_buffer[2560];

char					version[40] = Remote Gps (version ;

unsigned				fconvert = TRUE;

extern unsigned char	sbverrun[];

*======================.============<  >===================================*
void BadErc( erc, str) * bad erc detected *
register unsigned	erc;
register char		*str;
{
	ErrorExitString(erc, str, strlen(str));
}

* string may have leading spaces, but no leading sign *

int atoni( s, len)
char	*s;		* in: non nullterm string *
int		len;	* in: length of s *
{
	register int	i;
	int				n;

	for (i = 0; i < len  *(s+i) == ' '; i++)
		;	* skip white space *
	if (i >= len) return 0;
	for (n = 0; i < len  *(s+i) >= '0'  *(s+i) <= '9'; i++)
		n = (10 * n) + (*(s+i))  '0';
	return n;
}

*======================.============<  >===================================*
char * utoa( w)
unsigned				w;
{
	static char			buf[6];
	char				* pbuf;

	pbuf = buf[5];
	*pbuf = '\0';
	if( w == 0) {
		*pbuf = '0';
	} else {
		while( w) {
			*pbuf = ( ( w  10) + '0');
			w = 10;
		}
		pbuf++;
	}
	return( pbuf);
}

*======================.============<  >===================================*
void log_it( pb, erc)
unsigned char			* pb;
unsigned				erc;
{
	unsigned			cb;
	LOG 				log_record;

	log_record.message[0] = '\0';
	strcat( log_record.message, version);
	strcat( log_record.message,  );
	strcat( log_record.message, , );
	strcat( log_record.message, pb);
	if( erc = ERC_OK) {
		strcat( log_record.message,  ERC = );
		strcat( log_record.message, utoa( erc));
	}
	strcat( log_record.message, .\n);
	cb = strlen( log_record.message);
	log_record.type = LOG_USER_TYPE;
	log_record.cbmessage = cb;
	writelog( log_record, cb + 4);
	if (noisy) DoFunnyNoise(CAR_ALARM, 2);
}

*======================.============<  >===================================*
unsigned initialize( )
{
	PBCB				pbcb;
	unsigned			erc;
	unsigned char		* pb;
	unsigned			cb;
	unsigned char		buffer[14];
	char				tversion[20];
	int					i;

	for( i = sbverrun[0], tversion[i] = '\0'; i > 0; i) {
		tversion[i1] = sbverrun[i];
	}
	strcat( version, tversion);
	strcat( version, ));

	checkerc( rgparam( 1, 0, pbcb));
	if( pbcb.pb[0] = '[') {
		if( pbcb.pb[0] = '{') {
			checkerc( 205);
		} 
	}
	if( pbcb.pb[pbcb.cb1] = '>') {
		checkerc( 205);
	}
	if( pbcb.cb > 42) {						* {12}[12]<12> *
		checkerc( 205);
	}
	if( pbcb.cb < 1) {
		checkerc( 205);
	}
	memcpy( directory, pbcb.pb, pbcb.cb);
	directory[pbcb.cb] = '\0';
	strcat( specification, directory);
	strcat( specification, *_*_params);

	if( rgparam( 2, 0, pbcb) == ERC_OK) {
		if( pbcb.cb > 12) {
			checkerc( 205);
		}
		if( pbcb.cb < 1) {
			checkerc( 205);
		}
		memcpy( dir_password, pbcb.pb, pbcb.cb);
		dir_password[pbcb.cb] = '\0';
		strcat( specification, ^);
		strcat( specification, dir_password);
	}

	checkerc( rgparam( 3, 0, pbcb));
	if( pbcb.cb > 24) {
		checkerc( 205);
	}
	if( pbcb.cb < 1) {
		checkerc( 205);
	}
	if( pbcb.pb[0] = '{') {
		if( pbcb.pb[0] = '[') {
			if( pbcb.cb > 12) {
				checkerc( 205);
			}
			device[0] = '[';
			memcpy( device[1], pbcb.pb, pbcb.cb);
			device[pbcb.cb+1] = ']';
			device[pbcb.cb+2] = '\0';
		} else {
			memcpy( device, pbcb.pb, pbcb.cb);
			device[pbcb.cb] = '\0';
		}
	} else {
		memcpy( device, pbcb.pb, pbcb.cb);
		device[pbcb.cb] = '\0';
	}

	if( rgparam( 4, 0, pbcb) == ERC_OK) {
		if( pbcb.cb > 12) {
			checkerc( 205);
		}
		if( pbcb.cb < 1) {
			checkerc( 205);
		}
		memcpy( dev_password, pbcb.pb, pbcb.cb);
		dev_password[pbcb.cb] = '\0';
	}

	if( rgparam( 5, 0, pbcb) == ERC_OK) {
		mode = *pbcb.pb;
		switch( mode) {
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
			mode = '0';
			break;
		default:
			checkerc( 7);
		}
	}

	if( rgparam( 6, 0, pbcb) == ERC_OK) {
		priority = 0;
		while( pbcb.cb > 0) {
			if( *pbcb.pb >= '0'  *pbcb.pb <= '9') {
				priority *= 10;
				priority += *pbcb.pb  '0';
			}
			pbcb.pb++;
			pbcb.cb;
		}
	}
	if( priority == 0) {
		priority = 9;
	}
	if( priority > 15) {
		priority = 9;
	}

	if( rgparam( 7, 0, pbcb ) == 0) {
		switch( pbcb.pb[0]) {
		case 'N':
		case 'n':
			fconvert = FALSE;
			break;
		default:
			break;
		}
	}
	timedelay = 0;
	if( rgparam( 8, 0, pbcb) == ERC_OK) {
		if (pbcb.cb > 0) timedelay = atoni( pbcb.pb, pbcb.cb) * 10;
	}
	if (timedelay <= 0) timedelay = 600;

	noisy = FALSE;
	if( rgparam( 9, 0, pbcb) == ERC_OK) {
		switch( pbcb.pb[0]) {
		case 'Y':
		case 'y':
			noisy = TRUE;
			break;
		default:
			break;
		}
	}
	if (noisy) {
		InitMusic();
		DoFunnyNoise(V_SLOW_WARBLE, 1);
	}

	return( ERC_OK);
}

*======================.============<  >===================================*
unsigned bs_output_file( pb, flast)
unsigned char			* pb;
unsigned char			flast;
{
	unsigned			erc;
	unsigned			fh;
	unsigned			len_read;
	unsigned			len_write;
	unsigned long		length;
	unsigned long		lfa = 0;
	unsigned long		lfa_eof;
	unsigned			cbret;
	unsigned			i;
	unsigned			offset;

	if( ( erc = openfile( fh, pb, strlen( pb),
			dir_password, strlen( dir_password), MODE_MODIFY)) = ERC_OK) {
		log_it( OpenFile, erc);
		return( erc);
	}
	getfilestatus( fh, 0, length, 4);
	getfilestatus( fh, 6, lfa_eof, 4);

	while( lfa_eof = 0) {
		len_read = min( 2560l, length);
		if( ( erc = read( fh, file_buffer, len_read, lfa, cbret)) = 0) {
			closefile( fh);
			log_it( ReadFile, erc);
			return( erc);
		}
		length = len_read;
		lfa += len_read;
		len_write = min( 2560l, lfa_eof);
		lfa_eof = len_write;
		offset = 0;
		for( i = 0; i < 10; i++) {
			if( len_write == 0) {
				break;
			}
			if( ( erc = writebsrecord( gpam_wa,
					file_buffer[offset], min( 256, len_write),
					cbret)) = 0) {
				closefile( fh);
				log_it( WriteBsRecord, erc);
				return( erc);
			}
			offset += 256;
			len_write = min( 256, len_write);
		}
	}
	if( flast) {
		deletefile( fh);
	} else {
		closefile( fh);
	}
	return( ERC_OK);
}

*======================.============<  >===================================*
unsigned bs_output( )
{
	unsigned			handle;
	unsigned			erc;
	unsigned char		* pb;
	unsigned			i;
	unsigned			c;
	unsigned			cbret;
	unsigned char		flast;
	
	memset( gpam_wa, 0, sizeof( gpam_wa));

	if( remote.device[0] == '\0') {
		pb = device;
	} else {
		pb = remote.device;
	}
	if( remote.copies == 0) {
		remote.copies = 1;
	}	
	for( c = 0; c < remote.copies; c++) {
		if( c == remote.copies  1) {
			flast = TRUE;
		} else {
			flast = FALSE;
		}
		if( ( erc = openbytestream( gpam_wa, pb, strlen( pb),
				dev_password, strlen( dev_password), MODE_WRITE,
				gpam_buffer, sizeof( gpam_buffer))) = ERC_OK) {
			log_it( OpenByteStream, erc);
			return( erc);
		}
		for( i = 0; i < remote.files; i++) {
			if( i > 0) {
				writebsrecord( gpam_wa, \014, 1, cbret);
			}
			strcpy( gps_specification, directory);
			strcat( gps_specification, remote.printer);
			strcat( gps_specification, _);
			strcat( gps_specification, remote.job);
			strcat( gps_specification, _);
			strcat( gps_specification, remote.file[i]);
			if( ( erc = bs_output_file( gps_specification, flast)) = ERC_OK) {
				closebytestream( gpam_wa);
				return( erc);
			}
		}
		closebytestream( gpam_wa);
	}
	return( ERC_OK);
}

*======================.============<  >===================================*
unsigned gpam_output_file( pb)
unsigned char			* pb;
{
	unsigned			erc;
	unsigned			fh;
	unsigned			len_read;
	unsigned			len_write;
	unsigned long		length;
	unsigned long		lfa = 0;
	unsigned long		lfa_eof;
	unsigned			cbret;
	unsigned			i;
	unsigned			offset;

	if( ( erc = openfile( fh, pb, strlen( pb),
			dir_password, strlen( dir_password), MODE_MODIFY)) = ERC_OK) {
		log_it( OpenFile, erc);
		return( erc);
	}
	getfilestatus( fh, 0, length, 4);
	getfilestatus( fh, 6, lfa_eof, 4);

	while( lfa_eof = 0) {
		len_read = min( 2560l, length);
		if( ( erc = read( fh, file_buffer, len_read, lfa, cbret)) = 0) {
			closefile( fh);
			log_it( ReadFile, erc);
			return( erc);
		}
		length = len_read;
		lfa += len_read;
		len_write = min( 2560l, lfa_eof);
		lfa_eof = len_write;
		offset = 0;
		for( i = 0; i < 10; i++) {
			if( len_write == 0) {
				break;
			}
			if( ( erc = gpamwriterecord( gpam_wa,
					file_buffer[offset], min( 256, len_write),
					cbret)) = 0) {
				closefile( fh);
				log_it( GPAMWriteRecord, erc);
				return( erc);
			}
			offset += 256;
			len_write = min( 256, len_write);
		}
	}
	deletefile( fh);
	return( ERC_OK);
}

*======================.============<  >===================================*
unsigned gpam_output( )
{
	unsigned			handle;
	unsigned			erc;
	unsigned char		* pb;
	unsigned			i;
	unsigned			cbret;
	
	memset( gpam_open, 0, sizeof( GPAM_OPEN));
	memset( gpam_page, 0, sizeof( GPAM_PAGE));
	memset( gpam_wa, 0, sizeof( gpam_wa));

	if( remote.device[0] == '\0') {
		pb = device;
	} else {
		pb = remote.device;
	}
	if( remote.title[0] == '\0') {
		strcpy( gpam_open.sbdocname[1], remote.host);
		strcat( gpam_open.sbdocname[1], _);
		strcat( gpam_open.sbdocname[1], remote.printer);
		strcat( gpam_open.sbdocname[1], _);
		strcat( gpam_open.sbdocname[1], remote.job);
	} else {
		strcpy( gpam_open.sbdocname[1], remote.title);
	}
	gpam_open.sbdocname[0] = strlen( gpam_open.sbdocname[1]);

	strcpy( gpam_open.sbusername[1], remote.host);
	strcat( gpam_open.sbusername[1], _);
	strcat( gpam_open.sbusername[1], remote.owner);
	gpam_open.sbusername[0] = strlen( gpam_open.sbusername[1]);

	getdatetime( gpam_open.qdoccreationtime);

	gpam_open.wccount = remote.copies;

	gpam_open.bpriority = priority;

	if( ( erc = gpamopen( gpam_wa, sizeof( gpam_wa), pb, strlen( pb),
			dev_password, strlen( dev_password),
			gpam_buffer, sizeof( gpam_buffer),
			gpam_open, sizeof( GPAM_OPEN))) = ERC_OK) {
		log_it( GPAMOpen, erc);
		return( erc);
	}
	gpam_page.baspect = remote.orientation;
	if( ( erc = gpambeginpage( gpam_wa,
			gpam_page, sizeof( gpam_page))) = ERC_OK) {
		gpamclose( gpam_wa);
		log_it( GPAMBeginPage, erc);
		return( erc);
	}
	if( strlen( remote.fontname) = 0) {
		if( ( erc = gpamsetfont( gpam_wa,
				remote.fontname, strlen( remote.fontname),
				0, remote.fontsize)) = ERC_OK) {
			gpamclose( gpam_wa);
			log_it( GPAMSetFont, erc);
			return( erc);
		}
	}
	if( remote.sld = 0) {
		if( ( erc = gpamsetsld( gpam_wa, remote.sld)) = ERC_OK) {
			gpamclose( gpam_wa);
			log_it( GPAMSetSLD, erc);
			return( erc);
		}
	}
	for( i = 0; i < remote.files; i++) {
		if( i > 0) {
			gpamwriterecord( gpam_wa, \014, 1, cbret);
		}
		strcpy( gps_specification, directory);
		strcat( gps_specification, remote.printer);
		strcat( gps_specification, _);
		strcat( gps_specification, remote.job);
		strcat( gps_specification, _);
		strcat( gps_specification, remote.file[i]);
		if( ( erc = gpam_output_file( gps_specification)) = ERC_OK) {
			gpamclose( gpam_wa);
			return( erc);
		}
	}
	gpamclose( gpam_wa);
	return( ERC_OK);
}

*======================.============<  >===================================*
define MAX_CHUNK	1024L	* originally 2560L, but got erc 721 *
				* on WriteGpsFile call (only at Treasury *
				* for 'large' files (etcshutdown is big *
				* enough). *

unsigned gps_output_file( pb, handle)
unsigned char			* pb;
unsigned				handle;
{
	unsigned			erc;
	unsigned			fh;
	unsigned			len_read;
	unsigned			len_write;
	unsigned long		length;
	unsigned long		lfa = 0;
	unsigned long		lfa_eof;
	unsigned			cbret;

	if( ( erc = openfile( fh, pb, strlen( pb),
			dir_password, strlen( dir_password), MODE_MODIFY)) = ERC_OK) {
		log_it( OpenFile, erc);
		return( erc);
	}
	getfilestatus( fh, 0, length, 4);
	getfilestatus( fh, 6, lfa_eof, 4);

	while( lfa_eof = 0) {
		len_read = min( MAX_CHUNK, length);
		if( ( erc = read( fh, file_buffer, len_read, lfa, cbret)) = 0) {
			closefile( fh);
			log_it( ReadFile, erc);
			return( erc);
		}
		length = len_read;
		lfa += len_read;
		len_write = min( MAX_CHUNK, lfa_eof);
		if( ( erc = writegpsfile( handle, file_buffer, len_write,
				cbret)) = 0) {
			closefile( fh);
			log_it( WriteGpsFile, erc);
			return( erc);
		}
		lfa_eof = len_write;
	}
	deletefile( fh);
	return( ERC_OK);
}

*======================.============<  >===================================*
unsigned gps_output( )
{
	unsigned			handle;
	unsigned			erc;
	unsigned char		* pb;
	unsigned			i;
	
	memset( job, 0, sizeof( GPS_JOB));

	if( remote.device[0] == '\0') {
		pb = device;
	} else {
		pb = remote.device;
	}
	if( ( erc = opengpsfile( handle, pb, strlen( pb),
			dev_password, strlen( dev_password))) = ERC_OK) {
		log_it( OpenGpsFile, erc);
		return( erc);
	}
	if( remote.title[0] == '\0') {
		strcpy( job.sbdocname[1], remote.host);
		strcat( job.sbdocname[1], _);
		strcat( job.sbdocname[1], remote.printer);
		strcat( job.sbdocname[1], _);
		strcat( job.sbdocname[1], remote.job);
	} else {
		strcpy( job.sbdocname[1], remote.title);
	}
	job.sbdocname[0] = strlen( job.sbdocname[1]);

	strcpy( job.sbusername[1], remote.host);
	strcat( job.sbusername[1], _);
	strcat( job.sbusername[1], remote.owner);
	job.sbusername[0] = strlen( job.sbusername[1]);

	getdatetime( job.qdoccreationtime);

	job.wccount = remote.copies;

	job.bpriority = priority;

	if( ( erc = setgpsparams( handle, job, sizeof( GPS_JOB))) = ERC_OK) {
		closegpsfile( handle);
		log_it( SetGpsParams, erc);
		return( erc);
	}
	if( ( erc = setimagemodegps( handle, remote.mode)) = ERC_OK) {
		closegpsfile( handle);
		log_it( SetImageModeGps, erc);
		return( erc);
	}
	for( i = 0; i < remote.files; i++) {
		strcpy( gps_specification, directory);
		strcat( gps_specification, remote.printer);
		strcat( gps_specification, _);
		strcat( gps_specification, remote.job);
		strcat( gps_specification, _);
		strcat( gps_specification, remote.file[i]);
		if( ( erc = gps_output_file( gps_specification, handle)) = ERC_OK) {
			closegpsfile( handle);
			return( erc);
		}
	}
	closegpsfile( handle);
	return( ERC_OK);
}

*======================.============<  >===================================*
void remote_job( pb, cb)
unsigned char			* pb;
unsigned				cb;
{
	unsigned			erc;

	memset( remote, 0, sizeof( REMOTE));
	remote.mode = mode;
	strcpy( remote.device, device);

	if( ( erc = openfile( lookup_fh, pb, cb,
			dir_password, strlen( dir_password), MODE_MODIFY)) = ERC_OK) {
		log_it( OpenFile (params), erc);
		return;
	}
	if( ( erc = lookupreset( )) = ERC_OK) {
		log_it( LookUpReset, erc);
		goto rename_it;
		return;
	}

	while( ( erc = lookupfield( lookup_fh, lookup_buffer, SIZE_BUFFER,
			lookup_field, SIZE_FIELD, lookup_sfield,
			lookup_val, SIZE_VALUE, lookup_svalue, FALSE)) == ERC_OK) {
		lookup_field[lookup_sfield] = '\0';
		lookup_val[lookup_svalue] = '\0';
		lookup_value = lookup_val;
		if( strlen( lookup_value) == 0) {
			continue;
		}
		while( TRUE) {
			if( *lookup_value == ' ') {
				lookup_value++;
			} else if( *lookup_value == '\t') {
				lookup_value++;
			} else {
				break;
			}
		}
		if( strcmpi( Host, lookup_field) == 0) {
			strncpy( remote.host, lookup_value, sizeof( remote.host)  1);
		} else if( strcmpi( Printer, lookup_field) == 0) {
			strncpy( remote.printer, lookup_value, sizeof( remote.printer)1);
		} else if( strcmpi( Job, lookup_field) == 0) {
			strncpy( remote.job, lookup_value, sizeof( remote.job)  1);
		} else if( strcmpi( Owner, lookup_field) == 0) {
			strncpy( remote.owner, lookup_value, sizeof( remote.owner)  1);
		} else if( strcmpi( Title, lookup_field) == 0) {
			strncpy( remote.title, lookup_value, sizeof( remote.title)  1);
		} else if( strcmpi( Copies, lookup_field) == 0) {
			remote.copies = atoi( lookup_value);
		} else if( strcmpi( FontName, lookup_field) == 0) {
			strncpy( remote.fontname, lookup_value,
					sizeof( remote.fontname)  1);
		} else if( strcmpi( FontSize, lookup_field) == 0) {
			remote.fontsize = atoi( lookup_value);
			remote.fontsize *= 20;
		} else if( strcmpi( Sld, lookup_field) == 0) {
			remote.sld = atoi( lookup_value);
			remote.sld *= 20;
		} else if( strcmpi( Orientation, lookup_field) == 0) {
			switch( *lookup_value) {
			case 'L':
			case 'l':
				remote.orientation = 1;
				break;
			case 'P':
			case 'p':
				remote.orientation = 2;
				break;
			default:
				break;
			}
		} else if( strcmpi( Mode, lookup_field) == 0) {
			if( *lookup_value >= '0'  *lookup_value <= '4') {	*DRH 920427*
				remote.mode = *lookup_value  '0';
			}
		} else if( strcmpi( Device, lookup_field) == 0) {
			if( *lookup_value = '{') {
				if( *lookup_value = '[') {
					remote.device[0] = '[';
					strncpy( remote.device[1], lookup_value,
							sizeof( remote.device)  3);
					strcat( remote.device, ]);
				} else {
					strncpy( remote.device, lookup_value,
							sizeof( remote.device)  1);
				}
			} else {
				strncpy( remote.device, lookup_value,
						sizeof( remote.device)  1);
			}
		} else if( strcmpi( File, lookup_field) == 0) {
			if( remote.files < MAX_FILES  1) {
				strncpy( remote.file[remote.files], lookup_value,
						MAX_FILES_SIZE  1);
				remote.files++;
			}
		}
	}
	if( remote.mode == 4) {
		erc = bs_output( );
	} else if( remote.mode == 3) {
		erc = gpam_output( );
	} else {
		erc = gps_output( );
	}
	if( erc == ERC_OK) {
		deletefile( lookup_fh);
	} else {
rename_it:
		pb[cb1] = 'x';					* change params to paramx *
		renamefile( lookup_fh, pb, cb, dir_password, strlen( dir_password));
		closefile( lookup_fh);
	}
}

*======================.============<  >===================================*
main( )
{
	PBCB				pbcb;

	fdevelopement = TRUE;

	checkerc( initialize( ));

	if( fconvert) {
		CheckErc(ChangePriority( (char) SERVER_PRIORITY));
		converttosys( );
		exit( );
	}

	while( TRUE) {
		if( wildcardinit( specification, strlen( specification),
				wild, 800) == ERC_OK) {
			while( wildcardnext( wild, pbcb) == ERC_OK) {
				* got a params file *
				if (noisy) DoFunnyNoise(V_SLOW_WARBLE, 1);
				remote_job( pbcb.pb, pbcb.cb);
				if (noisy) DoFunnyNoise(FAST_PHASER, 1);
			}
		}
		delay( timedelay);
	}
	exit( );							* never gets here *
}

t);
	strcat( job.sbusername[1], _);
	strcat( job.sbusername[1], remote.owner);
	job.sbusername[0] = strlen( job.sbusername[1]);

	getdatetime( job.qdoccreationtime);

	job.wccount = remote.copies;

	job.bpriority = priority;

	if( ( erc = setgpsparams( handle, job, sizeof( GPS_JOB))) = ERC_OK) {
		closegpsfile( handle);
		log_it( SetGpsParams, erc);
		return( erc);
	}
	if( ( erc = setimagemodegps( handle, remote.mode)) = ER