]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/picobsd/tinyware/help/help.c
This commit was generated by cvs2svn to compensate for changes in r38776,
[FreeBSD/FreeBSD.git] / release / picobsd / tinyware / help / help.c
1 /*-
2  * Copyright (c) 1998 Andrzej Bialecki
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $Id: help.c,v 1.1.1.1 1998/07/14 07:30:53 abial Exp $
27  *
28  */
29
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <dirent.h>
35
36 void
37 display(char *fname)
38 {
39         FILE *fd;
40         DIR *dirp;
41         struct dirent *d;
42         char buf[100],junk[5],c, *dot;
43         int i;
44
45         snprintf(buf,99,"/help/%s.hlp",fname);
46         if((fd=fopen(buf,"r"))==NULL) {
47                 printf("No help available for '%s'.\n",fname);
48                 exit(1);
49         }
50         printf("\n");
51         i=0;
52         while(!feof(fd)) {
53                 if(fgets(buf,99,fd)==NULL) continue;
54                 if(i<23) {
55                         printf("%s",buf);
56                         i++;
57                 } else {
58                         printf("\e[7mPress Enter to continue\e[m");
59                         fgets(junk,5,stdin);
60                         printf("%s",buf);
61                         i=0;
62                 }
63         }
64         printf("\n");
65         i=0;
66         if(strcmp(fname,"help")==0) {
67                 printf("The following help items are available:\n\n");
68                 dirp=opendir("/help/.");
69                 while((d=readdir(dirp))!=NULL) {
70                         if(d->d_name[0]=='.') continue;
71                         if((dot=strchr(d->d_name,'.'))!=NULL) {
72                                 *dot='\0';
73                         }
74                         printf("%-13s",d->d_name);
75                         i++;
76                         if(i>5) {
77                                 printf("\n");
78                                 i=0;
79                         }
80                 }
81                 closedir(dirp);
82                 printf("\n");
83         }
84         return;
85 }
86
87
88 int
89 main(int argc, char *argv[])
90 {
91         if(argc==1) {
92                 display("help");
93         } else {
94                 display(argv[1]);
95         }
96         exit(0);
97 }