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