]>
Commit | Line | Data |
---|---|---|
3839e657 TT |
1 | /* |
2 | * Copyright 1987, 1988 by MIT Student Information Processing Board | |
3 | * | |
06cefee5 TT |
4 | * Permission to use, copy, modify, and distribute this software and |
5 | * its documentation for any purpose is hereby granted, provided that | |
6 | * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in | |
7 | * advertising or publicity pertaining to distribution of the software | |
8 | * without specific, written prior permission. M.I.T. and the | |
9 | * M.I.T. S.I.P.B. make no representations about the suitability of | |
10 | * this software for any purpose. It is provided "as is" without | |
11 | * express or implied warranty. | |
3839e657 | 12 | */ |
d1154eb4 | 13 | #include "config.h" |
3839e657 TT |
14 | #include "ss_internal.h" |
15 | #include <signal.h> | |
16 | #include <setjmp.h> | |
17 | #include <sys/wait.h> | |
18 | ||
19 | typedef void sigret_t; | |
20 | ||
3839e657 TT |
21 | static char const twentyfive_spaces[26] = |
22 | " "; | |
23 | static char const NL[2] = "\n"; | |
24 | ||
54434927 TT |
25 | void ss_list_requests(int argc __SS_ATTR((unused)), |
26 | const char * const *argv __SS_ATTR((unused)), | |
27 | int sci_idx, void *infop __SS_ATTR((unused))) | |
3839e657 | 28 | { |
54434927 TT |
29 | ss_request_entry *entry; |
30 | char const * const *name; | |
31 | int spacing; | |
32 | ss_request_table **table; | |
3839e657 TT |
33 | |
34 | char buffer[BUFSIZ]; | |
35 | FILE *output; | |
36 | int fd; | |
f3db3566 | 37 | sigset_t omask, igmask; |
91835c15 | 38 | sigret_t (*func)(int); |
f3db3566 | 39 | #ifndef NO_FORK |
3839e657 TT |
40 | int waitb; |
41 | #endif | |
42 | ||
f3db3566 TT |
43 | sigemptyset(&igmask); |
44 | sigaddset(&igmask, SIGINT); | |
45 | sigprocmask(SIG_BLOCK, &igmask, &omask); | |
3839e657 TT |
46 | func = signal(SIGINT, SIG_IGN); |
47 | fd = ss_pager_create(); | |
48 | output = fdopen(fd, "w"); | |
f3db3566 | 49 | sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); |
3839e657 TT |
50 | |
51 | fprintf (output, "Available %s requests:\n\n", | |
52 | ss_info (sci_idx) -> subsystem_name); | |
53 | ||
54 | for (table = ss_info(sci_idx)->rqt_tables; *table; table++) { | |
55 | entry = (*table)->requests; | |
56 | for (; entry->command_names; entry++) { | |
57 | spacing = -2; | |
58 | buffer[0] = '\0'; | |
59 | if (entry->flags & SS_OPT_DONT_LIST) | |
60 | continue; | |
61 | for (name = entry->command_names; *name; name++) { | |
54434927 | 62 | int len = strlen(*name); |
3839e657 TT |
63 | strncat(buffer, *name, len); |
64 | spacing += len + 2; | |
65 | if (name[1]) { | |
66 | strcat(buffer, ", "); | |
67 | } | |
68 | } | |
69 | if (spacing > 23) { | |
70 | strcat(buffer, NL); | |
71 | fputs(buffer, output); | |
72 | spacing = 0; | |
73 | buffer[0] = '\0'; | |
74 | } | |
75 | strncat(buffer, twentyfive_spaces, 25-spacing); | |
76 | strcat(buffer, entry->info_string); | |
77 | strcat(buffer, NL); | |
78 | fputs(buffer, output); | |
79 | } | |
80 | } | |
81 | fclose(output); | |
82 | #ifndef NO_FORK | |
83 | wait(&waitb); | |
84 | #endif | |
85 | (void) signal(SIGINT, func); | |
86 | } |