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