/*
	SCCS id:	@(#) fb_ptty.c	1.1
	Last edit: 	2/3/86 at 12:59:17	G S M
	Retrieved: 	6/12/86 at 10:53:08
	SCCS archive:	/vld/src/libfb/s.fb_ptty.c

	Authors:	Gary S. Moss
			U. S. Army Ballistic Research Laboratory
			Aberdeen Proving Ground
			Maryland 21005-5066
*/
#if ! defined( lint )
static
char	sccsTag[] = "@(#) fb_ptty.c	1.1	last edit 2/3/86 at 12:59:17";
#endif
#include <stdio.h>
#include <fb.h>
extern FILE	*popen();
static FILE	*ptty_fp;

_ptty_open( ptty_name )
char	*ptty_name;
	{	static char	command[48];
	(void) sprintf(	command,
			"fb-egs -i -l %d %d > %s",
			_fbsize, _fbsize, ptty_name
			);
	if( (ptty_fp = popen( command, "w" )) == NULL )
		return	-1;
	else
		return	(int) fileno( ptty_fp );
	}

_ptty_close()
	{
#ifdef DEBUG
	(void) fprintf( stderr, "_ptty_close()\n" );
#endif
	if( pclose( ptty_fp ) == -1 )
		{
		return	-1;
		}
	else
		return	0;
	}

int
_ptty_write( x, y, buff, ct )
int	x, y;
Pixel	*buff;
long	ct;
	{	int	pixels_written;
#ifdef DEBUG
	(void) fprintf( stderr, "_ptty_write(%d,%d,0x%x,%ld) ptty_fp=0x%x\n",
			x, y, buff, ct, ptty_fp
			);
#endif
	if(	(pixels_written =
		fwrite( (char *) buff, sizeof(Pixel), (int) ct, ptty_fp ))
		!= (int) ct
		)
		return	-1;
	else
		{
		(void) fflush( ptty_fp );
		return	0;
		}
	}

int
_ptty_read( x, y, buff, ct )
int	x, y;
Pixel	*buff;
long	ct;
	{
#ifdef DEBUG
	(void) fprintf( stderr, "_ptty_read(%d,%d,0x%x,%ld) ptty_fp=0x%x\n",
			x, y, buff, ct, ptty_fp
			);
#endif
	/* Can't do this yet.						*/
	return	-1;
	}
