2 * Copyright 1987, 1988 by MIT Student Information Processing Board
4 * For copyright info, see copyright.h.
10 #include <fcntl.h> /* just for O_* */
12 #include "ss_internal.h"
13 #include "copyright.h"
17 void ss_help (argc, argv, sci_idx, info_ptr)
19 char const * const *argv;
23 char buffer[MAXPATHLEN];
24 char const *request_name;
28 register ss_data *info;
30 request_name = ss_current_request(sci_idx, &code);
32 ss_perror(sci_idx, code, "");
33 return; /* no ss_abort_line, if invalid invocation */
36 ss_list_requests(argc, argv, sci_idx, info_ptr);
40 /* should do something better than this */
41 sprintf(buffer, "usage:\n\t%s [topic|command]\nor\t%s\n",
42 request_name, request_name);
43 ss_perror(sci_idx, 0, buffer);
46 info = ss_info(sci_idx);
47 if (info->info_dirs == (char **)NULL) {
48 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
51 if (info->info_dirs[0] == (char *)NULL) {
52 ss_perror(sci_idx, SS_ET_NO_INFO_DIR, (char *)NULL);
55 for (idx = 0; info->info_dirs[idx] != (char *)NULL; idx++) {
56 (void) strncpy(buffer, info->info_dirs[idx], sizeof(buffer) - 1);
57 buffer[sizeof(buffer) - 1] = '\0';
58 (void) strncat(buffer, "/", sizeof(buffer) - 1 - strlen(buffer));
59 (void) strncat(buffer, argv[1], sizeof(buffer) - 1 - strlen(buffer));
60 (void) strncat(buffer, ".info", sizeof(buffer) - 1 - strlen(buffer));
61 if ((fd = open(&buffer[0], O_RDONLY)) >= 0) goto got_it;
63 if ((fd = open(&buffer[0], O_RDONLY)) < 0) {
65 strncpy(buf, "No info found for ", sizeof(buf) - 1);
66 buf[sizeof(buf) - 1] = '\0';
67 strncat(buf, argv[1], sizeof(buf) - 1 - strlen(buf));
68 ss_perror(sci_idx, 0, buf);
72 switch (child = fork()) {
74 ss_perror(sci_idx, errno, "Can't fork for pager");
77 (void) dup2(fd, 0); /* put file on stdin */
80 (void) close(fd); /* what can we do if it fails? */
82 while (wait((int *)NULL) != child) {
84 while (wait((union wait *)NULL) != child) {
86 /* do nothing if wrong pid */
97 void ss_add_info_dir(sci_idx, info_dir, code_ptr)
102 register ss_data *info;
105 register char **dirs;
107 info = ss_info(sci_idx);
108 if (info_dir == NULL && *info_dir) {
109 *code_ptr = SS_ET_NO_INFO_DIR;
112 if ((d = opendir(info_dir)) == (DIR *)NULL) {
117 dirs = info->info_dirs;
118 for (n_dirs = 0; dirs[n_dirs] != (char *)NULL; n_dirs++)
119 ; /* get number of non-NULL dir entries */
120 dirs = (char **)realloc((char *)dirs,
121 (unsigned)(n_dirs + 2)*sizeof(char *));
122 if (dirs == (char **)NULL) {
123 info->info_dirs = (char **)NULL;
127 info->info_dirs = dirs;
128 dirs[n_dirs + 1] = (char *)NULL;
129 dirs[n_dirs] = malloc((unsigned)strlen(info_dir)+1);
130 strcpy(dirs[n_dirs], info_dir);
134 void ss_delete_info_dir(sci_idx, info_dir, code_ptr)
140 register char **info_dirs;
142 info_dirs = ss_info(sci_idx)->info_dirs;
143 for (i_d = info_dirs; *i_d; i_d++) {
144 if (!strcmp(*i_d, info_dir)) {
153 *code_ptr = SS_ET_NO_INFO_DIR;