Home | History | Annotate | Line # | Download | only in larn
      1 /*	$NetBSD: help.c,v 1.9 2012/06/19 05:30:43 dholland Exp $	*/
      2 
      3 /* help.c		Larn is copyrighted 1986 by Noah Morgan. */
      4 #include <sys/cdefs.h>
      5 #ifndef lint
      6 __RCSID("$NetBSD: help.c,v 1.9 2012/06/19 05:30:43 dholland Exp $");
      7 #endif /* not lint */
      8 
      9 #include <unistd.h>
     10 
     11 #include "header.h"
     12 #include "extern.h"
     13 
     14 static void retcont(void);
     15 static int openhelp(void);
     16 
     17 /*
     18  *	help function to display the help info
     19  *
     20  *	format of the .larn.help file
     21  *
     22  *	1st character of file:	# of pages of help available (ascii digit)
     23  *	page (23 lines) for the introductory message (not counted in above)
     24  *	pages of help text (23 lines per page)
     25  */
     26 void
     27 help(void)
     28 {
     29 	int    i, j;
     30 #ifndef VT100
     31 	char            tmbuf[128];	/* intermediate translation buffer
     32 					 * when not a VT100 */
     33 #endif	/* VT100 */
     34 	if ((j = openhelp()) < 0)
     35 		return;		/* open the help file and get # pages */
     36 	for (i = 0; i < 23; i++)
     37 		lgetl();	/* skip over intro message */
     38 	for (; j > 0; j--) {
     39 		clear();
     40 		for (i = 0; i < 23; i++)
     41 #ifdef VT100
     42 			lprcat(lgetl());	/* print out each line that
     43 						 * we read in */
     44 #else	/* VT100 */
     45 		{
     46 			tmcapcnv(tmbuf, lgetl());
     47 			lprcat(tmbuf);
     48 		}		/* intercept \33's */
     49 #endif	/* VT100 */
     50 		if (j > 1) {
     51 			lprcat("    ---- Press ");
     52 			standout("return");
     53 			lprcat(" to exit, ");
     54 			standout("space");
     55 			lprcat(" for more help ---- ");
     56 			i = 0;
     57 			while ((i != ' ') && (i != '\n') && (i != '\33'))
     58 				i = ttgetch();
     59 			if ((i == '\n') || (i == '\33')) {
     60 				lrclose();
     61 				setscroll();
     62 				drawscreen();
     63 				return;
     64 			}
     65 		}
     66 	}
     67 	lrclose();
     68 	retcont();
     69 	drawscreen();
     70 }
     71 
     72 /*
     73  *	function to display the welcome message and background
     74  */
     75 void
     76 welcome(void)
     77 {
     78 	int    i;
     79 #ifndef VT100
     80 	char            tmbuf[128];	/* intermediate translation buffer
     81 					 * when not a VT100 */
     82 #endif	/* VT100 */
     83 	if (openhelp() < 0)
     84 		return;		/* open the help file */
     85 	clear();
     86 	for (i = 0; i < 23; i++)
     87 #ifdef VT100
     88 		lprcat(lgetl());/* print out each line that we read in */
     89 #else	/* VT100 */
     90 	{
     91 		tmcapcnv(tmbuf, lgetl());
     92 		lprcat(tmbuf);
     93 	}			/* intercept \33's */
     94 #endif	/* VT100 */
     95 	lrclose();
     96 	retcont();		/* press return to continue */
     97 }
     98 
     99 /*
    100  *	function to say press return to continue and reset scroll when done
    101  */
    102 static void
    103 retcont(void)
    104 {
    105 	cursor(1, 24);
    106 	lprcat("Press ");
    107 	standout("return");
    108 	lprcat(" to continue: ");
    109 	while (ttgetch() != '\n');
    110 	setscroll();
    111 }
    112 
    113 /*
    114  *	routine to open the help file and return the first character - '0'
    115  */
    116 static int
    117 openhelp(void)
    118 {
    119 	if (lopen(helpfile) < 0) {
    120 		lprintf("Can't open help file \"%s\" ", helpfile);
    121 		lflush();
    122 		sleep(4);
    123 		drawscreen();
    124 		setscroll();
    125 		return (-1);
    126 	}
    127 	resetscroll();
    128 	return (lgetc() - '0');
    129 }
    130