2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright 1987, 1988 by MIT Student Information Processing Board
9 * For copyright info, see copyright.h.
12 #include <sys/param.h>
13 #include <sys/types.h>
16 #include <fcntl.h> /* just for O_* */
18 #include "ss_internal.h"
19 #include "copyright.h"
22 extern void ss_list_requests();
24 void ss_help (argc
, argv
, sci_idx
, info_ptr
)
26 char const * const *argv
;
30 char buffer
[MAXPATHLEN
];
31 char const *request_name
;
35 register ss_data
*info
;
37 request_name
= ss_current_request(sci_idx
, &code
);
39 ss_perror(sci_idx
, code
, "");
40 return; /* no ss_abort_line, if invalid invocation */
43 ss_list_requests(argc
, argv
, sci_idx
, info_ptr
);
47 /* should do something better than this */
48 snprintf(buffer
, sizeof (buffer
), (char *)dgettext(TEXT_DOMAIN
,
49 "usage:\n\t%s [topic|command]\nor\t%s\n"),
50 request_name
, request_name
);
51 ss_perror(sci_idx
, 0, buffer
);
54 info
= ss_info(sci_idx
);
55 if (info
->info_dirs
== (char **)NULL
) {
56 ss_perror(sci_idx
, SS_ET_NO_INFO_DIR
, (char *)NULL
);
59 if (info
->info_dirs
[0] == (char *)NULL
) {
60 ss_perror(sci_idx
, SS_ET_NO_INFO_DIR
, (char *)NULL
);
63 for (idx
= 0; info
->info_dirs
[idx
] != (char *)NULL
; idx
++) {
64 (void) strncpy(buffer
, info
->info_dirs
[idx
], sizeof(buffer
) - 1);
65 buffer
[sizeof(buffer
) - 1] = '\0';
66 (void) strncat(buffer
, "/", sizeof(buffer
) - 1 - strlen(buffer
));
67 (void) strncat(buffer
, argv
[1], sizeof(buffer
) - 1 - strlen(buffer
));
68 (void) strncat(buffer
, ".info", sizeof(buffer
) - 1 - strlen(buffer
));
69 if ((fd
= open(&buffer
[0], O_RDONLY
)) >= 0) goto got_it
;
71 if ((fd
= open(&buffer
[0], O_RDONLY
)) < 0) {
73 strncpy(buf
, "No info found for ", sizeof(buf
) - 1);
74 buf
[sizeof(buf
) - 1] = '\0';
75 strncat(buf
, argv
[1], sizeof(buf
) - 1 - strlen(buf
));
76 ss_perror(sci_idx
, 0, buf
);
80 switch (child
= fork()) {
82 ss_perror(sci_idx
, errno
, "Can't fork for pager");
85 (void) dup2(fd
, 0); /* put file on stdin */
88 (void) close(fd
); /* what can we do if it fails? */
90 while (wait((int *)NULL
) != child
) {
92 while (wait((union wait
*)NULL
) != child
) {
94 /* do nothing if wrong pid */
105 void ss_add_info_dir(sci_idx
, info_dir
, code_ptr
)
110 register ss_data
*info
;
113 register char **dirs
;
115 info
= ss_info(sci_idx
);
116 if (info_dir
== NULL
&& *info_dir
) {
117 *code_ptr
= SS_ET_NO_INFO_DIR
;
120 if ((d
= opendir(info_dir
)) == (DIR *)NULL
) {
125 dirs
= info
->info_dirs
;
126 for (n_dirs
= 0; dirs
[n_dirs
] != (char *)NULL
; n_dirs
++)
127 ; /* get number of non-NULL dir entries */
128 dirs
= (char **)realloc((char *)dirs
,
129 (unsigned)(n_dirs
+ 2)*sizeof(char *));
130 if (dirs
== (char **)NULL
) {
131 info
->info_dirs
= (char **)NULL
;
135 info
->info_dirs
= dirs
;
136 dirs
[n_dirs
+ 1] = (char *)NULL
;
137 dirs
[n_dirs
] = malloc((unsigned)strlen(info_dir
)+1);
138 strcpy(dirs
[n_dirs
], info_dir
);
142 void ss_delete_info_dir(sci_idx
, info_dir
, code_ptr
)
148 register char **info_dirs
;
150 info_dirs
= ss_info(sci_idx
)->info_dirs
;
151 for (i_d
= info_dirs
; *i_d
; i_d
++) {
152 if (!strcmp(*i_d
, info_dir
)) {
161 *code_ptr
= SS_ET_NO_INFO_DIR
;