2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * Copyright 1987, 1988 by MIT Student Information Processing Board
11 * For copyright info, see copyright.h.
14 #include <sys/param.h>
15 #include <sys/types.h>
18 #include <fcntl.h> /* just for O_* */
20 #include "ss_internal.h"
21 #include "copyright.h"
24 extern void ss_list_requests();
26 void ss_help (argc
, argv
, sci_idx
, info_ptr
)
28 char const * const *argv
;
32 char buffer
[MAXPATHLEN
];
33 char const *request_name
;
37 register ss_data
*info
;
39 request_name
= ss_current_request(sci_idx
, &code
);
41 ss_perror(sci_idx
, code
, "");
42 return; /* no ss_abort_line, if invalid invocation */
45 ss_list_requests(argc
, argv
, sci_idx
, info_ptr
);
49 /* should do something better than this */
50 snprintf(buffer
, sizeof (buffer
), (char *)dgettext(TEXT_DOMAIN
,
51 "usage:\n\t%s [topic|command]\nor\t%s\n"),
52 request_name
, request_name
);
53 ss_perror(sci_idx
, 0, buffer
);
56 info
= ss_info(sci_idx
);
57 if (info
->info_dirs
== (char **)NULL
) {
58 ss_perror(sci_idx
, SS_ET_NO_INFO_DIR
, (char *)NULL
);
61 if (info
->info_dirs
[0] == (char *)NULL
) {
62 ss_perror(sci_idx
, SS_ET_NO_INFO_DIR
, (char *)NULL
);
65 for (idx
= 0; info
->info_dirs
[idx
] != (char *)NULL
; idx
++) {
66 (void) strncpy(buffer
, info
->info_dirs
[idx
], sizeof(buffer
) - 1);
67 buffer
[sizeof(buffer
) - 1] = '\0';
68 (void) strncat(buffer
, "/", sizeof(buffer
) - 1 - strlen(buffer
));
69 (void) strncat(buffer
, argv
[1], sizeof(buffer
) - 1 - strlen(buffer
));
70 (void) strncat(buffer
, ".info", sizeof(buffer
) - 1 - strlen(buffer
));
71 if ((fd
= open(&buffer
[0], O_RDONLY
)) >= 0) goto got_it
;
73 if ((fd
= open(&buffer
[0], O_RDONLY
)) < 0) {
75 strncpy(buf
, "No info found for ", sizeof(buf
) - 1);
76 buf
[sizeof(buf
) - 1] = '\0';
77 strncat(buf
, argv
[1], sizeof(buf
) - 1 - strlen(buf
));
78 ss_perror(sci_idx
, 0, buf
);
82 switch (child
= fork()) {
84 ss_perror(sci_idx
, errno
, "Can't fork for pager");
87 (void) dup2(fd
, 0); /* put file on stdin */
90 (void) close(fd
); /* what can we do if it fails? */
92 while (wait((int *)NULL
) != child
) {
94 while (wait((union wait
*)NULL
) != child
) {
96 /* do nothing if wrong pid */
107 void ss_add_info_dir(sci_idx
, info_dir
, code_ptr
)
112 register ss_data
*info
;
115 register char **dirs
;
117 info
= ss_info(sci_idx
);
118 if (info_dir
== NULL
&& *info_dir
) {
119 *code_ptr
= SS_ET_NO_INFO_DIR
;
122 if ((d
= opendir(info_dir
)) == (DIR *)NULL
) {
127 dirs
= info
->info_dirs
;
128 for (n_dirs
= 0; dirs
[n_dirs
] != (char *)NULL
; n_dirs
++)
129 ; /* get number of non-NULL dir entries */
130 dirs
= (char **)realloc((char *)dirs
,
131 (unsigned)(n_dirs
+ 2)*sizeof(char *));
132 if (dirs
== (char **)NULL
) {
133 info
->info_dirs
= (char **)NULL
;
137 info
->info_dirs
= dirs
;
138 dirs
[n_dirs
+ 1] = (char *)NULL
;
139 dirs
[n_dirs
] = malloc((unsigned)strlen(info_dir
)+1);
140 strcpy(dirs
[n_dirs
], info_dir
);
144 void ss_delete_info_dir(sci_idx
, info_dir
, code_ptr
)
150 register char **info_dirs
;
152 info_dirs
= ss_info(sci_idx
)->info_dirs
;
153 for (i_d
= info_dirs
; *i_d
; i_d
++) {
154 if (!strcmp(*i_d
, info_dir
)) {
163 *code_ptr
= SS_ET_NO_INFO_DIR
;