[84] | 1 | /* |
---|
[1927] | 2 | * |
---|
| 3 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
| 4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
| 5 | * For copying information, see the file mit-copyright.h in this release. |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | /* |
---|
[84] | 9 | * Print-related requests for DISCUSS. |
---|
| 10 | * |
---|
[22418] | 11 | * $Id: print.c,v 1.29 2006-03-13 21:39:56 amb Exp $ |
---|
[84] | 12 | * |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #ifndef lint |
---|
[1635] | 17 | static char rcsid_discuss_c[] = |
---|
[22418] | 18 | "$Id: print.c,v 1.29 2006-03-13 21:39:56 amb Exp $"; |
---|
[1635] | 19 | #endif /* lint */ |
---|
[84] | 20 | |
---|
| 21 | #include <stdio.h> |
---|
[120] | 22 | #include <errno.h> |
---|
[84] | 23 | #include <sys/file.h> |
---|
| 24 | #include <signal.h> |
---|
[1635] | 25 | #include <string.h> |
---|
[12439] | 26 | #if HAVE_SYS_WAIT_H |
---|
[84] | 27 | #include <sys/wait.h> |
---|
[12439] | 28 | #endif |
---|
| 29 | #if HAVE_FCNTL_H |
---|
[6529] | 30 | #include <fcntl.h> |
---|
| 31 | #endif |
---|
[1635] | 32 | #include <discuss/discuss.h> |
---|
[8816] | 33 | #include <ss/ss.h> |
---|
[185] | 34 | #include "config.h" |
---|
[84] | 35 | #include "globals.h" |
---|
| 36 | |
---|
| 37 | #ifdef lint |
---|
| 38 | #define USE(var) var=var; |
---|
[12459] | 39 | #else /* lint */ |
---|
[84] | 40 | #define USE(var) ; |
---|
[12459] | 41 | #endif /* lint */ |
---|
[84] | 42 | |
---|
[120] | 43 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
---|
| 44 | |
---|
[84] | 45 | extern tfile unix_tfile(); |
---|
[120] | 46 | static trn_nums performed; |
---|
[105] | 47 | static char * request_name; |
---|
| 48 | static trn_info t_info; |
---|
| 49 | static tfile tf; |
---|
[84] | 50 | |
---|
[286] | 51 | extern void sl_free(); |
---|
| 52 | |
---|
[144] | 53 | static int |
---|
[1803] | 54 | display_trans(t_infop, codep) |
---|
[2737] | 55 | trn_info3 *t_infop; |
---|
[1803] | 56 | int *codep; |
---|
[105] | 57 | { |
---|
[1803] | 58 | output_trans(t_infop, tf, codep); |
---|
| 59 | if (*codep == 0) { |
---|
| 60 | dsc_public.highest_seen = max(dsc_public.highest_seen,t_infop->current); |
---|
| 61 | dsc_public.current = t_infop->current; |
---|
[120] | 62 | performed = TRUE; |
---|
[1803] | 63 | } else if (*codep == EPIPE) { |
---|
| 64 | dsc_public.current = t_infop->current; |
---|
[120] | 65 | performed = TRUE; |
---|
[1803] | 66 | return; /* silently quit */ |
---|
[105] | 67 | } |
---|
[1803] | 68 | else if (*codep != DELETED_TRN) { |
---|
[120] | 69 | fprintf(stderr, "Error printing transaction: %s\n", |
---|
[1803] | 70 | error_message(*codep)); |
---|
| 71 | return; |
---|
[120] | 72 | } |
---|
| 73 | |
---|
[1803] | 74 | *codep = 0; |
---|
| 75 | return; |
---|
[105] | 76 | } |
---|
| 77 | |
---|
[189] | 78 | prt_trans(argc, argv) |
---|
[84] | 79 | int argc; |
---|
| 80 | char **argv; |
---|
| 81 | { |
---|
| 82 | int fd; |
---|
[12439] | 83 | #if !HAVE_SIGACTION |
---|
[84] | 84 | int (*old_sig)(); |
---|
[7166] | 85 | #endif |
---|
[144] | 86 | int code; |
---|
[105] | 87 | selection_list *trn_list; |
---|
[12439] | 88 | #if HAVE_SIGACTION |
---|
| 89 | struct sigaction act, oact; |
---|
[7166] | 90 | #endif |
---|
[84] | 91 | |
---|
[120] | 92 | request_name = ss_name(sci_idx); |
---|
[309] | 93 | |
---|
| 94 | if (argc != 1) { |
---|
| 95 | if (strcmp(argv[0], "print") && |
---|
[22418] | 96 | strcmp(argv[0], "show") && |
---|
[309] | 97 | strcmp(argv[0], "pr") && |
---|
| 98 | strcmp(argv[0], "p")) { |
---|
| 99 | fprintf(stderr, "Usage: %s\n", argv[0]); |
---|
| 100 | return; |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
[120] | 104 | if (!dsc_public.attending) { |
---|
[8260] | 105 | ss_perror(sci_idx, DISC_NO_MTG, ""); |
---|
[600] | 106 | return; |
---|
[84] | 107 | } |
---|
[1803] | 108 | dsc_destroy_mtg_info(&dsc_public.m_info); |
---|
[286] | 109 | dsc_get_mtg_info(&dsc_public.nb, |
---|
| 110 | &dsc_public.m_info, &code); |
---|
[105] | 111 | if (code != 0) { |
---|
[600] | 112 | (void) ss_perror(sci_idx, code, "Can't get meeting info"); |
---|
| 113 | return; |
---|
[105] | 114 | } |
---|
[120] | 115 | |
---|
[286] | 116 | dsc_get_trn_info(&dsc_public.nb, dsc_public.current, |
---|
| 117 | &t_info, &code); |
---|
[965] | 118 | if (code == DELETED_TRN) { |
---|
| 119 | t_info.current = dsc_public.current; |
---|
| 120 | t_info.next = dsc_public.current+1; |
---|
| 121 | t_info.prev = dsc_public.current-1; |
---|
| 122 | } else if (code) |
---|
[120] | 123 | t_info.current = 0; |
---|
[105] | 124 | |
---|
[1803] | 125 | dsc_destroy_trn_info(&t_info); |
---|
| 126 | |
---|
[105] | 127 | if (argc == 1) { |
---|
[309] | 128 | char *ref; |
---|
| 129 | if (!strcmp(argv[0], "print") || |
---|
[22418] | 130 | !strcmp(argv[0], "show") || |
---|
[309] | 131 | !strcmp(argv[0], "pr") || |
---|
| 132 | !strcmp(argv[0], "p")) { |
---|
| 133 | ref = "current"; |
---|
| 134 | } else ref = argv[0]; |
---|
| 135 | |
---|
| 136 | trn_list = trn_select(&t_info, ref, |
---|
[120] | 137 | (selection_list *)NULL, &code); |
---|
| 138 | if (code) { |
---|
| 139 | ss_perror(sci_idx, code, ""); |
---|
[1803] | 140 | sl_free(trn_list); |
---|
[120] | 141 | return; |
---|
| 142 | } |
---|
[84] | 143 | } |
---|
[105] | 144 | else if (argc == 2) { |
---|
| 145 | trn_list = trn_select(&t_info, argv[1], |
---|
| 146 | (selection_list *)NULL, &code); |
---|
| 147 | if (code) { |
---|
| 148 | ss_perror(sci_idx, code, ""); |
---|
| 149 | sl_free(trn_list); |
---|
| 150 | return; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | else { |
---|
| 154 | trn_list = (selection_list *)NULL; |
---|
| 155 | while (argv++, argc-- > 1) { |
---|
| 156 | trn_list = trn_select(&t_info, *argv, |
---|
| 157 | trn_list, &code); |
---|
| 158 | if (code) { |
---|
| 159 | ss_perror(sci_idx, code, *argv); |
---|
| 160 | sl_free(trn_list); |
---|
| 161 | return; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
[120] | 166 | performed = FALSE; |
---|
[84] | 167 | /* |
---|
| 168 | * Ignore SIGPIPE from the pager |
---|
| 169 | */ |
---|
[12439] | 170 | #if HAVE_SIGACTION |
---|
| 171 | sigemptyset(&act.sa_mask); |
---|
| 172 | act.sa_flags = 0; |
---|
| 173 | act.sa_handler= (void (*)()) SIG_IGN; |
---|
| 174 | (void) sigaction(SIGPIPE, &act, &oact); |
---|
[7166] | 175 | #else |
---|
[84] | 176 | old_sig = signal(SIGPIPE, SIG_IGN); |
---|
[7166] | 177 | #endif |
---|
[106] | 178 | fd = ss_pager_create(); |
---|
[84] | 179 | if (fd < 0) { |
---|
[600] | 180 | ss_perror(sci_idx, errno, "Can't start pager"); |
---|
| 181 | return; |
---|
[84] | 182 | } |
---|
| 183 | tf = unix_tfile(fd); |
---|
[1803] | 184 | (void) sl_map(display_trans, trn_list,FALSE); |
---|
| 185 | sl_free(trn_list); |
---|
[84] | 186 | tclose(tf, &code); |
---|
| 187 | (void) close(fd); |
---|
| 188 | (void) tdestroy(tf); |
---|
[6529] | 189 | (void) wait((int *)0); |
---|
[12439] | 190 | #if HAVE_SIGACTION |
---|
| 191 | (void) sigaction (SIGPIPE, &oact, NULL); |
---|
[6529] | 192 | #else |
---|
[84] | 193 | (void) signal(SIGPIPE, old_sig); |
---|
[7166] | 194 | #endif |
---|
[120] | 195 | if (!performed) |
---|
[600] | 196 | ss_perror(sci_idx, DISC_NO_TRN, ""); |
---|
[84] | 197 | } |
---|
| 198 | |
---|
[189] | 199 | write_trans(argc, argv) |
---|
[84] | 200 | int argc; |
---|
| 201 | char **argv; |
---|
| 202 | { |
---|
[105] | 203 | selection_list *trn_list; |
---|
[84] | 204 | int fd; |
---|
| 205 | int code; |
---|
[600] | 206 | char *arg, *filename; |
---|
[84] | 207 | |
---|
[286] | 208 | if (dsc_public.host == (char *)NULL) { |
---|
[600] | 209 | ss_perror(sci_idx, DISC_NO_MTG, ""); |
---|
| 210 | return; |
---|
[84] | 211 | } |
---|
[1803] | 212 | dsc_destroy_mtg_info(&dsc_public.m_info); |
---|
[286] | 213 | dsc_get_mtg_info(&dsc_public.nb, |
---|
| 214 | &dsc_public.m_info, &code); |
---|
[105] | 215 | if (code != 0) { |
---|
| 216 | (void) ss_perror(sci_idx, code, "Can't get meeting info"); |
---|
| 217 | return; |
---|
| 218 | } |
---|
[600] | 219 | if (argc == 3) { |
---|
| 220 | arg = argv[1]; |
---|
| 221 | filename = argv[2]; |
---|
[84] | 222 | } |
---|
[600] | 223 | else if (argc == 2) { |
---|
| 224 | arg = "current"; |
---|
| 225 | filename = argv[1]; |
---|
| 226 | } |
---|
| 227 | else { |
---|
| 228 | (void) fprintf(stderr, |
---|
| 229 | "Usage: %s transaction_list filename\n", |
---|
| 230 | argv[0]); |
---|
| 231 | return; |
---|
| 232 | } |
---|
| 233 | trn_list = trn_select(&t_info, arg, (selection_list *)NULL, &code); |
---|
[105] | 234 | if (code) { |
---|
[600] | 235 | ss_perror(sci_idx, code, arg); |
---|
[105] | 236 | sl_free(trn_list); |
---|
| 237 | return; |
---|
| 238 | } |
---|
[120] | 239 | performed = FALSE; |
---|
[84] | 240 | |
---|
[600] | 241 | fd = open(filename, O_CREAT|O_APPEND|O_WRONLY, 0666); |
---|
[84] | 242 | if (fd < 0) { |
---|
[92] | 243 | ss_perror(sci_idx, errno, "Can't open output file"); |
---|
[84] | 244 | return; |
---|
| 245 | } |
---|
| 246 | tf = unix_tfile(fd); |
---|
[1803] | 247 | (void) sl_map(display_trans, trn_list, FALSE); |
---|
| 248 | sl_free(trn_list); |
---|
[84] | 249 | tclose(tf, &code); |
---|
| 250 | (void) close(fd); |
---|
| 251 | (void) tdestroy(tf); |
---|
[120] | 252 | if (!performed) |
---|
[600] | 253 | ss_perror(sci_idx, DISC_NO_TRN, ""); |
---|
[120] | 254 | return; |
---|
[84] | 255 | } |
---|