]> git.sur5r.net Git - openldap/blob - contrib/whois++/help.c
d18f4b05b3a616f15dacf2f15282f64a0cb4d5b5
[openldap] / contrib / whois++ / help.c
1 #if !defined(lint)
2 static char copyright[] = "Copyright 1992 The University of Adelaide";
3 #endif
4
5 /*
6  *                      H E L P
7  *
8  * Author:      Mark R. Prior
9  *              Communications and Systems Branch
10  *              Information Technology Division
11  *              The University of Adelaide
12  * E-mail:      mrp@itd.adelaide.edu.au
13  * Date:        October 1992
14  * Version:     1.7
15  * Description:
16  *              The Help module
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that the above copyright notice and this paragraph are
20  * duplicated in all such forms and that any documentation,
21  * advertising materials, and other materials related to such
22  * distribution and use acknowledge that the software was developed
23  * by the University of Adelaide. The name of the University may not
24  * be used to endorse or promote products derived from this software
25  * without specific prior written permission.
26  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
27  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
28  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  */
30
31 #include "whois++.h"
32
33 void    needHelp( reason )
34 char    *reason;
35 {
36         char            filename[MAXPATHLEN];
37         char            buffer[BUFSIZ];
38         int             i;
39         DIR             *dir;
40         struct dirent   *entry;
41         FILE            *help;
42
43         if ( reason == NULL || *reason == '\0' ) {
44                 sprintf( filename, "%s/%s/general", helpDir, language );
45                 if ( ( help = fopen( filename, "r" ) ) == NULL ) {
46                         printFormatted( lineLength, TRUE, stdout,
47                                 "Sorry cannot open general information help file" );
48                         return;
49                 }
50         } else {
51                 sprintf( filename, "%s/%s/%s", helpDir, language,
52                         lowerCase( reason ) );
53                 if ( ( help = fopen( filename, "r" ) ) == NULL ) {
54                         sprintf( filename, "%s/%s/%s", helpDir, defaultLanguage,
55                                 lowerCase( reason ) );
56                         if ( ( help = fopen( filename, "r" ) ) == NULL ) {
57                                 printFormatted( lineLength, TRUE, stdout,
58                                         "Sorry cannot open help file for topic \"%s\"",
59                                         reason );
60                                 return;
61                         } else {
62                                 printFormatted( lineLength, TRUE, stdout,
63                                         "Sorry no help in %s, using default language (%s).",
64                                         language, defaultLanguage );
65                         }
66                 }
67         }
68         while ( fgets( buffer, BUFSIZ, help ) != NULL ) {
69                 i = strlen( buffer );
70                 while ( i-- > 0 && ( buffer[i] == '\n' || buffer[i] == '\r' ) )
71                         buffer[i] = '\0';
72                 printFormatted( lineLength, FALSE, stdout, "%s", buffer );
73         }
74         fclose( help );
75         if ( reason == NULL || *reason == '\0' ) {
76                 sprintf( filename, "%s/%s", helpDir, language );
77                 if ( ( dir = opendir( filename ) ) == NULL )
78                         return;
79                 printFormatted( lineLength, FALSE, stdout, "" );
80                 printFormatted( lineLength, FALSE, stdout,
81                         "Further information is available on the following topics" );
82                 for ( entry = readdir( dir ); entry != NULL; entry = readdir( dir ) )
83                         if ( !EQ(entry->d_name, "." ) && !EQ(entry->d_name, ".." ) )
84                                 printFormatted( lineLength, FALSE, stdout,
85                                         " %s", lowerCase( entry->d_name ) );
86                 closedir( dir );
87         }
88         return;
89 }