e2fsprogs/lib/ss/list_rqs.c

92 lines
2.7 KiB
C
Raw Normal View History

1997-04-26 17:21:57 +04:00
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose is hereby granted, provided that
* the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. M.I.T. and the
* M.I.T. S.I.P.B. make no representations about the suitability of
* this software for any purpose. It is provided "as is" without
* express or implied warranty.
1997-04-26 17:21:57 +04:00
*/
#include "config.h"
1997-04-26 17:21:57 +04:00
#include "ss_internal.h"
#include <signal.h>
#include <setjmp.h>
#include <sys/wait.h>
typedef void sigret_t;
static char const twentyfive_spaces[26] =
" ";
static char const NL[2] = "\n";
2003-12-07 09:28:50 +03:00
void ss_list_requests(int argc __SS_ATTR((unused)),
const char * const *argv __SS_ATTR((unused)),
int sci_idx, void *infop __SS_ATTR((unused)))
1997-04-26 17:21:57 +04:00
{
2003-12-07 09:28:50 +03:00
ss_request_entry *entry;
char const * const *name;
int spacing;
ss_request_table **table;
1997-04-26 17:21:57 +04:00
char buffer[BUFSIZ];
FILE *output;
int fd;
1997-04-26 17:34:30 +04:00
sigset_t omask, igmask;
sigret_t (*func)(int);
1997-04-26 17:34:30 +04:00
#ifndef NO_FORK
1997-04-26 17:21:57 +04:00
int waitb;
#endif
1997-04-26 17:34:30 +04:00
sigemptyset(&igmask);
sigaddset(&igmask, SIGINT);
sigprocmask(SIG_BLOCK, &igmask, &omask);
1997-04-26 17:21:57 +04:00
func = signal(SIGINT, SIG_IGN);
fd = ss_pager_create();
if (fd < 0) {
perror("ss_pager_create");
(void) signal(SIGINT, func);
return;
}
1997-04-26 17:21:57 +04:00
output = fdopen(fd, "w");
1997-04-26 17:34:30 +04:00
sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
1997-04-26 17:21:57 +04:00
fprintf (output, "Available %s requests:\n\n",
ss_info (sci_idx) -> subsystem_name);
for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
entry = (*table)->requests;
for (; entry->command_names; entry++) {
spacing = -2;
buffer[0] = '\0';
if (entry->flags & SS_OPT_DONT_LIST)
continue;
for (name = entry->command_names; *name; name++) {
2003-12-07 09:28:50 +03:00
int len = strlen(*name);
1997-04-26 17:21:57 +04:00
strncat(buffer, *name, len);
spacing += len + 2;
if (name[1]) {
strcat(buffer, ", ");
}
}
if (spacing > 23) {
strcat(buffer, NL);
fputs(buffer, output);
spacing = 0;
buffer[0] = '\0';
}
strncat(buffer, twentyfive_spaces, 25-spacing);
strcat(buffer, entry->info_string);
strcat(buffer, NL);
fputs(buffer, output);
}
}
fclose(output);
#ifndef NO_FORK
wait(&waitb);
#endif
(void) signal(SIGINT, func);
}