Whamcloud - gitweb
tune2fs: fix BUGs of tuning project quota
[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 #include <signal.h>
16 #include <setjmp.h>
17 #include <sys/wait.h>
18
19 typedef void sigret_t;
20
21 void ss_list_requests(int argc __SS_ATTR((unused)),
22                       const char * const *argv __SS_ATTR((unused)),
23                       int sci_idx, void *infop __SS_ATTR((unused)))
24 {
25     ss_request_entry *entry;
26     char const * const *name;
27     int i, spacing;
28     ss_request_table **table;
29
30     FILE *output;
31     int fd;
32     sigset_t omask, igmask;
33     sigret_t (*func)(int);
34 #ifndef NO_FORK
35     int waitb;
36 #endif
37
38     sigemptyset(&igmask);
39     sigaddset(&igmask, SIGINT);
40     sigprocmask(SIG_BLOCK, &igmask, &omask);
41     func = signal(SIGINT, SIG_IGN);
42     fd = ss_pager_create();
43     if (fd < 0) {
44         perror("ss_pager_create");
45         (void) signal(SIGINT, func);
46         return;
47     }
48     output = fdopen(fd, "w");
49     sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
50
51     fprintf (output, "Available %s requests:\n\n",
52              ss_info (sci_idx) -> subsystem_name);
53
54     for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
55         entry = (*table)->requests;
56         for (; entry->command_names; entry++) {
57             spacing = -2;
58             if (entry->flags & SS_OPT_DONT_LIST)
59                 continue;
60             for (name = entry->command_names; *name; name++) {
61                 int len = strlen(*name);
62                 fputs(*name, output);
63                 spacing += len + 2;
64                 if (name[1]) {
65                     fputs(", ", output);
66                 }
67             }
68             if (spacing > 23) {
69                 fputc('\n', output);
70                 spacing = 0;
71             }
72             for (i = 0; i < 25 - spacing; i++)
73                 fputc(' ', output);
74             fputs(entry->info_string, output);
75             fputc('\n', output);
76         }
77     }
78     fclose(output);
79 #ifndef NO_FORK
80     wait(&waitb);
81 #endif
82     (void) signal(SIGINT, func);
83 }