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

	ZWrite()

	This function writes a buffer to a file.

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

#include "ZPort.h"		/* define portability identifiers */
#include "ZFiles.h"		/* define file data block structures */
#include "DefTeco.h"		/* define general identifiers */
#include "DefChars.h"		/* define identifiers for characters */

VOID	ErrMsg();		/* display an error message */

EXTERN	struct	OFDBST	OFiles[];



#ifdef UNKNOWN
DEFAULT ZWrite(OfIndx, BfrBeg, RecSiz)
DEFAULT	OfIndx;			/* index into OFiles array */
char *BfrBeg;			/* address of output buffer */
char *RecSiz;			/* record size */
{
	puts("Terminating in function ZWrite.\n");
	exit(1);
}
#endif





#ifdef vax11c
#include rmsdef			/* define RMS return status identifiers */
#include ssdef			/* define system service return identifiers */

VOID	lib$stop();		/* terminate image with stack dump */
int	sys$putmsg();		/* VAX/VMS "put message" system service */
int	sys$put();		/* RMS PUT service */
VOID	ZDspCh();		/* display a character on the terminal */

EXTERN	struct	message_vector msgvec;


DEFAULT ZWrite(OfIndx, BfrBeg, RecSiz)
DEFAULT	OfIndx;			/* index into OFiles array */
char	*BfrBeg;		/* address of output buffer */
DEFAULT	RecSiz;			/* record size */
{
	int status;

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=2){DbgMsg();DbgDBf("ZWrite: called\015\012");DbgROf();}
#endif

	OFiles[OfIndx].ORab.rab$l_rbf = BfrBeg;		/* buffer */
	OFiles[OfIndx].ORab.rab$w_rsz = RecSiz;		/* size */

#if DEBUGGING
if(DbgLvl>=2){DbgMsg();DbgDBf("ZWrite: calling sys$put, RecSiz = ");
MakDBf(RecSiz, 10);ZDspBf(DBfBeg, DBfPtr-DBfBeg);DbgDBf("\015\012");DbgROf();}
#endif
	status = sys$put(&OFiles[OfIndx].ORab);	/* output the record */
	if (status != RMS$_NORMAL)		/* if it didn't work */
		{
		msgvec.msgcod = status;
		msgvec.rmsstv = OFiles[OfIndx].ORab.rab$l_stv;
		status = sys$putmsg(	&msgvec,/* message vector */
					0,	/* action routine */
					0);	/* facility name */
		if (status != SS$_NORMAL)
			lib$stop(status);
		ZDspCh(LINEFD);
#if DEBUGGING
if(DbgLvl>=2)
{DbgMsg();DbgDBf("ZWrite: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}

#if DEBUGGING
if(DbgLvl>=2)
{DbgMsg();DbgDBf("ZWrite: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
#endif



#ifdef XENIX

VOID	fputs();		/* standard C library function */
VOID	ZDspBf();		/* display a buffer on the terminal */


DEFAULT ZWrite(OfIndx, BfrBeg, RecSiz)
DEFAULT	OfIndx;			/* index into OFiles array */
char	*BfrBeg;		/* address of output buffer */
DEFAULT	RecSiz;			/* record size */
{
	char	*ptr;
	char	savchr;

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=2){DbgMsg();DbgDBf("ZWrite: called.\015\012");DbgROf();}
#endif

	ptr = BfrBeg + RecSiz;
	savchr = *ptr;
	*ptr = '\0';
	fputs(BfrBeg, OFiles[OfIndx].OStrem);
	*ptr = savchr;
#if DEBUGGING
if(DbgLvl>=2)
{DbgMsg();DbgDBf("ZWrite: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
#endif
