[285] | 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 | /* |
---|
[22404] | 9 | * $Id: reply.c,v 1.23 2006-03-10 07:11:31 ghudson Exp $ |
---|
[285] | 10 | * |
---|
| 11 | * Code for "reply" request in discuss. |
---|
| 12 | * |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #ifndef lint |
---|
[1638] | 17 | static char rcsid_discuss_c[] = |
---|
[22404] | 18 | "$Id: reply.c,v 1.23 2006-03-10 07:11:31 ghudson Exp $"; |
---|
[12459] | 19 | #endif /* lint */ |
---|
[285] | 20 | |
---|
| 21 | #include <stdio.h> |
---|
[22404] | 22 | #include <stdlib.h> |
---|
[285] | 23 | #include <sys/file.h> |
---|
[6529] | 24 | #include <string.h> |
---|
| 25 | #include <fcntl.h> |
---|
[285] | 26 | #include <sys/wait.h> |
---|
[8816] | 27 | #include <ss/ss.h> |
---|
[1638] | 28 | #include <discuss/discuss.h> |
---|
[285] | 29 | #include "config.h" |
---|
| 30 | #include "globals.h" |
---|
| 31 | |
---|
| 32 | /* EXTERNAL ROUTINES */ |
---|
| 33 | |
---|
| 34 | tfile unix_tfile(); |
---|
[1438] | 35 | extern void flag_interrupts(),dont_flag_interrupts(); |
---|
[285] | 36 | |
---|
| 37 | #define DEFAULT_EDITOR "/bin/ed" |
---|
| 38 | |
---|
| 39 | repl(argc, argv) |
---|
| 40 | int argc; |
---|
| 41 | char **argv; |
---|
| 42 | { |
---|
| 43 | int fd; |
---|
| 44 | trn_nums txn_no, orig_trn; |
---|
| 45 | tfile tf; |
---|
| 46 | selection_list *trn_list; |
---|
| 47 | trn_info t_info; |
---|
| 48 | int code; |
---|
[1846] | 49 | int prompt_subject = FALSE; |
---|
| 50 | char *subject = &buffer[0]; |
---|
[285] | 51 | char *editor = NULL; |
---|
| 52 | char *trans = NULL; |
---|
| 53 | char *mtg = NULL; |
---|
[525] | 54 | char *myname = NULL; |
---|
[1097] | 55 | |
---|
[285] | 56 | while (++argv, --argc) { |
---|
| 57 | if (!strcmp (*argv, "-meeting") || !strcmp (*argv, "-mtg")) { |
---|
| 58 | if (argc==1) { |
---|
| 59 | (void) fprintf(stderr, |
---|
| 60 | "No argument to %s.\n", *argv); |
---|
| 61 | return; |
---|
| 62 | } else { |
---|
| 63 | --argc; |
---|
| 64 | mtg = *(++argv); |
---|
| 65 | } |
---|
| 66 | } else if (!strcmp (*argv, "-editor") || !strcmp(*argv, "-ed")) { |
---|
| 67 | if (argc==1) { |
---|
| 68 | (void) fprintf(stderr, |
---|
| 69 | "No argument to %s.\n", *argv); |
---|
| 70 | return; |
---|
| 71 | } else { |
---|
| 72 | --argc; |
---|
| 73 | editor = *(++argv); |
---|
| 74 | } |
---|
| 75 | } else if (!strcmp(*argv, "-no_editor")) { |
---|
| 76 | editor = ""; |
---|
[1846] | 77 | } else if (!strcmp(*argv, "-subject") || |
---|
| 78 | !strcmp(*argv, "-sj")) { |
---|
| 79 | /* prompt for subject */ |
---|
| 80 | prompt_subject = TRUE; |
---|
[285] | 81 | } else { |
---|
| 82 | if (!trans) trans = *argv; |
---|
| 83 | else { |
---|
[596] | 84 | ss_perror(sci_idx, 0, |
---|
| 85 | "Cannot reply to multiple transactions"); |
---|
| 86 | return; |
---|
[285] | 87 | } |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | if (mtg && !trans) { |
---|
[596] | 91 | fprintf(stderr, |
---|
| 92 | "Must have transaction specifier if using -mtg.\n"); |
---|
[285] | 93 | return; |
---|
| 94 | } |
---|
[596] | 95 | if (mtg) { |
---|
[285] | 96 | (void) sprintf(buffer, "goto %s", mtg); |
---|
[22404] | 97 | code = ss_execute_line(sci_idx, buffer); |
---|
[285] | 98 | if (code != 0) { |
---|
| 99 | ss_perror(sci_idx, code, buffer); |
---|
| 100 | return; |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
[1438] | 104 | flag_interrupts(); |
---|
[285] | 105 | if (!dsc_public.attending) { |
---|
| 106 | ss_perror(sci_idx, 0, "No current meeting.\n"); |
---|
[1438] | 107 | goto abort2; |
---|
[285] | 108 | } |
---|
| 109 | |
---|
[286] | 110 | dsc_get_trn_info(&dsc_public.nb, dsc_public.current, &t_info, &code); |
---|
[285] | 111 | if (code != 0) |
---|
| 112 | t_info.current = 0; |
---|
[1819] | 113 | dsc_destroy_trn_info(&t_info); |
---|
[285] | 114 | |
---|
| 115 | trn_list = trn_select(&t_info, trans ? trans : "current" , |
---|
| 116 | (selection_list *)NULL, &code); |
---|
| 117 | if (code) { |
---|
| 118 | ss_perror(sci_idx, code, ""); |
---|
[1819] | 119 | sl_free((char *) trn_list); |
---|
[1438] | 120 | goto abort2; |
---|
[285] | 121 | } |
---|
| 122 | |
---|
| 123 | if (trn_list -> low != trn_list -> high) { |
---|
| 124 | ss_perror(sci_idx, 0, "Cannot reply to range"); |
---|
[1819] | 125 | sl_free((char *)trn_list); |
---|
[1438] | 126 | goto abort2; |
---|
[285] | 127 | } |
---|
| 128 | |
---|
| 129 | orig_trn = trn_list -> low; |
---|
[1819] | 130 | sl_free((char *)trn_list); |
---|
[285] | 131 | |
---|
[286] | 132 | dsc_get_trn_info(&dsc_public.nb, orig_trn, &t_info, &code); |
---|
[1035] | 133 | |
---|
[285] | 134 | if (code != 0) { |
---|
[525] | 135 | ss_perror(sci_idx, code, ""); |
---|
[1819] | 136 | goto abort; |
---|
[285] | 137 | } |
---|
| 138 | |
---|
[525] | 139 | if(!acl_is_subset("a", dsc_public.m_info.access_modes)) { |
---|
[596] | 140 | (void) ss_perror(sci_idx, 0, |
---|
| 141 | "You do not have permission to create replies in this meeting."); |
---|
| 142 | goto abort; |
---|
[525] | 143 | } |
---|
[285] | 144 | |
---|
[525] | 145 | dsc_whoami(&dsc_public.nb, &myname, &code); |
---|
| 146 | |
---|
| 147 | if (code != 0) { |
---|
| 148 | ss_perror(sci_idx, code, "while checking for anonymity"); |
---|
| 149 | } else { |
---|
| 150 | if (strncmp(myname, "???", 3) == 0) { |
---|
| 151 | printf("Reply will be anonymous.\n"); |
---|
| 152 | } |
---|
| 153 | } |
---|
[1819] | 154 | free(myname); |
---|
| 155 | myname = NULL; |
---|
[525] | 156 | |
---|
[1846] | 157 | if (prompt_subject) { |
---|
| 158 | (void) printf("Subject: "); |
---|
| 159 | if (fgets(subject,BUFSIZ,stdin) == (char *)NULL) { |
---|
| 160 | clearerr(stdin); |
---|
| 161 | if (interrupt) goto abort; |
---|
| 162 | ss_perror(sci_idx, errno, "Error reading subject."); |
---|
| 163 | goto abort; |
---|
| 164 | } |
---|
| 165 | if (interrupt) goto abort; |
---|
| 166 | subject[strlen(subject)-1] = '\0'; /* Get rid of NL */ |
---|
| 167 | } else { |
---|
| 168 | if (strncmp(t_info.subject, "Re: ", 4)) { |
---|
[285] | 169 | char *new_subject = malloc((unsigned)strlen(t_info.subject)+5); |
---|
| 170 | (void) strcpy(new_subject, "Re: "); |
---|
| 171 | (void) strcat(new_subject, t_info.subject); |
---|
| 172 | (void) free(t_info.subject); |
---|
| 173 | t_info.subject = new_subject; |
---|
[1846] | 174 | } |
---|
| 175 | |
---|
| 176 | printf("Subject: %s\n", t_info.subject); |
---|
[285] | 177 | } |
---|
| 178 | (void) unlink(temp_file); |
---|
| 179 | if (edit(temp_file, editor) != 0) { |
---|
| 180 | (void) fprintf(stderr, |
---|
| 181 | "Error during edit; transaction not entered\n"); |
---|
| 182 | goto abort; |
---|
| 183 | } |
---|
[1438] | 184 | if (interrupt) goto abort; |
---|
[285] | 185 | fd = open(temp_file, O_RDONLY, 0); |
---|
| 186 | if (fd < 0) { |
---|
| 187 | (void) fprintf(stderr, "No file; not entered.\n"); |
---|
| 188 | goto abort; |
---|
| 189 | } |
---|
| 190 | tf = unix_tfile(fd); |
---|
| 191 | |
---|
[1846] | 192 | dsc_add_trn(&dsc_public.nb, tf, |
---|
| 193 | prompt_subject ? subject : t_info.subject, |
---|
[286] | 194 | orig_trn, &txn_no, &code); |
---|
[285] | 195 | if (code != 0) { |
---|
[525] | 196 | ss_perror(sci_idx, code, "while adding transaction\n"); |
---|
[1435] | 197 | close(fd); |
---|
[285] | 198 | goto abort; |
---|
| 199 | } |
---|
[596] | 200 | |
---|
[1435] | 201 | close(fd); |
---|
[1861] | 202 | (void) unlink(temp_file); |
---|
[1516] | 203 | (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
[596] | 204 | txn_no, dsc_public.mtg_name); |
---|
[285] | 205 | |
---|
| 206 | dsc_public.current = orig_trn; |
---|
| 207 | |
---|
| 208 | /* and now a pragmatic definition of 'seen': If you are up-to-date |
---|
| 209 | in a meeting, then you see transactions you enter. */ |
---|
| 210 | if (dsc_public.highest_seen == txn_no -1) { |
---|
[286] | 211 | dsc_public.highest_seen = txn_no; |
---|
[285] | 212 | } |
---|
| 213 | |
---|
[1111] | 214 | /* Update last */ |
---|
| 215 | dsc_public.m_info.last = txn_no; |
---|
| 216 | dsc_public.m_info.highest = txn_no; |
---|
| 217 | |
---|
[285] | 218 | abort: |
---|
[1819] | 219 | dsc_destroy_trn_info(&t_info); |
---|
[1438] | 220 | abort2: |
---|
| 221 | dont_flag_interrupts(); |
---|
[285] | 222 | } |
---|
[525] | 223 | |
---|