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

	ZDspBf()

	This function displays a buffer of a given length on the terminal
screen.  On the VAX (and maybe other systems) doing any kind of output
involves a fair amount of overhead,  regardless of the size of the buffer
being output.  It is therefore better to make a single call to the operating
system's output routine than to call the routine for each and every
character.  If such improvements do not apply to the system this program
is running on,  then this routine can simply call ZDspCh for every character
in the buffer.

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

#include "ZPort.h"		/* define portability identifiers */



#ifdef UNKNOWN
VOID	ZDspCh();		/* output a character */
VOID ZDspBf(buffer, length)	/* output a buffer to terminal */
char *buffer;
DEFAULT length;
{
	puts("Terminating in function ZDspBf.\n");
	exit(1);
}
#endif



#ifdef vax11c
#include iodef		/* define i/o code identifiers */
#include rab		/* define RMS record access block structures */
#include rmsdef		/* define RMS return status identifiers */
#include ssdef		/* define system service status return identifiers */
#define MAXTOUT 500

VOID	lib$stop();		/* terminate image with stack dump */
int	sys$qiow();		/* VAX/VMS queue i/o request system service */

EXTERN	BOOLEAN	GotCtC;		/* indicates hat a CTRL_C has been hit */
EXTERN	short	TOChan;		/* terminal channel */
EXTERN	struct	RAB TORab;	/* output RMS record access block */


VOID ZDspBf(buffer, length)	/* output a buffer to the terminal */
char *buffer;
DEFAULT length;
{
	auto	int	iolength;
	struct	io_status_block iosb;
	auto	int	status;
	auto	DEFAULT	TmpLng;


	if (TOChan)				/* if it's a terminal */
		{
		while ((length > 0) && !GotCtC)
			{
			iolength = (length > MAXTOUT) ? MAXTOUT : length;
			status = sys$qiow(
				TERM_OUT_EFN,	/* event flag number */
				TOChan,		/* channel */
				IO$_WRITEVBLK,	/* I/O func */
				&iosb,		/* I/O status block */
				0,		/* ast routine address */
				0,		/* ast parameter */
				buffer,		/* p1 */
				iolength,	/* p2 */
				0,		/* p3 */
				0,		/* p4 */
				0,		/* p5 */
				0);		/* p6 */
			if (status != SS$_NORMAL)
				lib$stop(status);
			if ((iosb.io_status != SS$_NORMAL) &&
			    (iosb.io_status != SS$_ABORT) &&
			    (iosb.io_status != SS$_CONTROLC) &&
			    (iosb.io_status != SS$_CONTROLO))
				lib$stop(iosb.io_status);
			buffer += MAXTOUT;
			length -= MAXTOUT;
			}
		}
	else					/* else it's not a terminal */
		for (TmpLng=1; TmpLng<=length; ++TmpLng)
			ZDspCh(*buffer++);
}
#endif



#ifdef XENIX
EXTERN	int	tty_fd;

extern	VOID	ZAbort();	/* clean up and terminate TECOC */

VOID ZDspBf(buffer, length)	/* output a buffer to terminal */
char *buffer;
DEFAULT length;
{
	if (write(tty_fd, buffer, length) == -1)
		{
		puts("Unable to write to terminal in function ZDspBf");
		ZAbort();
		}
}
#endif
