C!----------------------------------------------------------
	SUBROUTINE HELP(STRING,help_lib,prompt)
C
C   Subroutine to enter HELP file structure 
C Modified for "nice" paging (BHT, 12/88)
C-----------------------------------------------------------
	EXTERNAL BHT_PUT_OUTPUT, BHT_GET_INPUT
	INCLUDE '($HLPDEF)'
	INCLUDE '($IODEF)'
	CHARACTER*(*) STRING, help_lib
	INTEGER FLAG
	INTEGER*2 term_chan
	INTEGER IERR,sys$assign,sys$qiow,sys$dassgn
	LOGICAL PROMPT
	byte cbuf(12)
	common /help/ lineno,maxlin
	integer*2 lineno,maxlin
	IF (PROMPT) then 
	  FLAG = HLP$M_HELP .or. HLP$M_LIBLIST .or. HLP$M_PROMPT 
	else
	  FLAG = HLP$M_HELP .or. HLP$M_LIBLIST 
	endif
	lineno = 0
	IF (PROMPT) then 
	  maxlin = 24 - 1
C   assign a channel to SYS$OUTPUT: get # of lines/page for terminal
	  IERR = sys$assign('SYS$OUTPUT',%ref(term_chan),,)
	  ierr = sys$qiow(,%val(term_chan),%val(IO$_SENSEMODE),,,,
	1	%ref(cbuf),%val(12),,,,)
C %val(12) added for V5.5
!	  type *,'term length = ',cbuf(8)
!	  type *,'page width  = ',cbuf(3)
	  IERR = sys$Dassgn(%val(term_chan))
	  maxlin = cbuf(8) - 1
C   recover from QIO error:
	  if (maxlin .le. 1) maxlin = 23
	ELSE
	  maxlin = 32767	! no page control
	endif
	CALL LBR$OUTPUT_HELP(BHT_PUT_OUTPUT,,STRING,help_lib,
     1    flag,BHT_GET_INPUT)
	RETURN
	END
C!----------------------------------------------------------
	SUBROUTINE HELP1(STRING,help_lib,prompt)
C
C   Subroutine to enter HELP file structure -- no Topic? prompt
C-----------------------------------------------------------
	EXTERNAL BHT_PUT_OUTPUT, BHT_GET_INPUT
	INCLUDE '($HLPDEF)'
	INCLUDE '($IODEF)'
	CHARACTER*(*) STRING, help_lib
	INTEGER FLAG
	INTEGER*2 term_chan
	INTEGER IERR,sys$assign,sys$qiow,sys$dassgn
	LOGICAL PROMPT
	byte cbuf(12)
	common /help/ lineno,maxlin
	integer*2 lineno,maxlin
	lineno = 0
	IF (PROMPT) then 
	  maxlin = 24 - 1
C   assign a channel to SYS$OUTPUT: get # of lines/page for terminal
	  IERR = sys$assign('SYS$OUTPUT',%ref(term_chan),,)
	  ierr = sys$qiow(,%val(term_chan),%val(IO$_SENSEMODE),,,,
	1	%ref(cbuf),%val(12),,,,)
C %val(12) added for V5.5
!	  type *,'term length = ',cbuf(8)
!	  type *,'page width  = ',cbuf(3)
	  IERR = sys$Dassgn(%val(term_chan))
	  maxlin = cbuf(8) - 1
C   recover from QIO error:
	  if (maxlin .le. 1) maxlin = 23
	ELSE
	  maxlin = 32767	! no page control
	endif
	FLAG = HLP$M_HELP .or. HLP$M_LIBLIST 
	CALL LBR$OUTPUT_HELP(BHT_PUT_OUTPUT,,STRING,help_lib,
     1    flag,BHT_GET_INPUT)
	RETURN
	END
C-----------------------------------------------------------
	INTEGER FUNCTION BHT_GET_INPUT(string,prompt,ln)
C this routines acts as a "front end" to LIB$GET_INPUT
C it resets the line counter, so that up to a full page will be displayed
C after any requested input.
	character*(*) string,prompt
	integer*2 ln
	INTEGER LIB$GET_INPUT
	common /help/ lineno,maxlin
	integer*2 lineno,maxlin
	BHT_GET_INPUT = LIB$GET_INPUT(string,prompt,ln)
	lineno = 0
	return
	end
C-----------------------------------------------------------
	INTEGER FUNCTION BHT_PUT_OUTPUT(string)
C this routines acts as a "front end" to LIB$PUT_OUTPUT
C it updates a line counter, so that every time the page fills, the
C user must hit return to continue
	character*(*) string,dummy*1
	INTEGER LIB$PUT_OUTPUT, LIB$GET_INPUT
	common /help/ lineno,maxlin
	integer*2 lineno,maxlin
	BHT_PUT_OUTPUT = LIB$PUT_OUTPUT(string)
	if (lineno .ge. maxlin) then
	  BHT_PUT_OUTPUT = LIB$GET_INPUT(dummy,
	1		'Press RETURN to continue ... ')
	  lineno = 0
	ENDIF
	lineno = lineno + 1
	return
	end
