
#include	"sysdef.h"

/*	SCMARK.C						*/
/*								*/
/*	Copyright Notice					*/
/*								*/
/*								*/
/*	C version Copyright (C) 1984 Change Software, Inc.	*/
/*	Copyright (C) 1978 1979 1980 1981 1982 1983 1984 by	*/
/*		      Change Software, Inc.			*/
/*								*/
/*								*/
/*	This software is furnished under a license and may	*/
/*	be  used  and  copied  only in accordance with the	*/
/*	terms of such license and with  the  inclusion  of	*/
/*	the  above copyright notice.  This software or any	*/
/*	other copies thereof may not be provided or other-	*/
/*	wise made available to any other person.  No title	*/
/*	to and ownership of the software is hereby  trans-	*/
/*	ferred.							*/
/*								*/


#include	"scerrd.h"
#define	then


struct mark	{
		int	linenumber ;
		CHAR	c[32] ;
		} ;

#define	MAXMARK	4
extern struct mark markbuffer[] ;


vtpushmark()

{
	extern int *curline,rept,worklength ;
	extern CHAR workbuffer[] ;
	register CHAR *wp ;
	register int i,place ;

	if ( rept < 0 ) then return(0) ;
	if ( rept > MAXMARK )
	  then	{
		scwarning(w_badmark) ;
		return(0) ;
		}
	  else	{
		if ( (place = rept) == 0 && markbuffer[0].linenumber != 0 )
		  then	{
			for (i=0; i <= MAXMARK;i++)
			  if (markbuffer[i].linenumber == 0)
			    then {
				place = i ;
				break ;
				}
			ceol24() ;
			if ( place != 0 )
			  then	{
				putbin("Markbuffer 0 in use, number ",0) ;
				scdecout(place) ;
				putbin(" used.",0) ;
				}
			  else	putbin("All markers in use, zero reused",0);
			goback() ;
			}
			
		markbuffer[place].linenumber = *curline ;
		mcopy(markbuffer[place].c,workbuffer,worklength);
		rept = 0 ;
		return(1) ;
		}
}


vtpopmark()
{
	extern int *curline,*maxline,rept,worklength ;
	extern CHAR workbuffer[] ;
	register int status ;

	if ( rept > MAXMARK )
	  then	{
		scwarning(w_badmark) ;
		status = 0 ;
		}
	  else	{
		if ( markbuffer[rept].linenumber < *maxline )
		  then	{
			*curline = markbuffer[rept].linenumber ;
			creset() ;
			cnpage( *curline ) ;
			status = 1 ;
			}
		  else	status = 0 ;
		}
	rept = 0 ;
	return( status ) ;
}
	

vtmview()
{
	register int i,j ;
	register CHAR *cp ;

	for (i=0; i <= MAXMARK; i++ ) {
		if ( markbuffer[i].linenumber != 0 )
		  then	{
		    cp = markbuffer[i].c ;
		    ceol24() ;
		    putbin("Mark # ",0) ;
		    scdecout(i) ;
		    scdecout(markbuffer[i].linenumber) ;
		    putbin("  ",0) ;
		    for (j=0;j<32 && isdelimiter(*cp)==0;j++) putbin(cp++,1);
		    suspend(3) ;
			}
		}
	goback() ;
	return(1) ;
}
			
	
static mcopy(to,from,size)
CHAR *to,*from ;
int size ;
{
	register int i ;
	register CHAR *fp,*tp ;

	if ( size == 0 )
	  then	return(0) ;
	  else	{
		if ( size > 32 ) then size = 32 ;
		fp = from ;
		tp = to ;
		for ( i=size; i>0; i--) *tp++ = *fp++ ;
		*tp = 0 ;
		}
	return(1) ;
}
	

