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