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

	ZRembr()

	If there is no file specification on the command line,  and the -m
switch does not appear to prevent use of the remembered file name,  then open
the remembered file;  the file that was edited last time TECOC was invoked.

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

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


EXTERN	char	*FBfEnd;	/* end of file specification buffer */
EXTERN	char	*FBfPtr;	/* pointer into file specification buffer */




#ifdef UNKNOWN
BOOLEAN ZRembr()		/* if no file spec, use last one */
{
	puts("Terminating in function ZRembr.\n");
	exit(1);
}
#endif





#ifdef vax11c

#include "DefChars.h"	/* define identifiers for characters */
#include descrip	/* define string descriptor definition macros */
#include nam		/* define RMS NAM block identifiers */
#include ssdef		/* define system service status return identifiers */

VOID	lib$stop();	/* terminate image with stack dump */
int	sys$trnlog();	/* VAX/VMS translate logical name system service */

EXTERN	char	FBfBeg[];	/* file specification buffer */
EXTERN	BOOLEAN	FileDf;		/* was a file specification parsed? */
EXTERN	BOOLEAN	Swit_M;		/* was an M command line switch parsed? */
readonly $DESCRIPTOR(filemem_descriptor,"TECOC$MEMORY");


BOOLEAN ZRembr()	/* if no file spec, use last one */
{
	int status;
	struct dsc$descriptor_s RSL_desc =
		{
		NAM$C_MAXRSS,			/* dsc$w_length */
		DSC$K_DTYPE_T,			/* dsc$b_dtype */
		DSC$K_CLASS_S,			/* dsc$b_class */
		FBfBeg				/* dsc$a_pointer */
		};
	short	length;

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

	if (FileDf || Swit_M)			/* if filespec or -m */
		return(NO);			/* don't "remember" */

	status = sys$trnlog(	&filemem_descriptor,	/* logical name */
				&length,	/* returned string length */
				&RSL_desc,	/* returned string buffer */
				0,		/* logical name table */
				0,		/* access mode */
				3);		/* table search mask */
	if (status == SS$_NOTRAN)		/* if logical didn't exist */
		return(NO);			/* we're done */
	if (status != SS$_NORMAL)		/* if something is wrong */
		lib$stop(status);		/* terminate */
	FBfPtr += length;
	*FBfPtr = '\0';
	return(YES);
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ZRembr: returning\015\012");DbgROf();}DbgInd-=2;
#endif
}
#endif




#ifdef XENIX


BOOLEAN ZRembr()	/* if no file spec, use last one */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ZRembr: called\015\012");DbgROf();}
#endif

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