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 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     int mask;
39     sigret_t (*func)();
40 #ifndef WAIT_USES_INT
41     union wait waitb;
42 #else
43     int waitb;
44 #endif
45
46     DONT_USE(argc);
47     DONT_USE(argv);
48
49     mask = sigblock(sigmask(SIGINT));
50     func = signal(SIGINT, SIG_IGN);
51     fd = ss_pager_create();
52     output = fdopen(fd, "w");
53     sigsetmask(mask);
54
55     fprintf (output, "Available %s requests:\n\n",
56              ss_info (sci_idx) -> subsystem_name);
57
58     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
59         entry = (*table)->requests;
60         for (; entry->command_names; entry++) {
61             spacing = -2;
62             buffer[0] = '\0';
63             if (entry->flags & SS_OPT_DONT_LIST)
64                 continue;
65             for (name = entry->command_names; *name; name++) {
66                 register int len = strlen(*name);
67                 strncat(buffer, *name, len);
68                 spacing += len + 2;
69                 if (name[1]) {
70                     strcat(buffer, ", ");
71                 }
72             }
73             if (spacing > 23) {
74                 strcat(buffer, NL);
75                 fputs(buffer, output);
76                 spacing = 0;
77                 buffer[0] = '\0';
78             }
79             strncat(buffer, twentyfive_spaces, 25-spacing);
80             strcat(buffer, entry->info_string);
81             strcat(buffer, NL);
82             fputs(buffer, output);
83         }
84     }
85     fclose(output);
86 #ifndef NO_FORK
87     wait(&waitb);
88 #endif
89     (void) signal(SIGINT, func);
90 }