2 * Copyright (c) 1998 Eric P. Scott <eps@sirius.com>
3 * Copyright (c) 1998 Andrzej Bialecki <abial@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $Id: help.c,v 1.3 1998/09/23 14:51:34 abial Exp $
34 #include <sys/ioctl.h>
36 int display(FILE *, const char *);
38 static int cnt, crt=-1;
41 main(int argc, char *argv[])
47 if (!(fd=fopen("/help.a", "r"))) {
48 (void)fputs("Couldn't open help archive.\n", stderr);
52 if (ioctl(fileno(stdout), TIOCGWINSZ, &ts)>=0) {
56 s=display(fd, argc>1 ? argv[1] : "help");
58 else for (i=2;i<argc;) {
60 s|=display(fd, argv[i++]);
76 (void)fputs("\033[7mPress Enter to continue\033[m", stderr);
79 if (fgets(buf, sizeof buf, stdin)) return 0;
80 (void)fputc('\n', stderr);
85 display(FILE *fd, const char *fname)
92 if (!fgets(aname, sizeof aname, fd)) {
95 if (strncmp(aname, ARMAG, SARMAG)) return 1;
96 (void)snprintf(aname, sizeof(aname), "%s/", fname);
98 if (fread((void *)&ar, sizeof ar, 1, fd)!=1) return 1;
99 if (strncmp(ar.ar_fmag, ARFMAG, 2)) return 1;
103 if ((c=(int)(*p++-'0'))<0||c>9) break;
105 } while (p<&ar.ar_size[sizeof ar.ar_size]);
106 if (!strncmp(ar.ar_name, aname, strlen(aname))) break;
107 if (fseek(fd, (long)n, SEEK_CUR)<0) return 1;
108 if ((n&1)&&fgetc(fd)!='\n') return 1;
110 if (cnt>=crt&&more()) return -1;
111 (void)fputc('\n', stdout);
113 o=0; while (o<n&&(c=fgetc(fd))!=EOF) {
116 (void)fputc(c, stdout);
117 if (c!='\n') continue;
118 if (++cnt<crt) continue;
119 if (o>=n||(c=fgetc(fd))==EOF) break;
120 if (more()) return -1;
123 if (cnt>=crt&&more()) return -1;
124 (void)fputc('\n', stdout);
126 if (!strcmp(fname, "help")) {
128 (void)fgets(aname, sizeof aname, fd);
129 if (cnt>=crt&&more()) return -1;
130 (void)fputs("The following help items are available:\n",
134 while (fread((void *)&ar, sizeof ar, 1, fd)==1) {
135 if (strncmp(ar.ar_fmag, ARFMAG, 2)) break;
137 (void)fputc('\n', stdout);
138 if (++cnt>=crt&&more()) return -1;
140 *(index(ar.ar_name,'/'))=' ';
141 (void)printf("%.13s", ar.ar_name);
146 if ((c=(int)(*p++-'0'))<0||c>9) break;
148 } while (p<&ar.ar_size[sizeof ar.ar_size]);
149 if (fseek(fd, (long)n, SEEK_CUR)<0) break;
150 if ((n&1)&&fgetc(fd)!='\n') break;
152 if (cnt>=crt&&more()) return -1;
153 (void)fputc('\n', stdout);