1*9f61b804Splunky /* $NetBSD: help.c,v 1.7 2011/08/31 16:24:55 plunky Exp $ */
2d4f96eeaScgd
386ef2669Sjtc /*-
486ef2669Sjtc * Copyright (c) 1993
586ef2669Sjtc * The Regents of the University of California. All rights reserved.
686ef2669Sjtc *
786ef2669Sjtc * This code is derived from software contributed to Berkeley by
886ef2669Sjtc * Barry Brachman.
986ef2669Sjtc *
1086ef2669Sjtc * Redistribution and use in source and binary forms, with or without
1186ef2669Sjtc * modification, are permitted provided that the following conditions
1286ef2669Sjtc * are met:
1386ef2669Sjtc * 1. Redistributions of source code must retain the above copyright
1486ef2669Sjtc * notice, this list of conditions and the following disclaimer.
1586ef2669Sjtc * 2. Redistributions in binary form must reproduce the above copyright
1686ef2669Sjtc * notice, this list of conditions and the following disclaimer in the
1786ef2669Sjtc * documentation and/or other materials provided with the distribution.
18e5aeb4eaSagc * 3. Neither the name of the University nor the names of its contributors
1986ef2669Sjtc * may be used to endorse or promote products derived from this software
2086ef2669Sjtc * without specific prior written permission.
2186ef2669Sjtc *
2286ef2669Sjtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2386ef2669Sjtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2486ef2669Sjtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2586ef2669Sjtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2686ef2669Sjtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2786ef2669Sjtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2886ef2669Sjtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2986ef2669Sjtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3086ef2669Sjtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3186ef2669Sjtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3286ef2669Sjtc * SUCH DAMAGE.
3386ef2669Sjtc */
3486ef2669Sjtc
3527bf0524Slukem #include <sys/cdefs.h>
3686ef2669Sjtc #ifndef lint
37d4f96eeaScgd #if 0
3886ef2669Sjtc static char sccsid[] = "@(#)help.c 8.1 (Berkeley) 6/11/93";
39d4f96eeaScgd #else
40*9f61b804Splunky __RCSID("$NetBSD: help.c,v 1.7 2011/08/31 16:24:55 plunky Exp $");
41d4f96eeaScgd #endif
4286ef2669Sjtc #endif /* not lint */
4386ef2669Sjtc
4486ef2669Sjtc #include <curses.h>
4586ef2669Sjtc #include <stdio.h>
4686ef2669Sjtc
4786ef2669Sjtc #include "bog.h"
4886ef2669Sjtc #include "extern.h"
4986ef2669Sjtc
50f06735e8Schristos extern int nlines;
51ed65ee16Sjmc
5286ef2669Sjtc int
help(void)53ed65ee16Sjmc help(void)
5486ef2669Sjtc {
5586ef2669Sjtc int eof, i;
5686ef2669Sjtc FILE *fp;
5786ef2669Sjtc WINDOW *win;
5886ef2669Sjtc char buf[BUFSIZ];
5986ef2669Sjtc
6086ef2669Sjtc if ((fp = fopen(HELPFILE, "r")) == NULL)
6186ef2669Sjtc return(-1);
6286ef2669Sjtc win = newwin(0, 0, 0, 0);
6386ef2669Sjtc clearok(win, 1);
6486ef2669Sjtc
6586ef2669Sjtc eof = 0;
6686ef2669Sjtc if (ungetc(getc(fp), fp) == EOF) {
6786ef2669Sjtc wprintw(win, "There doesn't seem to be any help.");
6886ef2669Sjtc eof = 1; /* Nothing there... */
6986ef2669Sjtc }
7086ef2669Sjtc
7186ef2669Sjtc while (!eof) {
7286ef2669Sjtc for (i = 0; i < nlines - 3; i++) {
73*9f61b804Splunky if (fgets(buf, sizeof(buf), fp) == NULL) {
7486ef2669Sjtc eof = 1;
7586ef2669Sjtc break;
7686ef2669Sjtc }
7786ef2669Sjtc if (buf[0] == '.' && buf[1] == '\n')
7886ef2669Sjtc break;
7986ef2669Sjtc wprintw(win, "%s", buf);
8086ef2669Sjtc }
8186ef2669Sjtc if (eof || ungetc(getc(fp), fp) == EOF) {
8286ef2669Sjtc eof = 1;
8386ef2669Sjtc break;
8486ef2669Sjtc }
8586ef2669Sjtc wmove(win, nlines - 1, 0);
8686ef2669Sjtc wprintw(win,
8786ef2669Sjtc "Type <space> to continue, anything else to quit...");
8886ef2669Sjtc wrefresh(win);
8986ef2669Sjtc if ((inputch() & 0177) != ' ')
9086ef2669Sjtc break;
9186ef2669Sjtc wclear(win);
9286ef2669Sjtc }
9386ef2669Sjtc
9486ef2669Sjtc fclose(fp);
9586ef2669Sjtc if (eof) {
9686ef2669Sjtc wmove(win, nlines - 1, 0);
9786ef2669Sjtc wprintw(win, "Hit any key to continue...");
9886ef2669Sjtc wrefresh(win);
9986ef2669Sjtc inputch();
10086ef2669Sjtc }
10186ef2669Sjtc delwin(win);
10286ef2669Sjtc clearok(stdscr, 1);
10386ef2669Sjtc refresh();
10486ef2669Sjtc return(0);
10586ef2669Sjtc }
106