1 /* 2 * Copyright (c) 2000 by Sun Microsystems, Inc. 3 * All rights reserved. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 /* 9 * Copyright 1987, 1988 by MIT Student Information Processing Board 10 * 11 * For copyright information, see copyright.h. 12 */ 13 #include "copyright.h" 14 #include "ss_internal.h" 15 #include <libintl.h> 16 #include <signal.h> 17 #include <setjmp.h> 18 #include <sys/wait.h> 19 20 #ifdef lint /* "lint returns a value which is sometimes ignored" */ 21 #define DONT_USE(x) x=x; 22 #else /* !lint */ 23 #define DONT_USE(x) ; 24 #endif /* lint */ 25 26 extern int ss_pager_create(); 27 28 static char const twentyfive_spaces[26] = 29 " "; 30 static char const NL[2] = "\n"; 31 32 void 33 ss_list_requests(argc, argv, sci_idx, info_ptr) 34 int argc; 35 char **argv; 36 int sci_idx; 37 pointer info_ptr; 38 { 39 register ss_request_entry *entry; 40 register char const * const *name; 41 register int spacing; 42 register ss_request_table **table; 43 44 char buffer[BUFSIZ]; 45 FILE *output; 46 int fd; 47 #ifdef POSIX_SIGNALS 48 struct sigaction nsig, osig; 49 sigset_t nmask, omask; 50 #else 51 int mask; 52 RETSIGTYPE (*func)(); 53 #endif 54 #ifndef WAIT_USES_INT 55 union wait waitb; 56 #else 57 int waitb; 58 #endif 59 60 DONT_USE(argc); 61 DONT_USE(argv); 62 63 #ifdef POSIX_SIGNALS 64 sigemptyset(&nmask); 65 sigaddset(&nmask, SIGINT); 66 sigprocmask(SIG_BLOCK, &nmask, &omask); 67 68 nsig.sa_handler = SIG_IGN; 69 sigemptyset(&nsig.sa_mask); 70 nsig.sa_flags = 0; 71 sigaction(SIGINT, &nsig, &osig); 72 #else 73 mask = sigblock(sigmask(SIGINT)); 74 func = signal(SIGINT, SIG_IGN); 75 #endif 76 77 fd = ss_pager_create(); 78 output = fdopen(fd, "w"); 79 80 #ifdef POSIX_SIGNALS 81 sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); 82 #else 83 sigsetmask(mask); 84 #endif 85 86 fprintf (output, dgettext(TEXT_DOMAIN, "Available %s requests:\n\n"), 87 ss_info (sci_idx) -> subsystem_name); 88 89 for (table = ss_info(sci_idx)->rqt_tables; *table; table++) { 90 entry = (*table)->requests; 91 for (; entry->command_names; entry++) { 92 spacing = -2; 93 buffer[0] = '\0'; 94 if (entry->flags & SS_OPT_DONT_LIST) 95 continue; 96 for (name = entry->command_names; *name; name++) { 97 register int len = strlen(*name); 98 strncat(buffer, *name, len); 99 spacing += len + 2; 100 if (name[1]) { 101 strcat(buffer, ", "); 102 } 103 } 104 if (spacing > 23) { 105 strcat(buffer, NL); 106 fputs(buffer, output); 107 spacing = 0; 108 buffer[0] = '\0'; 109 } 110 strncat(buffer, twentyfive_spaces, 25-spacing); 111 112 /* 113 * Due to libss not knowing what TEXT_DOMAIN 114 * the calling application is using for its info_string 115 * messages, we know require the callers (ktutil,kadmin) 116 * to L10N the messages before calling libss. 117 */ 118 strcat(buffer, entry->info_string); 119 strcat(buffer, NL); 120 fputs(buffer, output); 121 } 122 } 123 fclose(output); 124 #ifndef NO_FORK 125 wait(&waitb); 126 #endif 127 #ifdef POSIX_SIGNALS 128 sigaction(SIGINT, &osig, (struct sigaction *)0); 129 #else 130 (void) signal(SIGINT, func); 131 #endif 132 } 133