Whamcloud - gitweb
Align function prototypes for libss's request handler function
[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 "config.h"
14 #include "ss_internal.h"
15 #ifdef HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #include <signal.h>
19 #include <setjmp.h>
20 #include <sys/wait.h>
21
22 typedef void sigret_t;
23
24 void ss_list_requests(int argc __SS_ATTR((unused)),
25                       ss_argv_t 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 i, spacing;
31     ss_request_table **table;
32
33     FILE *output;
34     int fd;
35     sigset_t omask, igmask;
36     sigret_t (*func)(int);
37 #ifndef NO_FORK
38     int waitb;
39 #endif
40
41     sigemptyset(&igmask);
42     sigaddset(&igmask, SIGINT);
43     sigprocmask(SIG_BLOCK, &igmask, &omask);
44     func = signal(SIGINT, SIG_IGN);
45     fd = ss_pager_create();
46     if (fd < 0) {
47         perror("ss_pager_create");
48         (void) signal(SIGINT, func);
49         return;
50     }
51     output = fdopen(fd, "w");
52     if (!output) {
53         perror("fdopen");
54         close(fd);
55         (void) signal(SIGINT, func);
56         return;
57     }
58     sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
59
60     fprintf (output, "Available %s requests:\n\n",
61              ss_info (sci_idx) -> subsystem_name);
62
63     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
64         entry = (*table)->requests;
65         for (; entry->command_names; entry++) {
66             spacing = -2;
67             if (entry->flags & SS_OPT_DONT_LIST)
68                 continue;
69             for (name = entry->command_names; *name; name++) {
70                 int len = strlen(*name);
71                 fputs(*name, output);
72                 spacing += len + 2;
73                 if (name[1]) {
74                     fputs(", ", output);
75                 }
76             }
77             if (spacing > 23) {
78                 fputc('\n', output);
79                 spacing = 0;
80             }
81             for (i = 0; i < 25 - spacing; i++)
82                 fputc(' ', output);
83             fputs(entry->info_string, output);
84             fputc('\n', output);
85         }
86     }
87     fclose(output);
88 #ifndef NO_FORK
89     wait(&waitb);
90 #endif
91     (void) signal(SIGINT, func);
92 }