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