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