
#include	"sysdef.h"

#include	"scerrd.h"

#define	then
#define	LF	012
#define	CR	015


sclinsert(ch)
char ch ;
{
	extern char workbuffer[] ;
	extern int  worklength ;
	register char *wp ;
	register int  *ip ;
	extern int *curline,loaded,nwhite,cnt_lines;
	extern int *loclow,*lochigh,*maxline,page_size[],termtype ;

	nwhite = 0 ;
	scunloadline() ;
	ins_scline() ;
	scloadline() ;
	txtmod() ;
	wp = workbuffer ;
	ip = &worklength ;
	*ip = 1 ;
	*wp++ = ch ;
	if ( ch == CR )
	  then	{
		*wp++ = LF ;
		(*ip)++ ;
		}
	  else	{
		if ( ch == LF )
		  then	{
			*wp++ = CR ;
			*wp++ = '\0' ;
			(*ip)++ ;
			(*ip)++ ;
			}
		}
	if ( scttin() ) then scxnewline() ;
	if ( *lochigh - *loclow < page_size[termtype] )
	  then	{
		(*lochigh)++ ;
		if ( *lochigh >= *maxline ) then (*lochigh)-- ;
		}
	if ( *curline > *lochigh ) then sclinc() ;
	creset() ;
}
	
