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

	ZRdLin()

	This function reads a line from the current input file into the
edit buffer.  It must

	1.  return ERR_NFI if no input file is defined
	2.  read until the end of a line, a form feed, or the end of the
	    file is encountered.
	3.  maintain FFPage, IEof and IFile
	4.  maintain IEof. This variable should be set to -1L when the
	    end of the input file is encountered.

	This function places the input into the edit buffer by appending it
to the edit buffer and adjusting the EndEBf pointer.  IBfEnd points to the
last byte of allocated, unused memory at the end of the edit buffer.
	The line that is inserted into the edit buffer does not have any
terminator at the end:  no line feed or carriage return.

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

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

EXTERN	DEFAULT	CurInp;		/* index of current input stream in IFiles */
EXTERN	char	*EBfEnd;	/* edit buffer end */
EXTERN	LONG	FFPage;		/* form feed flag (see ^E command) */
EXTERN	char	*IBfEnd;	/* input buffer area end */
EXTERN	BOOLEAN	IsEofI[];
EXTERN	struct	IFDBST	IFiles[];




#ifdef UNKNOWN
DEFAULT ZRdLin(length)		/* read a line */
DEFAULT *length;
{
	puts("Terminating in function ZRdLin.\n");
	exit(1);
}
#endif



#ifdef vax11c
#include "DefChars.h"	/* define identifiers for characters */
#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$get();	/* RMS GET service */
VOID	ZDspCh();	/* display a character on the terminal */

EXTERN	struct	message_vector msgvec;
EXTERN	struct	RAB IRab;	/* input RMS record access block */


DEFAULT ZRdLin(length)		/* read a line */
DEFAULT *length;
{
	int	status;

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

	IFiles[CurInp].IRab.rab$l_ubf = EBfEnd+1L;	/* input buffer */
	IFiles[CurInp].IRab.rab$w_usz = 
		((IBfEnd-EBfEnd) > 65535) ? 65535 : (IBfEnd - EBfEnd);

	status = sys$get(&IFiles[CurInp].IRab);		/* get a record */
	if (status == RMS$_EOF)				/* if end of file */
		IsEofI[CurInp] = YES;
	else if (status != RMS$_NORMAL)
		{
		msgvec.msgcod = status;
		msgvec.rmsstv = IRab.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("ZRdLin: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}
	else
		*length = IFiles[CurInp].IRab.rab$w_rsz;
#if DEBUGGING
if(DbgLvl>=2)
{DbgMsg();DbgDBf("ZRdLin: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
#endif



#ifdef XENIX
DEFAULT ZRdLin(length)		/* read a line */
DEFAULT *length;
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=2){DbgMsg();DbgDBf("ZRdLin: called.\015\012");DbgROf();}
#endif

	if (fgets(EBfEnd+1L, IBfEnd-EBfEnd, IFiles[CurInp].IStrem) == NULL)
		IsEofI[CurInp] = YES;
	else
		*length = strlen(EBfEnd+1L) - 1;
#if DEBUGGING
if(DbgLvl>=2)
{DbgMsg();DbgDBf("ZRdLin: returning SUCCESS, length = ");MakDBf(*length,10);
ZDspBf(DBfBeg,DBfPtr-DBfBeg);DbgDBf("\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
#endif
