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