1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 1987, 1988 by MIT Student Information Processing Board
4 *
5 * For copyright information, see copyright.h.
6 */
7 #include "copyright.h"
8 #include "ss_internal.h"
9 #include <signal.h>
10 #include <setjmp.h>
11 #include <sys/wait.h>
12
13 #ifdef lint /* "lint returns a value which is sometimes ignored" */
14 #define DONT_USE(x) x=x;
15 #else /* !lint */
16 #define DONT_USE(x) ;
17 #endif /* lint */
18
19 static char const twentyfive_spaces[26] =
20 " ";
21 static char const NL[2] = "\n";
22
23 void
ss_list_requests(int argc,const char * const * argv,int sci_idx,void * info_ptr)24 ss_list_requests(int argc, const char * const *argv, int sci_idx,
25 void *info_ptr)
26 {
27 ss_request_entry *entry;
28 char const *const *name;
29 int spacing;
30 ss_request_table **table;
31
32 char buffer[BUFSIZ];
33 FILE *output;
34 int fd;
35 #ifdef POSIX_SIGNALS
36 struct sigaction nsig, osig;
37 sigset_t nmask, omask;
38 #else
39 int mask;
40 void (*func)();
41 #endif
42 #ifndef WAIT_USES_INT
43 union wait waitb;
44 #else
45 int waitb;
46 #endif
47
48 DONT_USE(argc);
49 DONT_USE(argv);
50
51 #ifdef POSIX_SIGNALS
52 sigemptyset(&nmask);
53 sigaddset(&nmask, SIGINT);
54 sigprocmask(SIG_BLOCK, &nmask, &omask);
55
56 nsig.sa_handler = SIG_IGN;
57 sigemptyset(&nsig.sa_mask);
58 nsig.sa_flags = 0;
59 sigaction(SIGINT, &nsig, &osig);
60 #else
61 mask = sigblock(sigmask(SIGINT));
62 func = signal(SIGINT, SIG_IGN);
63 #endif
64
65 fd = ss_pager_create(); /* FD_CLOEXEC set */
66 output = fdopen(fd, "w");
67
68 #ifdef POSIX_SIGNALS
69 sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
70 #else
71 sigsetmask(mask);
72 #endif
73
74 fprintf (output, "Available %s requests:\n\n",
75 ss_info (sci_idx) -> subsystem_name);
76
77 for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
78 entry = (*table)->requests;
79 for (; entry->command_names; entry++) {
80 spacing = -2;
81 buffer[0] = '\0';
82 if (entry->flags & SS_OPT_DONT_LIST)
83 continue;
84 buffer[sizeof(buffer) - 1] = '\0';
85 for (name = entry->command_names; *name; name++) {
86 int len = strlen(*name);
87 strncat(buffer, *name, sizeof(buffer) - 1 - strlen(buffer));
88 spacing += len + 2;
89 if (name[1]) {
90 strncat(buffer, ", ", sizeof(buffer) - 1 - strlen(buffer));
91 }
92 }
93 if (spacing > 23) {
94 strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));
95 fputs(buffer, output);
96 spacing = 0;
97 buffer[0] = '\0';
98 }
99 strncat(buffer, twentyfive_spaces, sizeof(buffer) - 1 - (25-spacing));
100 strncpy(buffer + 25, entry->info_string, sizeof(buffer) - 1 - 25);
101 strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));
102 fputs(buffer, output);
103 }
104 }
105 fclose(output);
106 #ifndef NO_FORK
107 wait(&waitb);
108 #endif
109 #ifdef POSIX_SIGNALS
110 sigaction(SIGINT, &osig, (struct sigaction *)0);
111 #else
112 (void) signal(SIGINT, func);
113 #endif
114 }
115