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