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

	ZOClDe()

	This function closes and deletes the current output stream.  It must

	1.  if no current output stream is defined,  simply return
	2.  close the output stream
	3.  delete the file just closed

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

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

extern	VOID	ZDspBf();	/* display a buffer on the terminal */

EXTERN	BOOLEAN	IsOpnO[];
EXTERN	struct	OFDBST	OFiles[];



#ifdef UNKNOWN
VOID ZOClDe(OfIndx)			/* close and delete output file */
DEFAULT	OfIndx;				/* index into OFiles array */
{
	puts("Terminating in function ZOClDe.\n");
	exit(1);
}
#endif



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

VOID	lib$stop();		/* terminate image with stack dump */
int	sys$close();		/* RMS CLOSE service */


VOID ZOClDe(OfIndx)			/* close and delete output file */
DEFAULT	OfIndx;				/* index into OFiles array */
{
	int	status;

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1)
{DbgMsg();ZDspBf("ZOClDe: called.\015\012", 17);DbgROf();}
#endif

	if (IsOpnO[OfIndx])		/* if output stream is open */
		{
		OFiles[OfIndx].OFab.fab$l_fop |= FAB$M_DLT;
		status = sys$close(&OFiles[OfIndx].OFab);
		if (status != RMS$_NORMAL)
			lib$stop(status, OFiles[OfIndx].OFab.fab$l_stv);
		IsOpnO[OfIndx] = NO;
		}
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ZOClDe: returning.\015\012");DbgROf();}DbgInd-=2;
#endif
}
#endif



#ifdef XENIX
DEFAULT	fclose();		/* standard C library function */
VOID	exit();			/* standard C library function */
WORD	unlink();		/* standard C library function */

EXTERN	char	OFNam[];	/* output file name */


VOID ZOClDe(OfIndx)			/* close and delete output file */
DEFAULT	OfIndx;				/* index into OFiles array */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1)
{DbgMsg();DbgDBf("ZOClDe: called.\015\012");DbgROf();}
#endif

	if (IsOpnO[OfIndx])		/* if output stream is open */
		{
		if (fclose(OFiles[OfIndx].OStrem) == EOF)
			{
			ZDspBf("ZOClDe: fclose() failed.\015\012", 25);
			exit(1);
			}
		if (unlink(OFiles[OfIndx].OFNam) != 0)
			{
			ZDspBf("ZOClDe: unlink() failed.\015\012", 25);
			exit();
			}
		IsOpnO[OfIndx] = NO;
		}
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ZOClDe: returning.\015\012");DbgROf();}DbgInd-=2;
#endif
}
#endif
