2 * Copyright 1987, 1988 by MIT Student Information Processing Board
4 * For copyright info, see copyright.h.
14 #include <sys/param.h>
15 #include <sys/types.h>
17 #ifdef NEED_SYS_FCNTL_H
19 #include <sys/fcntl.h>
22 #include "ss_internal.h"
23 #include "copyright.h"
27 void ss_help (argc, argv, sci_idx, info_ptr)
29 char const * const *argv;
34 char const *request_name;
38 register ss_data *info;
40 request_name = ss_current_request(sci_idx, &code);
42 ss_perror(sci_idx, code, "");
43 return; /* no ss_abort_line, if invalid invocation */
46 ss_list_requests(argc, argv, sci_idx, info_ptr);
50 /* should do something better than this */
51 buffer = malloc(80+2*strlen(request_name));
54 "couldn't allocate memory to print usage message");
57 sprintf(buffer, "usage:\n\t%s [topic|command]\nor\t%s\n",
58 request_name, request_name);
59 ss_perror(sci_idx, 0, buffer);
63 info = ss_info(sci_idx);
64 if (info->info_dirs == (char **)NULL) {
65 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
68 if (info->info_dirs[0] == (char *)NULL) {
69 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
72 for (fd = -1, idx = 0; info->info_dirs[idx] != (char *)NULL; idx++) {
73 buffer = malloc(strlen (info->info_dirs[idx]) + 1 +
74 strlen (argv[1]) + 6);
77 "couldn't allocate memory for help filename");
80 (void) strcpy(buffer, info->info_dirs[idx]);
81 (void) strcat(buffer, "/");
82 (void) strcat(buffer, argv[1]);
83 (void) strcat(buffer, ".info");
84 fd = open(buffer, O_RDONLY);
90 #define MSG "No info found for "
91 char *buf = malloc(strlen (MSG) + strlen (argv[1]) + 1);
94 ss_perror(sci_idx, 0, buf);
98 switch (child = fork()) {
100 ss_perror(sci_idx, errno, "Can't fork for pager");
103 (void) dup2(fd, 0); /* put file on stdin */
106 (void) close(fd); /* what can we do if it fails? */
107 while (wait(0) != child) {
108 /* do nothing if wrong pid */
113 #ifndef HAVE_DIRENT_H
119 void ss_add_info_dir(sci_idx, info_dir, code_ptr)
124 register ss_data *info;
127 register char **dirs;
129 info = ss_info(sci_idx);
130 if (info_dir == NULL && *info_dir) {
131 *code_ptr = SS_ET_NO_INFO_DIR;
134 if ((d = opendir(info_dir)) == (DIR *)NULL) {
139 dirs = info->info_dirs;
140 for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
141 ; /* get number of non-NULL dir entries */
142 dirs = (char **)realloc((char *)dirs,
143 (unsigned)(n_dirs + 2)*sizeof(char *));
144 if (dirs == (char **)NULL) {
145 info->info_dirs = (char **)NULL;
149 info->info_dirs = dirs;
150 dirs[n_dirs + 1] = (char *)NULL;
151 dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
152 strcpy(dirs[n_dirs], info_dir);
156 void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
162 register char **info_dirs;
164 info_dirs = ss_info(sci_idx)->info_dirs;
165 for (i_d = info_dirs; *i_d; i_d++) {
166 if (!strcmp(*i_d, info_dir)) {
175 *code_ptr = SS_ET_NO_INFO_DIR;