list_rqs.c revision d1154eb460efe588eaed3d439c1caaca149fa362
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 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 buffer[0] = '\0'; 59 if (entry->flags & SS_OPT_DONT_LIST) 60 continue; 61 for (name = entry->command_names; *name; name++) { 62 int len = strlen(*name); 63 strncat(buffer, *name, len); 64 spacing += len + 2; 65 if (name[1]) { 66 strcat(buffer, ", "); 67 } 68 } 69 if (spacing > 23) { 70 strcat(buffer, NL); 71 fputs(buffer, output); 72 spacing = 0; 73 buffer[0] = '\0'; 74 } 75 strncat(buffer, twentyfive_spaces, 25-spacing); 76 strcat(buffer, entry->info_string); 77 strcat(buffer, NL); 78 fputs(buffer, output); 79 } 80 } 81 fclose(output); 82#ifndef NO_FORK 83 wait(&waitb); 84#endif 85 (void) signal(SIGINT, func); 86} 87