2 * Copyright 1987, 1988 by MIT Student Information Processing Board
4 * For copyright info, see copyright.h.
10 #ifdef NEED_SYS_FCNTL_H
12 #include <sys/fcntl.h>
15 #include "ss_internal.h"
16 #include "copyright.h"
20 void ss_help (argc, argv, sci_idx, info_ptr)
22 char const * const *argv;
26 char buffer[MAXPATHLEN];
27 char const *request_name;
31 register ss_data *info;
33 request_name = ss_current_request(sci_idx, &code);
35 ss_perror(sci_idx, code, "");
36 return; /* no ss_abort_line, if invalid invocation */
39 ss_list_requests(argc, argv, sci_idx, info_ptr);
43 /* should do something better than this */
44 sprintf(buffer, "usage:\n\t%s [topic|command]\nor\t%s\n",
45 request_name, request_name);
46 ss_perror(sci_idx, 0, buffer);
49 info = ss_info(sci_idx);
50 if (info->info_dirs == (char **)NULL) {
51 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
54 if (info->info_dirs[0] == (char *)NULL) {
55 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
58 for (idx = 0; info->info_dirs[idx] != (char *)NULL; idx++) {
59 (void) strcpy(buffer, info->info_dirs[idx]);
60 (void) strcat(buffer, "/");
61 (void) strcat(buffer, argv[1]);
62 (void) strcat(buffer, ".info");
63 if ((fd = open(&buffer[0], O_RDONLY)) >= 0) goto got_it;
65 if ((fd = open(&buffer[0], O_RDONLY)) < 0) {
67 strcpy(buf, "No info found for ");
69 ss_perror(sci_idx, 0, buf);
73 switch (child = fork()) {
75 ss_perror(sci_idx, errno, "Can't fork for pager");
78 (void) dup2(fd, 0); /* put file on stdin */
81 (void) close(fd); /* what can we do if it fails? */
82 while (wait((union wait *)NULL) != child) {
83 /* do nothing if wrong pid */
94 void ss_add_info_dir(sci_idx, info_dir, code_ptr)
99 register ss_data *info;
102 register char **dirs;
104 info = ss_info(sci_idx);
105 if (info_dir == NULL && *info_dir) {
106 *code_ptr = SS_ET_NO_INFO_DIR;
109 if ((d = opendir(info_dir)) == (DIR *)NULL) {
114 dirs = info->info_dirs;
115 for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
116 ; /* get number of non-NULL dir entries */
117 dirs = (char **)realloc((char *)dirs,
118 (unsigned)(n_dirs + 2)*sizeof(char *));
119 if (dirs == (char **)NULL) {
120 info->info_dirs = (char **)NULL;
124 info->info_dirs = dirs;
125 dirs[n_dirs + 1] = (char *)NULL;
126 dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
127 strcpy(dirs[n_dirs], info_dir);
131 void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
137 register char **info_dirs;
139 info_dirs = ss_info(sci_idx)->info_dirs;
140 for (i_d = info_dirs; *i_d; i_d++) {
141 if (!strcmp(*i_d, info_dir)) {
150 *code_ptr = SS_ET_NO_INFO_DIR;