
/*	VTSWAP.C						*/
/*								*/
/*	Copyright Notice					*/
/*								*/
/*								*/
/*	C version Copyright (C) 1984 Change Software, Inc.	*/
/*	Copyright (C) 1978 1979 1980 1981 1982 1983 1984 1985	*/
/*		      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	"sysdef.h"
#include	"tempio.h"
#include	"scerrd.h"

#define	CR	015
#define	LF	012
#define	FF	014
#define	TAB	011

#define	then





/*	VTSWPCH	swap current character for next character		*/

#define	TAB	011

vtswpch()
{
	register char ch1,ch2,*cp ;
	extern char workbuffer[] ;
	extern int chposition,read_only ;

	if ( read_only ) then return(0) ;
	if ( atcrlf() ) then return(0) ;
	pinc() ;
	if ( atcrlf() ) then return(0) ;
	pdec() ;
	cp = &workbuffer[chposition] ;
	ch1 = *cp++ ;
	ch2 = *cp ;
	*cp-- = ch1 ;
	*cp = ch2 ;
	txtmod() ;
	if ( ! ( ch1==TAB || ch2==TAB ) )
	  then	putbin(cp,2) ;
	  else	{
		lkill() ;
		partdump() ;
		}
	scmove() ;
	return(1) ;
}




vtswpline()
{

/*	25-JUN-1985 10:13  BDN	Remove MALLOC() calls	*/

	char junk1[_MAXLEN+2],junk2[_MAXLEN+2] ;
	extern int *curline,*lochigh,maxlen,*maxline,worklength,read_only ;
	extern char workbuffer[] ;
	char *l1save,*l2save ;
	int   l1len, l2len ;

	l1save = junk1 ;
	l2save = junk2 ;
	scopy(l1save,workbuffer,worklength) ;
	l1len = worklength ;
	scunloadline() ;
	creset() ;
	if ( ++(*curline) < *maxline )
	  then	{
		scloadline() ;
		if ( read_only == 0 )
		  then	{
			l2len = worklength ;
			scopy(l2save,workbuffer,worklength) ;
			scopy(workbuffer,l1save,l1len) ;
			worklength = l1len ;
			txtmod() ;
			if ( *curline <= *lochigh )
			  then	{
				scmove() ;
				lkill() ;
				dumpworkbuffer() ;
				}
			scunloadline() ;
			(*curline)-- ;
			scloadline() ;
			scopy(workbuffer,l2save,l2len) ;
			worklength = l2len ;
			txtmod() ;
			scmove() ;
			lkill() ;
			dumpworkbuffer() ;
			}
		}
	  else	(*curline)-- ;
	scmove() ;
	return(1) ;
}
