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