From 6c88a1f638ea30adbeecdffc40a099b3d7b9f99f Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Mon, 7 Sep 1998 19:00:34 +0000 Subject: Change the way the help files are stored, and save ca. 30kB on the "dial" floppy. Submitted by: Eric P. Scott --- release/picobsd/tinyware/help/help.c | 163 ++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 52 deletions(-) (limited to 'release/picobsd/tinyware/help/help.c') 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 + * Copyright (c) 1998 Andrzej Bialecki * 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 #include -#include -#include +#include +#include + +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;i9) 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) 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; } -- cgit v1.2.3