

/*								*/
/*	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	"scerrd.h"
#include	"scterm.h"
#include	"tempio.h"

#define	CR	015
#define	LF	012
#define	FF	014
#define	SPACE	040
#define	tab	011
#define	TAB	011
#define	false	0
#define	true	1
#define	then

extern int chposition,curposition,worklength ;
extern char workbuffer[] ;


/*	SVINSERT							*/
/*									*/
/*	Insert last deleted line buffer into the current line at 'WHERE'*/
/*	Slow but simple, since we don't use it often.			*/


svlinsert(where)
int where;
{
	extern struct deltype lastdeleted ;

	return(svinsert(where,lastdeleted.lastline.c,lastdeleted.lastline.len));
}


svwinsert(where)
int where;
{
	extern struct deltype lastdeleted ;

	return(svinsert(where,lastdeleted.lastword.c,lastdeleted.lastword.len));
}

svcinsert(where)
int where;
{
	extern struct deltype lastdeleted ;

	if ( lastdeleted.lastc != '\0' )
	  then return(svinsert(where,&lastdeleted.lastc,1)) ;
	  else return(0) ;
}


svinsert(where,s,len)
char *s ;
int len,where ;
{
	extern int maxlen,worklength ;
	extern char workbuffer[] ;
	extern struct deltype lastdeleted ;
	register char *cp,*wp ;
	register int i ;
	int j ;

	if ( where >= worklength || where < 0 ) then return(0) ;
	if ( len == 0 ) then return(0) ;
	for ( j=0; j < len && worklength < maxlen; j++ ) {

		txtmod() ;
		wp = &workbuffer[worklength] ;
		cp = wp ;
		for ( i=0; i<worklength-where; i++ ) *wp-- = *(--cp) ;
		workbuffer[where] = *s++ ;
		worklength++ ;
		where++ ;
		}
	return(len) ;
}



remchar(where)
register int where ;
{
	extern int worklength ;
	extern struct deltype lastdeleted ;
	register char *cp,*dp ;
	extern char workbuffer[] ;
	int i ;

	if ( where >= worklength ) then return(0) ;
	txtmod() ;
	worklength-- ;
	cp = &workbuffer[where] ;
	dp = cp ;
	lastdeleted.lastc = *dp++ ;
	for ( i = worklength-where; i > 0 ; i-- ) *cp++ = *dp++ ;
	return(lastdeleted.lastc) ;
}


delword()
{
	extern struct deltype lastdeleted ;
	register char *cp, csave ;

	csave = lastdeleted.lastc ;
	lastdeleted.lastword.len = 0 ;
	cp = lastdeleted.lastword.c ;
	if ( atworddelim()==0 )
	  while (atcrlf()==0 && atworddelim()==0 && remchar(chposition))
			{
			if ( isdelimiter(lastdeleted.lastc) == 0 )
			  then	{
				*cp++ = lastdeleted.lastc ;
				lastdeleted.lastword.len++ ;
				}
			}
	while (atcrlf() == 0 && atworddelim() && remchar(chposition));
			{
			if ( isdelimiter(lastdeleted.lastc) == 0 )
			  then	{
				*cp++ = lastdeleted.lastc ;
				lastdeleted.lastword.len++ ;
				}
			}
	putbin(lastdeleted.lastword.c,lastdeleted.lastword.len);
	lastdeleted.lastc = csave ;
}
