xref: /netbsd-src/games/larn/help.c (revision c34afa686bf074a6dcc7f17157faae72111dde9a)
1*c34afa68Sdholland /*	$NetBSD: help.c,v 1.9 2012/06/19 05:30:43 dholland Exp $	*/
2210cab45Smycroft 
361f28255Scgd /* help.c		Larn is copyrighted 1986 by Noah Morgan. */
4a8fba37dSchristos #include <sys/cdefs.h>
5a8fba37dSchristos #ifndef lint
6*c34afa68Sdholland __RCSID("$NetBSD: help.c,v 1.9 2012/06/19 05:30:43 dholland Exp $");
7a8fba37dSchristos #endif /* not lint */
8a8fba37dSchristos 
9a8fba37dSchristos #include <unistd.h>
10a8fba37dSchristos 
1161f28255Scgd #include "header.h"
12a8fba37dSchristos #include "extern.h"
13d7ba3de7Sdholland 
14f2a20f5fSdholland static void retcont(void);
15d7ba3de7Sdholland static int openhelp(void);
16d7ba3de7Sdholland 
1761f28255Scgd /*
1861f28255Scgd  *	help function to display the help info
1961f28255Scgd  *
2061f28255Scgd  *	format of the .larn.help file
2161f28255Scgd  *
2261f28255Scgd  *	1st character of file:	# of pages of help available (ascii digit)
2361f28255Scgd  *	page (23 lines) for the introductory message (not counted in above)
2461f28255Scgd  *	pages of help text (23 lines per page)
2561f28255Scgd  */
26a8fba37dSchristos void
help(void)27*c34afa68Sdholland help(void)
2861f28255Scgd {
29a8fba37dSchristos 	int    i, j;
3061f28255Scgd #ifndef VT100
31a8fba37dSchristos 	char            tmbuf[128];	/* intermediate translation buffer
32a8fba37dSchristos 					 * when not a VT100 */
33a8fba37dSchristos #endif	/* VT100 */
34a8fba37dSchristos 	if ((j = openhelp()) < 0)
35a8fba37dSchristos 		return;		/* open the help file and get # pages */
36a8fba37dSchristos 	for (i = 0; i < 23; i++)
37a8fba37dSchristos 		lgetl();	/* skip over intro message */
38a8fba37dSchristos 	for (; j > 0; j--) {
3961f28255Scgd 		clear();
4061f28255Scgd 		for (i = 0; i < 23; i++)
4161f28255Scgd #ifdef VT100
42a8fba37dSchristos 			lprcat(lgetl());	/* print out each line that
43a8fba37dSchristos 						 * we read in */
44a8fba37dSchristos #else	/* VT100 */
4561f28255Scgd 		{
46a8fba37dSchristos 			tmcapcnv(tmbuf, lgetl());
47a8fba37dSchristos 			lprcat(tmbuf);
48a8fba37dSchristos 		}		/* intercept \33's */
49a8fba37dSchristos #endif	/* VT100 */
50a8fba37dSchristos 		if (j > 1) {
51a8fba37dSchristos 			lprcat("    ---- Press ");
52a8fba37dSchristos 			standout("return");
53a8fba37dSchristos 			lprcat(" to exit, ");
54a8fba37dSchristos 			standout("space");
5561f28255Scgd 			lprcat(" for more help ---- ");
56a8fba37dSchristos 			i = 0;
57a8fba37dSchristos 			while ((i != ' ') && (i != '\n') && (i != '\33'))
58c310e89dSdholland 				i = ttgetch();
59a8fba37dSchristos 			if ((i == '\n') || (i == '\33')) {
60a8fba37dSchristos 				lrclose();
61a8fba37dSchristos 				setscroll();
62a8fba37dSchristos 				drawscreen();
63a8fba37dSchristos 				return;
6461f28255Scgd 			}
6561f28255Scgd 		}
6661f28255Scgd 	}
67a8fba37dSchristos 	lrclose();
68a8fba37dSchristos 	retcont();
69a8fba37dSchristos 	drawscreen();
7061f28255Scgd }
7161f28255Scgd 
7261f28255Scgd /*
7361f28255Scgd  *	function to display the welcome message and background
7461f28255Scgd  */
75a8fba37dSchristos void
welcome(void)76*c34afa68Sdholland welcome(void)
7761f28255Scgd {
78a8fba37dSchristos 	int    i;
7961f28255Scgd #ifndef VT100
80a8fba37dSchristos 	char            tmbuf[128];	/* intermediate translation buffer
81a8fba37dSchristos 					 * when not a VT100 */
82a8fba37dSchristos #endif	/* VT100 */
83a8fba37dSchristos 	if (openhelp() < 0)
84a8fba37dSchristos 		return;		/* open the help file */
8561f28255Scgd 	clear();
8661f28255Scgd 	for (i = 0; i < 23; i++)
8761f28255Scgd #ifdef VT100
8861f28255Scgd 		lprcat(lgetl());/* print out each line that we read in */
89a8fba37dSchristos #else	/* VT100 */
90a8fba37dSchristos 	{
91a8fba37dSchristos 		tmcapcnv(tmbuf, lgetl());
92a8fba37dSchristos 		lprcat(tmbuf);
93a8fba37dSchristos 	}			/* intercept \33's */
94a8fba37dSchristos #endif	/* VT100 */
95a8fba37dSchristos 	lrclose();
96a8fba37dSchristos 	retcont();		/* press return to continue */
9761f28255Scgd }
9861f28255Scgd 
9961f28255Scgd /*
10061f28255Scgd  *	function to say press return to continue and reset scroll when done
10161f28255Scgd  */
102f2a20f5fSdholland static void
retcont(void)103*c34afa68Sdholland retcont(void)
10461f28255Scgd {
105a8fba37dSchristos 	cursor(1, 24);
106a8fba37dSchristos 	lprcat("Press ");
107a8fba37dSchristos 	standout("return");
108a8fba37dSchristos 	lprcat(" to continue: ");
109c310e89dSdholland 	while (ttgetch() != '\n');
11061f28255Scgd 	setscroll();
11161f28255Scgd }
11261f28255Scgd 
11361f28255Scgd /*
11461f28255Scgd  *	routine to open the help file and return the first character - '0'
11561f28255Scgd  */
116d7ba3de7Sdholland static int
openhelp(void)117d7ba3de7Sdholland openhelp(void)
11861f28255Scgd {
119a8fba37dSchristos 	if (lopen(helpfile) < 0) {
12061f28255Scgd 		lprintf("Can't open help file \"%s\" ", helpfile);
121a8fba37dSchristos 		lflush();
122a8fba37dSchristos 		sleep(4);
123a8fba37dSchristos 		drawscreen();
124a8fba37dSchristos 		setscroll();
125a8fba37dSchristos 		return (-1);
12661f28255Scgd 	}
127a8fba37dSchristos 	resetscroll();
128a8fba37dSchristos 	return (lgetc() - '0');
12961f28255Scgd }
130