[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 | /* |
---|
[22404] | 9 | * $Id: new_trans.c,v 1.30 2006-03-10 07:11:31 ghudson Exp $ |
---|
[84] | 10 | * |
---|
| 11 | * New-transaction routine for DISCUSS. (Request 'talk'.) |
---|
| 12 | * |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #ifndef lint |
---|
[520] | 17 | static char rcsid_discuss_c[] = |
---|
[22404] | 18 | "$Id: new_trans.c,v 1.30 2006-03-10 07:11:31 ghudson Exp $"; |
---|
[12459] | 19 | #endif /* lint */ |
---|
[84] | 20 | |
---|
| 21 | #include <stdio.h> |
---|
| 22 | #include <sys/file.h> |
---|
| 23 | #include <signal.h> |
---|
[1634] | 24 | #include <string.h> |
---|
[84] | 25 | #include <sys/wait.h> |
---|
[12439] | 26 | #if HAVE_FCNTL_H |
---|
[6529] | 27 | #include <fcntl.h> |
---|
| 28 | #endif |
---|
[8816] | 29 | #include <ss/ss.h> |
---|
[1634] | 30 | #include <discuss/discuss.h> |
---|
[185] | 31 | #include "config.h" |
---|
[84] | 32 | #include "globals.h" |
---|
| 33 | |
---|
| 34 | #ifdef lint |
---|
| 35 | #define USE(var) var=var; |
---|
[12459] | 36 | #else /* lint */ |
---|
[84] | 37 | #define USE(var) ; |
---|
[12459] | 38 | #endif /* lint */ |
---|
[84] | 39 | |
---|
| 40 | extern tfile unix_tfile(); |
---|
[1043] | 41 | extern void flag_interrupts(), dont_flag_interrupts(); |
---|
[84] | 42 | |
---|
[189] | 43 | new_trans(argc, argv) |
---|
[520] | 44 | int argc; |
---|
| 45 | char **argv; |
---|
[84] | 46 | { |
---|
[520] | 47 | int fd, txn_no; |
---|
| 48 | tfile tf; |
---|
| 49 | char *subject = &buffer[0]; |
---|
| 50 | char *whoami = argv[0]; |
---|
| 51 | char *mtg = NULL; |
---|
[523] | 52 | char *myname = NULL; |
---|
[520] | 53 | int code; |
---|
| 54 | char *editor = NULL; |
---|
[84] | 55 | |
---|
[520] | 56 | USE(sci_idx); |
---|
[523] | 57 | |
---|
[520] | 58 | while (++argv, --argc) { |
---|
| 59 | if (!strcmp (*argv, "-meeting") || !strcmp (*argv, "-mtg")) { |
---|
| 60 | if (argc==1) { |
---|
| 61 | ss_perror(sci_idx, 0, "No arguments supplied."); |
---|
| 62 | return; |
---|
| 63 | } else { |
---|
| 64 | --argc; |
---|
| 65 | mtg = *(++argv); |
---|
| 66 | } |
---|
| 67 | } else if (!strcmp (*argv, "-editor") || !strcmp(*argv, "-ed")) { |
---|
| 68 | if (argc==1) { |
---|
| 69 | ss_perror(sci_idx, 0, "No editor name supplied."); |
---|
| 70 | return; |
---|
| 71 | } else { |
---|
| 72 | --argc; |
---|
| 73 | editor = *(++argv); |
---|
| 74 | } |
---|
[594] | 75 | } else if (!strcmp(*argv, "-no_editor") || !strcmp(*argv, "-ned")) { |
---|
[520] | 76 | editor = ""; |
---|
| 77 | } else { |
---|
| 78 | (void) fprintf(stderr, |
---|
| 79 | "Usage: %s [ -editor cmd ] [ -no_editor ] [ -mtg meeting_name ]\n", |
---|
| 80 | whoami); |
---|
| 81 | return; |
---|
| 82 | } |
---|
| 83 | } |
---|
[523] | 84 | |
---|
| 85 | flag_interrupts(); |
---|
[594] | 86 | |
---|
[520] | 87 | if (mtg) { |
---|
| 88 | (void) sprintf(buffer, "goto %s", mtg); |
---|
[22404] | 89 | code = ss_execute_line(sci_idx, buffer); |
---|
[520] | 90 | if (code != 0) { |
---|
| 91 | ss_perror(sci_idx, code, buffer); |
---|
[523] | 92 | goto punt; |
---|
[520] | 93 | } |
---|
[523] | 94 | if (interrupt) goto punt; |
---|
[520] | 95 | } |
---|
[195] | 96 | |
---|
[520] | 97 | if (!dsc_public.attending) { |
---|
| 98 | ss_perror(sci_idx, DISC_NO_MTG, ""); |
---|
[523] | 99 | goto punt; |
---|
[520] | 100 | } |
---|
[135] | 101 | |
---|
[523] | 102 | if(!acl_is_subset("w", dsc_public.m_info.access_modes)) { |
---|
[520] | 103 | ss_perror(sci_idx, 0, |
---|
[523] | 104 | "You do not have permission to create transactions in this meeting."); |
---|
| 105 | goto punt; |
---|
| 106 | } |
---|
[119] | 107 | |
---|
[523] | 108 | dsc_whoami(&dsc_public.nb, &myname, &code); |
---|
| 109 | if (interrupt) goto punt; |
---|
| 110 | if (code != 0) { |
---|
| 111 | ss_perror(sci_idx, code, "while checking for anonymity"); |
---|
| 112 | } else { |
---|
| 113 | if (strncmp(myname, "???", 3) == 0) { |
---|
| 114 | printf("Entry will be anonymous.\n"); |
---|
| 115 | } |
---|
| 116 | } |
---|
[1820] | 117 | free(myname); |
---|
| 118 | myname = NULL; |
---|
[594] | 119 | |
---|
[520] | 120 | (void) printf("Subject: "); |
---|
[1820] | 121 | if (fgets(subject,BUFSIZ,stdin) == (char *)NULL) { |
---|
[523] | 122 | clearerr(stdin); |
---|
| 123 | if (interrupt) goto punt; |
---|
[520] | 124 | ss_perror(sci_idx, errno, "Error reading subject."); |
---|
[523] | 125 | goto punt; |
---|
[520] | 126 | } |
---|
[523] | 127 | if (interrupt) goto punt; |
---|
[1820] | 128 | subject[strlen(subject)-1] = '\0'; /* Get rid of NL */ |
---|
[523] | 129 | |
---|
[520] | 130 | (void) unlink(temp_file); |
---|
| 131 | if ((code = edit(temp_file, editor)) != 0) { |
---|
| 132 | ss_perror(sci_idx, code, |
---|
| 133 | "Error during edit; transaction not entered."); |
---|
[523] | 134 | goto punt; |
---|
[520] | 135 | } |
---|
[523] | 136 | if (interrupt) goto punt; |
---|
[520] | 137 | fd = open(temp_file, O_RDONLY, 0); |
---|
| 138 | if (fd < 0) { |
---|
| 139 | ss_perror(sci_idx, errno, "Can't read transaction"); |
---|
[523] | 140 | goto punt; |
---|
[520] | 141 | } |
---|
| 142 | tf = unix_tfile(fd); |
---|
| 143 | dsc_add_trn(&dsc_public.nb, tf, subject, 0, |
---|
| 144 | &txn_no, &code); |
---|
| 145 | if (code != 0) { |
---|
[1033] | 146 | ss_perror(sci_idx, code, "while adding transaction"); |
---|
[1436] | 147 | close(fd); |
---|
[523] | 148 | goto punt; |
---|
[520] | 149 | } |
---|
[594] | 150 | |
---|
[1436] | 151 | close(fd); |
---|
[1861] | 152 | (void) unlink(temp_file); |
---|
[1436] | 153 | |
---|
[1515] | 154 | (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
[594] | 155 | txn_no, dsc_public.mtg_name); |
---|
| 156 | |
---|
[520] | 157 | if (dsc_public.current == 0) |
---|
[594] | 158 | dsc_public.current = txn_no; |
---|
[520] | 159 | |
---|
| 160 | /* and now a pragmatic definition of 'seen': If you are up-to-date |
---|
| 161 | in a meeting, then you see transactions you enter. */ |
---|
| 162 | if (dsc_public.highest_seen == txn_no -1) { |
---|
| 163 | dsc_public.highest_seen = txn_no; |
---|
| 164 | } |
---|
[1112] | 165 | |
---|
| 166 | /* update last */ |
---|
| 167 | dsc_public.m_info.last = txn_no; |
---|
| 168 | dsc_public.m_info.highest = txn_no; |
---|
[523] | 169 | punt: |
---|
| 170 | dont_flag_interrupts(); |
---|
[84] | 171 | } |
---|