
#include	"sysdef.h"

/*								*/
/*	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	"scerrd.h"
#include	"tempio.h"
#define	then
#define	CR	015
#define	FF	014
#define	LF	012
#define	SPACE	040
#define	TAB	011

extern int  chposition,*curline,curposition,*loclow,*lochigh ;


/*	VTSENT()	find the next sentence in the text		*/
/*			We could use FNNEXT but that could involve some	*/
/*			extra cursor moves or page reprinting.		*/

static char dotsp[] = ". " ;
static char dotcr[] = ".\015" ;

vtsent()
{
	register char *cp ;
	extern int chposition,curposition,*curline,*maxline,worklength ;
	extern char workbuffer[] ;
	register int off,pos ;
	int more,oldchposition,oldcurposition,oldcurline,status ;

	status = 0 ;			/* assume the search will fail	*/
	oldcurline = *curline ;		/* save the old current line #	*/
	off = chposition+1 ;
	scunloadline() ;
	while ( *curline < *maxline ) {
		scloadline() ;
		if (   (pos=finstr(&workbuffer[off],worklength-off,dotsp,2)) 
		    || (pos=finstr(&workbuffer[off],worklength-off,dotcr,2)))
		  then	break ;
		off = 0 ;
		(*curline)++ ;
	}
	if ( pos == 0 )
	  then	{
		*curline = oldcurline ;
		scloadline() ;
		scwarning( w_nopat ) ;
		status = 0 ;
		}
	  else	{
		chposition = pos + off - 1 ;
		fixposition() ;
		oldcurline = *curline ;
		oldchposition = chposition ;
		nextword() ;
		cp = workbuffer ;
		while ( atcrlf() && (more=(++(*curline) < *maxline)) ) {
			scloadline() ;
			creset() ;
			if ( *cp == ' ' || *cp == TAB ) then nextword() ;
			}
		if ( !more )
		  then	{
			*curline = oldcurline ;
			chposition = oldchposition ;
			scloadline() ;
			fixposition() ;
			}
		if ( *curline > *lochigh )
		  then	{
			oldchposition = chposition ;
			oldcurposition = curposition ;
			cnpage( *curline ) ;
			chposition = oldchposition ;
			curposition = oldcurposition ;
			}
		scmove() ;
		status = chposition+1 ;
		}
	return( status ) ;
}


static nextword()
{
	while ( atcrlf() == 0 && attabspace() == 0 ) pinc() ;
	while ( atcrlf() == 0 && attabspace() ) pinc() ;	
	return(1) ;
}




#define	then

vtepara()
{
	extern int *curline,chposition,curposition,*maxline,worklength ;
	extern int *loclow,*lochigh ;
	extern char workbuffer[] ;
	register int match,status ;
	register char *cp ;
	int oldchposition,oldcurposition,oldcurline ;

	oldchposition = chposition ;
	oldcurposition = curposition ;
	oldcurline = *curline ;
	creset() ;
	match = 0 ;
	cp = workbuffer ;
	while ( match == 0 && ++(*curline) < *maxline ) {
		scloadline() ;
		match = ( isdelimiter(*cp) || *cp == SPACE || *cp == TAB ) ;
		}
	if ( match == 0 )
	  then	{
		scwarning(w_nopat) ;
		chposition = oldchposition ;
		curposition = oldcurposition ;
		*curline = oldcurline ;
		scloadline() ;
		scmove() ;
		status = 0 ;
		}
	  else	{
		if ( *curline > *lochigh ) then cnpage( *curline ) ;
		scloadline() ;
		scmove() ;
		status = 1 ;
		}
	return( status ) ;
}
	
			

	


vtnpara()
{
	extern int *curline,chposition,curposition,*maxline,worklength ;
	extern int *loclow,*lochigh ;
	extern char workbuffer[] ;
	register int match,status ;
	register char *cp ;
	int oldchposition,oldcurposition,oldcurline ;
	
	oldchposition = chposition ;
	oldcurposition = curposition ;
	oldcurline = *curline ;
	if ( vtepara() )
	  then	{
		creset() ;
		match = 0 ;
		while ( match == 0 && ++(*curline) < *maxline ) {
			cp = workbuffer ;
			scloadline() ;
			while ( *cp == SPACE || *cp == TAB ) cp++ ;
			match = ( isdelimiter(*cp) == 0 ) ;
			}
		if ( match == 0 )
		  then	{
			scwarning(w_nopat) ;
			chposition = oldchposition ;
			curposition = oldcurposition ;
			*curline = oldcurline ;
			scloadline() ;
			scmove() ;
			status = 0 ;
			}
		  else	{
			if ( *curline > *lochigh ) then cnpage( *curline ) ;
			scloadline() ;
			scmove() ;
			status = 1 ;
			}
		}
	  else	status = 0 ;
	return( status ) ;
}
	
			
