2 * Copyright 1987, 1988 by MIT Student Information Processing Board
4 * This file may be copied under the terms of the GNU Public License.
19 #include <sys/param.h>
20 #include <sys/types.h>
22 #ifdef NEED_SYS_FCNTL_H
24 #include <sys/fcntl.h>
27 #include "ss_internal.h"
29 void ss_help (argc, argv, sci_idx, info_ptr)
31 char const * const *argv;
36 char const *request_name;
40 register ss_data *info;
42 request_name = ss_current_request(sci_idx, &code);
44 ss_perror(sci_idx, code, "");
45 return; /* no ss_abort_line, if invalid invocation */
48 ss_list_requests(argc, argv, sci_idx, info_ptr);
52 /* should do something better than this */
53 buffer = malloc(80+2*strlen(request_name));
56 "couldn't allocate memory to print usage message");
59 sprintf(buffer, "usage:\n\t%s [topic|command]\nor\t%s\n",
60 request_name, request_name);
61 ss_perror(sci_idx, 0, buffer);
65 info = ss_info(sci_idx);
66 if (info->info_dirs == (char **)NULL) {
67 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
70 if (info->info_dirs[0] == (char *)NULL) {
71 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
74 for (fd = -1, idx = 0; info->info_dirs[idx] != (char *)NULL; idx++) {
75 buffer = malloc(strlen (info->info_dirs[idx]) + 1 +
76 strlen (argv[1]) + 6);
79 "couldn't allocate memory for help filename");
82 (void) strcpy(buffer, info->info_dirs[idx]);
83 (void) strcat(buffer, "/");
84 (void) strcat(buffer, argv[1]);
85 (void) strcat(buffer, ".info");
86 fd = open(buffer, O_RDONLY);
92 #define MSG "No info found for "
93 char *buf = malloc(strlen (MSG) + strlen (argv[1]) + 1);
96 ss_perror(sci_idx, 0, buf);
100 switch (child = fork()) {
102 ss_perror(sci_idx, errno, "Can't fork for pager");
105 (void) dup2(fd, 0); /* put file on stdin */
108 (void) close(fd); /* what can we do if it fails? */
109 while (wait(0) != child) {
110 /* do nothing if wrong pid */
115 #ifndef HAVE_DIRENT_H
121 void ss_add_info_dir(sci_idx, info_dir, code_ptr)
126 register ss_data *info;
129 register char **dirs;
131 info = ss_info(sci_idx);
132 if (info_dir == NULL && *info_dir) {
133 *code_ptr = SS_ET_NO_INFO_DIR;
136 if ((d = opendir(info_dir)) == (DIR *)NULL) {
141 dirs = info->info_dirs;
142 for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
143 ; /* get number of non-NULL dir entries */
144 dirs = (char **)realloc((char *)dirs,
145 (unsigned)(n_dirs + 2)*sizeof(char *));
146 if (dirs == (char **)NULL) {
147 info->info_dirs = (char **)NULL;
151 info->info_dirs = dirs;
152 dirs[n_dirs + 1] = (char *)NULL;
153 dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
154 strcpy(dirs[n_dirs], info_dir);
158 void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
164 register char **info_dirs;
166 info_dirs = ss_info(sci_idx)->info_dirs;
167 for (i_d = info_dirs; *i_d; i_d++) {
168 if (!strcmp(*i_d, info_dir)) {
177 *code_ptr = SS_ET_NO_INFO_DIR;