aboutsummaryrefslogtreecommitdiff
path: root/release/picobsd/tinyware/help/help.c
diff options
context:
space:
mode:
Diffstat (limited to 'release/picobsd/tinyware/help/help.c')
-rw-r--r--release/picobsd/tinyware/help/help.c163
1 files changed, 111 insertions, 52 deletions
diff --git a/release/picobsd/tinyware/help/help.c b/release/picobsd/tinyware/help/help.c
index fda11a60bb63..ed390324f3c4 100644
--- a/release/picobsd/tinyware/help/help.c
+++ b/release/picobsd/tinyware/help/help.c
@@ -1,5 +1,6 @@
/*-
- * Copyright (c) 1998 Andrzej Bialecki
+ * Copyright (c) 1998 Eric P. Scott <eps@sirius.com>
+ * Copyright (c) 1998 Andrzej Bialecki <abial@nask.pl>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,75 +24,133 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: help.c,v 1.1.1.1 1998/07/14 07:30:53 abial Exp $
- *
+ * $Id$
*/
#include <stdio.h>
#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <ar.h>
+#include <sys/ioctl.h>
+
+int display(FILE *, const char *);
+
+static int cnt, crt=-1;
-void
-display(char *fname)
+int
+main(int argc, char *argv[])
{
+ register int i, s;
FILE *fd;
- DIR *dirp;
- struct dirent *d;
- char buf[100],junk[5],c, *dot;
- int i;
+ struct ttysize ts;
- snprintf(buf,99,"/help/%s.hlp",fname);
- if((fd=fopen(buf,"r"))==NULL) {
- printf("No help available for '%s'.\n",fname);
+ if (!(fd=fopen("/help.a", "r"))) {
+ (void)fputs("Couldn't open help archive.\n", stderr);
exit(1);
}
- printf("\n");
- i=0;
- while(!feof(fd)) {
- if(fgets(buf,99,fd)==NULL) continue;
- if(i<23) {
- printf("%s",buf);
- i++;
- } else {
- printf("Press Enter to continue");
- fgets(junk,5,stdin);
- printf("%s",buf);
- i=0;
- }
+ cnt=0;
+ if (ioctl(fileno(stdout), TIOCGWINSZ, &ts)>=0) {
+ crt=ts.ts_lines-1;
}
- printf("\n");
- i=0;
- if(strcmp(fname,"help")==0) {
- printf("The following help items are available:\n\n");
- dirp=opendir("/help/.");
- while((d=readdir(dirp))!=NULL) {
- if(d->d_name[0]=='.') continue;
- if((dot=strchr(d->d_name,'.'))!=NULL) {
- *dot='\0';
- }
- printf("%-13s",d->d_name);
- i++;
- if(i>5) {
- printf("\n");
- i=0;
- }
+ if (crt<3) crt=23;
+ s=display(fd, argc>1 ? argv[1] : "help");
+ if (s<0) s=0;
+ else for (i=2;i<argc;) {
+ rewind(fd);
+ s|=display(fd, argv[i++]);
+ if (s<0) {
+ s=0;
+ break;
}
- closedir(dirp);
- printf("\n");
}
- return;
+ (void)fclose(fd);
+ exit(s);
}
+int
+more(void)
+{
+ char buf[8];
+
+ (void)fflush(stdout);
+ (void)fputs("\033[7mPress Enter to continue\033[m", stderr);
+ (void)fflush(stderr);
+ cnt=0;
+ if (fgets(buf, sizeof buf, stdin)) return 0;
+ (void)fputc('\n', stderr);
+ return 1;
+}
int
-main(int argc, char *argv[])
+display(FILE *fd, const char *fname)
{
- if(argc==1) {
- display("help");
- } else {
- display(argv[1]);
+ register char *p;
+ register int c, n, o;
+ struct ar_hdr ar;
+ char aname[20];
+
+ if (!fgets(aname, sizeof aname, fd)) {
+ return 1;
+ }
+ if (strncmp(aname, ARMAG, SARMAG)) return 1;
+ (void)sprintf(aname, "%-16.16s", fname);
+ for (;;) {
+ if (fread((void *)&ar, sizeof ar, 1, fd)!=1) return 1;
+ if (strncmp(ar.ar_fmag, ARFMAG, 2)) return 1;
+ n=0;
+ p=ar.ar_size;
+ do {
+ if ((c=(int)(*p++-'0'))<0||c>9) break;
+ n*=10; n+=c;
+ } while (p<&ar.ar_size[sizeof ar.ar_size]);
+ if (!strncmp(ar.ar_name, aname, 16)) break;
+ if (fseek(fd, (long)n, SEEK_CUR)<0) return 1;
+ if ((n&1)&&fgetc(fd)!='\n') return 1;
+ }
+ if (cnt>=crt&&more()) return -1;
+ (void)fputc('\n', stdout);
+ cnt++;
+ o=0; while (o<n&&(c=fgetc(fd))!=EOF) {
+ per:
+ o++;
+ (void)fputc(c, stdout);
+ if (c!='\n') continue;
+ if (++cnt<crt) continue;
+ if (o>=n||(c=fgetc(fd))==EOF) break;
+ if (more()) return -1;
+ goto per;
+ }
+ if (cnt>=crt&&more()) return -1;
+ (void)fputc('\n', stdout);
+ cnt++;
+ if (!strcmp(fname, "help")) {
+ rewind(fd);
+ (void)fgets(aname, sizeof aname, fd);
+ if (cnt>=crt&&more()) return -1;
+ (void)fputs("The following help items are available:\n",
+ stdout);
+ cnt++;
+ o=0;
+ while (fread((void *)&ar, sizeof ar, 1, fd)==1) {
+ if (strncmp(ar.ar_fmag, ARFMAG, 2)) break;
+ if ((o%6)==0) {
+ (void)fputc('\n', stdout);
+ if (++cnt>=crt&&more()) return -1;
+ }
+ (void)printf("%.13s", ar.ar_name);
+ ++o;
+ n=0;
+ p=ar.ar_size;
+ do {
+ if ((c=(int)(*p++-'0'))<0||c>9) break;
+ n*=10; n+=c;
+ } while (p<&ar.ar_size[sizeof ar.ar_size]);
+ if (fseek(fd, (long)n, SEEK_CUR)<0) break;
+ if ((n&1)&&fgetc(fd)!='\n') break;
+ }
+ if (cnt>=crt&&more()) return -1;
+ (void)fputc('\n', stdout);
+ cnt++;
}
- exit(0);
+ return 0;
}