• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1987, 1988 by MIT Student Information Processing Board
3  *
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.
12  */
13 #include "ss_internal.h"
14 #include <signal.h>
15 #include <setjmp.h>
16 #include <sys/wait.h>
17 
18 typedef void sigret_t;
19 
20 static char const twentyfive_spaces[26] =
21     "                         ";
22 static char const NL[2] = "\n";
23 
ss_list_requests(int argc __SS_ATTR ((unused)),const char * const * argv __SS_ATTR ((unused)),int sci_idx,void * infop __SS_ATTR ((unused)))24 void ss_list_requests(int argc __SS_ATTR((unused)),
25 		      const char * const *argv __SS_ATTR((unused)),
26 		      int sci_idx, void *infop __SS_ATTR((unused)))
27 {
28     ss_request_entry *entry;
29     char const * const *name;
30     int spacing;
31     ss_request_table **table;
32 
33     char buffer[BUFSIZ];
34     FILE *output;
35     int fd;
36     sigset_t omask, igmask;
37     sigret_t (*func)(int);
38 #ifndef NO_FORK
39     int waitb;
40 #endif
41 
42     sigemptyset(&igmask);
43     sigaddset(&igmask, SIGINT);
44     sigprocmask(SIG_BLOCK, &igmask, &omask);
45     func = signal(SIGINT, SIG_IGN);
46     fd = ss_pager_create();
47     output = fdopen(fd, "w");
48     sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
49 
50     fprintf (output, "Available %s requests:\n\n",
51 	     ss_info (sci_idx) -> subsystem_name);
52 
53     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
54         entry = (*table)->requests;
55         for (; entry->command_names; entry++) {
56             spacing = -2;
57             buffer[0] = '\0';
58             if (entry->flags & SS_OPT_DONT_LIST)
59                 continue;
60             for (name = entry->command_names; *name; name++) {
61                 int len = strlen(*name);
62                 strncat(buffer, *name, len);
63                 spacing += len + 2;
64                 if (name[1]) {
65                     strcat(buffer, ", ");
66                 }
67             }
68             if (spacing > 23) {
69                 strcat(buffer, NL);
70                 fputs(buffer, output);
71                 spacing = 0;
72                 buffer[0] = '\0';
73             }
74             strncat(buffer, twentyfive_spaces, 25-spacing);
75             strcat(buffer, entry->info_string);
76             strcat(buffer, NL);
77             fputs(buffer, output);
78         }
79     }
80     fclose(output);
81 #ifndef NO_FORK
82     wait(&waitb);
83 #endif
84     (void) signal(SIGINT, func);
85 }
86