/* EDMOVE.C */
#include	"sysdef.h"

#define	then
/*								*/
/*	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.							*/
/*								*/
/*	The information in this  software  is  subject  to	*/
/*	change  without notice and should not be construed	*/
/*	as a commitment by the author.				*/
/*								*/
/*								*/

#include	"scerrd.h"
#include	"tempio.h"

#define	CR	015
#define	LF	012

cmove()
{
	extern int	highlim,lowlim,target,*maxline ;
	register int	lineno,status ;

	if ( target == 0 )
	  then	{
		tederror("Need a :TARGET line for destination");
		return(0) ;
		}
	if ( target >= lowlim && target <= highlim )
	  then	{
		tederror("Can't move into a move range") ;
		return(0) ;
		}

	if ( highlim == lowlim ) 
	  then	{
		if ( (status=delline( lowlim )) != 0 )
		  then status = undelline(target) ;
		return( status ) ;
		}

	status = 1 ;
	if ( target < lowlim )
	  then	{
		for (lineno=highlim; lineno>=lowlim && status!=0;lineno--)
			if ( (status=delline( highlim )) != 0 )
			  then status = undelline(target) ;
		}
	  else	{
		for (lineno=lowlim; lineno<=highlim && status!=0;lineno++)
			if ( (status=delline( lowlim )) != 0 )
			  then status = undelline(target+highlim-lowlim) ;
		}
	return( status ) ;
		
}




ccopy()
{
	extern int	highlim,lowlim,target,*maxline ;
	extern struct	textline inline ;
	extern struct	textline *textpointer() ;
	register struct	textline *tp ;
	register int	lineno,startline ;
	int status ;

	if ( target == 0 ) then target = *maxline ;
	if ( target >= lowlim && target <= highlim )
	  then	{
		tederror("Can't copy into a copy range") ;
		return(0) ;
		}

	status = 1 ;
	startline = lowlim ;
	for (lineno=lowlim; lineno<=highlim && status!=0;lineno++) {
		tp = textpointer(startline++) ;
		scopy(inline.c,tp->c,tp->len) ;
		inline.len = tp->len ;
		status = doinsert(target++,inline.c,inline.len) ;
		if ( target < lowlim ) then startline++ ;
		}
	return( status ) ;
		
}
