/*	SCHELP.C	Driver for screen help			*/
/*								*/
/*	15-AUG-1985 16:31  removed from orig schelp.c to allow	*/
/*	overlaying of the help subsystem in PDP-11 TED.		*/
/*								*/
/*	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"

static char tedhfile[] = "TEDHELP" ;

static
char *vthelpfile[] = {
		""		,
		"TEDANSI"	,
		"TEDVT100"	,
		"TEDVT220"	,
		""		} ;

static char buffer[512] ;
static char notopic[] = "" ;
static char nulltopic[] = "\01" ;
static char lnmenu[] = "lnmenu" ;

#define	then
#define	VTOPEN	1
#define	TEDOPEN	2


static char tednotfound[]="Help not found for that topic\015\012" ;

tedhelp(s)
char *s ;
{
	int status ;
	extern char *hlbuffer ;
	extern int hlpopen,hlpctx[] ;
	extern char *gettopic(),*expcommand() ;
	register char *topic ;

	hlbuffer = &buffer ;
	hlpctx[0] = 0 ;
	if ( hlpopen != TEDOPEN )
	  then if ( ( status = opnhlp(tedhfile) ) == 0 )
		  then	{
			tederror("Can't open editor help file") ;
			hlpopen = 0 ;
			return(0) ;
			}
	hlpopen = TEDOPEN ;
	topic = &notopic ;

	if ( *s != 0 )
	  then	{
		topic = expcommand(s) ;
		if ( *topic == 0 )
		  then	putbin(tednotfound,0) ;
		  else	dsptopic(topic) ;
		}
	  else	{
		dsptopic(lnmenu) ;
		while ( *topic != *nulltopic )
		  if ( *(topic=gettopic(TEDOPEN)) != *nulltopic )
		    then
			if ( *topic == *notopic )
			  then	{
				putbin(tednotfound,0) ;
				suspend(2) ;
				}
			  else	dsptopic(topic) ;
		}
	putbin("\015\012",0) ;
	return(1) ;
}


