2 * Copyright 1987, 1988 by MIT Student Information Processing Board
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose is hereby granted, provided that
6 * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7 * advertising or publicity pertaining to distribution of the software
8 * without specific, written prior permission. M.I.T. and the
9 * M.I.T. S.I.P.B. make no representations about the suitability of
10 * this software for any purpose. It is provided "as is" without
11 * express or implied warranty.
26 #include <sys/param.h>
27 #include <sys/types.h>
29 #ifdef NEED_SYS_FCNTL_H
31 #include <sys/fcntl.h>
34 #include "ss_internal.h"
36 void ss_help (argc, argv, sci_idx, info_ptr)
38 char const * const *argv;
43 char const *request_name;
47 register ss_data *info;
49 request_name = ss_current_request(sci_idx, &code);
51 ss_perror(sci_idx, code, "");
52 return; /* no ss_abort_line, if invalid invocation */
55 ss_list_requests(argc, argv, sci_idx, info_ptr);
59 /* should do something better than this */
60 buffer = malloc(80+2*strlen(request_name));
63 "couldn't allocate memory to print usage message");
66 sprintf(buffer, "usage:\n\t%s [topic|command]\nor\t%s\n",
67 request_name, request_name);
68 ss_perror(sci_idx, 0, buffer);
72 info = ss_info(sci_idx);
73 if (info->info_dirs == (char **)NULL) {
74 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
77 if (info->info_dirs[0] == (char *)NULL) {
78 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
81 for (fd = -1, idx = 0; info->info_dirs[idx] != (char *)NULL; idx++) {
82 buffer = malloc(strlen (info->info_dirs[idx]) + 1 +
83 strlen (argv[1]) + 6);
86 "couldn't allocate memory for help filename");
89 (void) strcpy(buffer, info->info_dirs[idx]);
90 (void) strcat(buffer, "/");
91 (void) strcat(buffer, argv[1]);
92 (void) strcat(buffer, ".info");
93 fd = open(buffer, O_RDONLY);
99 #define MSG "No info found for "
100 char *buf = malloc(strlen (MSG) + strlen (argv[1]) + 1);
102 strcat(buf, argv[1]);
103 ss_perror(sci_idx, 0, buf);
107 switch (child = fork()) {
109 ss_perror(sci_idx, errno, "Can't fork for pager");
112 (void) dup2(fd, 0); /* put file on stdin */
115 (void) close(fd); /* what can we do if it fails? */
116 while (wait(0) != child) {
117 /* do nothing if wrong pid */
122 #ifndef HAVE_DIRENT_H
128 void ss_add_info_dir(sci_idx, info_dir, code_ptr)
133 register ss_data *info;
136 register char **dirs;
138 info = ss_info(sci_idx);
139 if (info_dir == NULL && *info_dir) {
140 *code_ptr = SS_ET_NO_INFO_DIR;
143 if ((d = opendir(info_dir)) == (DIR *)NULL) {
148 dirs = info->info_dirs;
149 for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
150 ; /* get number of non-NULL dir entries */
151 dirs = (char **)realloc((char *)dirs,
152 (unsigned)(n_dirs + 2)*sizeof(char *));
153 if (dirs == (char **)NULL) {
154 info->info_dirs = (char **)NULL;
158 info->info_dirs = dirs;
159 dirs[n_dirs + 1] = (char *)NULL;
160 dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
161 strcpy(dirs[n_dirs], info_dir);
165 void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
171 register char **info_dirs;
173 info_dirs = ss_info(sci_idx)->info_dirs;
174 for (i_d = info_dirs; *i_d; i_d++) {
175 if (!strcmp(*i_d, info_dir)) {
184 *code_ptr = SS_ET_NO_INFO_DIR;