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 | * |
---|
10 | * do_trn.c -- Routines to implement the various lisp requests related |
---|
11 | * to transactions |
---|
12 | * |
---|
13 | */ |
---|
14 | |
---|
15 | #include <stdio.h> |
---|
16 | #include <sys/types.h> |
---|
17 | #include <sys/file.h> |
---|
18 | #include <sys/stat.h> |
---|
19 | #include <signal.h> |
---|
20 | #include <sys/wait.h> |
---|
21 | #include <ctype.h> |
---|
22 | #include <sys/time.h> |
---|
23 | #include <netdb.h> |
---|
24 | #if HAVE_FCNTL_H |
---|
25 | #include <fcntl.h> |
---|
26 | #endif |
---|
27 | #include <string.h> |
---|
28 | #include "edsc.h" |
---|
29 | #if HAVE_SRAND48 |
---|
30 | #define random lrand48 |
---|
31 | #define srandom srand48 |
---|
32 | #endif |
---|
33 | |
---|
34 | /* |
---|
35 | * Define POSIX-style macros for systems who don't have them. |
---|
36 | */ |
---|
37 | #ifndef S_ISREG |
---|
38 | #define S_ISREG(m) ((m&S_IFMT) == S_IFREG) |
---|
39 | #endif |
---|
40 | |
---|
41 | do_gti(args) |
---|
42 | char *args; |
---|
43 | { |
---|
44 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
45 | trn_nums trn_num; |
---|
46 | name_blk nb; |
---|
47 | trn_info3 t_info; |
---|
48 | int code; |
---|
49 | |
---|
50 | /* First, we get the transaction number */ |
---|
51 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
52 | printf(";Missing trn number\n"); |
---|
53 | return; |
---|
54 | } |
---|
55 | |
---|
56 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
57 | printf(";Missing meeting name\n"); |
---|
58 | return; |
---|
59 | } |
---|
60 | |
---|
61 | trn_num = atoi(trn_string); |
---|
62 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
63 | if (code != 0) { |
---|
64 | printf(";%s\n", error_message(code)); |
---|
65 | return; |
---|
66 | } |
---|
67 | |
---|
68 | dsc_get_trn_info3(&nb,trn_num,&t_info,&code); |
---|
69 | if (code != 0) { |
---|
70 | printf(";%s\n", error_message(code)); |
---|
71 | dsc_destroy_name_blk(&nb); |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | t_info.subject = do_quote(t_info.subject); |
---|
76 | printf("(%d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d \"%s\")\n", |
---|
77 | t_info.current, |
---|
78 | t_info.prev, |
---|
79 | t_info.next, |
---|
80 | t_info.pref, |
---|
81 | t_info.nref, |
---|
82 | t_info.fref, |
---|
83 | t_info.lref, |
---|
84 | t_info.chain_index, |
---|
85 | short_time(&t_info.date_entered), |
---|
86 | t_info.num_lines, |
---|
87 | t_info.num_chars, |
---|
88 | t_info.subject, |
---|
89 | t_info.author, |
---|
90 | t_info.flags, |
---|
91 | t_info.signature ? t_info.signature : ""); |
---|
92 | |
---|
93 | dsc_destroy_name_blk(&nb); |
---|
94 | dsc_destroy_trn_info3(&t_info); |
---|
95 | } |
---|
96 | |
---|
97 | do_gt(args) |
---|
98 | char *args; |
---|
99 | { |
---|
100 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
101 | trn_nums trn_num; |
---|
102 | name_blk nb; |
---|
103 | trn_info3 tinfo; |
---|
104 | tfile tf; |
---|
105 | char *plural; |
---|
106 | char line[255]; |
---|
107 | int code; |
---|
108 | |
---|
109 | /* First, we get the transaction number */ |
---|
110 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
111 | printf(";Missing trn number\n"); |
---|
112 | return; |
---|
113 | } |
---|
114 | |
---|
115 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
116 | printf(";Missing meeting name\n"); |
---|
117 | return; |
---|
118 | } |
---|
119 | |
---|
120 | trn_num = atoi(trn_string); |
---|
121 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
122 | if (code != 0) { |
---|
123 | printf(";%s\n", error_message(code)); |
---|
124 | return; |
---|
125 | } |
---|
126 | |
---|
127 | dsc_get_trn_info3(&nb,trn_num,&tinfo,&code); |
---|
128 | if (code != 0) { |
---|
129 | printf(";%s\n", error_message(code)); |
---|
130 | dsc_destroy_name_blk(&nb); |
---|
131 | return; |
---|
132 | } |
---|
133 | |
---|
134 | if (tinfo.num_lines != 1) |
---|
135 | plural = "s"; |
---|
136 | else |
---|
137 | plural = ""; |
---|
138 | |
---|
139 | |
---|
140 | if (tinfo.subject [0] == '\0') |
---|
141 | tinfo.num_lines--; |
---|
142 | |
---|
143 | printf("(%d)\n", |
---|
144 | tinfo.num_lines+3); |
---|
145 | fflush(stdout); /* Flush out the number of lines */ |
---|
146 | |
---|
147 | tf = stdout_tf; |
---|
148 | |
---|
149 | if (tinfo.signature && strcmp(tinfo.signature, tinfo.author)) |
---|
150 | (void) sprintf (line, "[%04d]%c %s (%s) %s %s (%d line%s)\n", |
---|
151 | tinfo.current, |
---|
152 | tinfo.flags & TRN_FLAG1 ? 'F' : ' ', |
---|
153 | tinfo.author, tinfo.signature, mtg_name, |
---|
154 | short_time (&tinfo.date_entered), |
---|
155 | tinfo.num_lines, plural); |
---|
156 | else |
---|
157 | (void) sprintf (line, "[%04d]%c %s %s %s (%d line%s)\n", |
---|
158 | tinfo.current, |
---|
159 | tinfo.flags & TRN_FLAG1 ? 'F' : ' ', |
---|
160 | tinfo.author, mtg_name, |
---|
161 | short_time (&tinfo.date_entered), |
---|
162 | tinfo.num_lines, plural); |
---|
163 | twrite (tf, line, strlen (line), &code); |
---|
164 | if (tinfo.subject [0] != '\0') { |
---|
165 | twrite (tf, "Subject: ", 9, &code); |
---|
166 | twrite (tf, tinfo.subject, strlen (tinfo.subject), &code); |
---|
167 | twrite (tf, "\n", 1, &code); |
---|
168 | } |
---|
169 | |
---|
170 | dsc_get_trn(&nb, trn_num, tf, &code); |
---|
171 | if (code != 0) return; |
---|
172 | |
---|
173 | if (tinfo.pref == 0 && tinfo.nref == 0) |
---|
174 | (void) sprintf (line, "--[%04d]--\n", tinfo.current); |
---|
175 | else if (tinfo.pref == 0) |
---|
176 | (void) sprintf (line, "--[%04d]-- (nref = [%04d])\n", |
---|
177 | tinfo.current, tinfo.nref); |
---|
178 | else if (tinfo.nref == 0) |
---|
179 | (void) sprintf (line, "--[%04d]-- (pref = [%04d])\n", |
---|
180 | tinfo.current, tinfo.pref); |
---|
181 | else |
---|
182 | (void) sprintf (line, |
---|
183 | "--[%04d]-- (pref = [%04d], nref = [%04d])\n", |
---|
184 | tinfo.current, tinfo.pref, tinfo.nref); |
---|
185 | twrite (tf, line, strlen (line), &code); |
---|
186 | |
---|
187 | dsc_destroy_name_blk(&nb); |
---|
188 | dsc_destroy_trn_info3(&tinfo); |
---|
189 | } |
---|
190 | |
---|
191 | do_gtf(args) |
---|
192 | char *args; |
---|
193 | { |
---|
194 | char *cp = args, *mtg_name, delim, *trn_string, *output_fn; |
---|
195 | trn_nums trn_num; |
---|
196 | name_blk nb; |
---|
197 | trn_info3 tinfo; |
---|
198 | #ifndef EDSC_CACHE |
---|
199 | tfile tf; |
---|
200 | int fd; |
---|
201 | char *plural; |
---|
202 | char line[255]; |
---|
203 | #else |
---|
204 | struct stat stat_buf; |
---|
205 | #endif |
---|
206 | int code; |
---|
207 | |
---|
208 | /* First, get the output filename */ |
---|
209 | if (get_word(&cp, &output_fn, " ", &delim) < 0) { |
---|
210 | printf(";Missing output filename\n"); |
---|
211 | return; |
---|
212 | } |
---|
213 | |
---|
214 | /* Now, we get the transaction number */ |
---|
215 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
216 | printf(";Missing trn number\n"); |
---|
217 | return; |
---|
218 | } |
---|
219 | |
---|
220 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
221 | printf(";Missing meeting name\n"); |
---|
222 | return; |
---|
223 | } |
---|
224 | |
---|
225 | trn_num = atoi(trn_string); |
---|
226 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
227 | if (code != 0) { |
---|
228 | printf(";%s\n", error_message(code)); |
---|
229 | return; |
---|
230 | } |
---|
231 | |
---|
232 | #ifdef EDSC_CACHE |
---|
233 | while (!cache_transaction(&nb, trn_num, &cache_current)) |
---|
234 | ; |
---|
235 | if (cache_current->info_code) { |
---|
236 | printf(";%s\n", error_message(cache_current->info_code)); |
---|
237 | dsc_destroy_name_blk(&nb); |
---|
238 | return; |
---|
239 | } |
---|
240 | if (cache_current->text_code) { |
---|
241 | printf(";%s\n", error_message(cache_current->info_code)); |
---|
242 | dsc_destroy_name_blk(&nb); |
---|
243 | return; |
---|
244 | } |
---|
245 | cache_pc = 0; |
---|
246 | cache_working = 1; |
---|
247 | tinfo = cache_current->t_info; |
---|
248 | if ((!stat(output_fn, &stat_buf)) && |
---|
249 | S_ISREG(stat_buf.st_mode)) |
---|
250 | (void) unlink(output_fn); |
---|
251 | if (link(cache_current->filename, output_fn)) { |
---|
252 | int fd, rfd, cc; |
---|
253 | char buf[8192]; |
---|
254 | |
---|
255 | if ((fd = open(output_fn, |
---|
256 | O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0) { |
---|
257 | printf(";Can't open output file %s: %s\n", output_fn, |
---|
258 | error_message(errno)); |
---|
259 | dsc_destroy_name_blk(&nb); |
---|
260 | return; |
---|
261 | } |
---|
262 | if ((rfd = open(cache_current->filename, O_RDONLY, 0)) < 0) { |
---|
263 | printf(";Can't open input file %s: %s\n", output_fn, |
---|
264 | error_message(errno)); |
---|
265 | dsc_destroy_name_blk(&nb); |
---|
266 | return; |
---|
267 | } |
---|
268 | while ((cc = read(rfd, buf, sizeof(buf))) > 0) { |
---|
269 | if (cc != write(fd, buf, cc)) { |
---|
270 | printf("; Failed write!\n"); |
---|
271 | dsc_destroy_name_blk(&nb); |
---|
272 | return; |
---|
273 | } |
---|
274 | } |
---|
275 | if (cc < 0) { |
---|
276 | printf("; Failed read!\n"); |
---|
277 | dsc_destroy_name_blk(&nb); |
---|
278 | return; |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | #else |
---|
283 | if ((fd = open(output_fn, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0) { |
---|
284 | printf(";Can't open %s: %s\n", output_fn, error_message(errno)); |
---|
285 | return; |
---|
286 | } |
---|
287 | tf = unix_tfile(fd); |
---|
288 | |
---|
289 | dsc_get_trn_info3(&nb,trn_num,&tinfo,&code); |
---|
290 | if (code != 0) { |
---|
291 | printf(";%s\n", error_message(code)); |
---|
292 | dsc_destroy_name_blk(&nb); |
---|
293 | return; |
---|
294 | } |
---|
295 | |
---|
296 | if (tinfo.num_lines != 1) |
---|
297 | plural = "s"; |
---|
298 | else |
---|
299 | plural = ""; |
---|
300 | |
---|
301 | |
---|
302 | if (tinfo.subject [0] == '\0') |
---|
303 | tinfo.num_lines--; |
---|
304 | |
---|
305 | if (tinfo.signature && strcmp(tinfo.signature, tinfo.author)) |
---|
306 | (void) sprintf (line, "[%04d]%c %s (%s) %s %s (%d line%s)\n", |
---|
307 | tinfo.current, |
---|
308 | tinfo.flags & TRN_FLAG1 ? 'F' : ' ', |
---|
309 | tinfo.author, tinfo.signature, mtg_name, |
---|
310 | short_time (&tinfo.date_entered), |
---|
311 | tinfo.num_lines, plural); |
---|
312 | else |
---|
313 | (void) sprintf (line, "[%04d]%c %s %s %s (%d line%s)\n", |
---|
314 | tinfo.current, |
---|
315 | tinfo.flags & TRN_FLAG1 ? 'F' : ' ', |
---|
316 | tinfo.author, mtg_name, |
---|
317 | short_time (&tinfo.date_entered), |
---|
318 | tinfo.num_lines, plural); |
---|
319 | twrite (tf, line, strlen (line), &code); |
---|
320 | if (tinfo.subject [0] != '\0') { |
---|
321 | twrite (tf, "Subject: ", 9, &code); |
---|
322 | twrite (tf, tinfo.subject, strlen (tinfo.subject), &code); |
---|
323 | twrite (tf, "\n", 1, &code); |
---|
324 | } |
---|
325 | |
---|
326 | dsc_get_trn(&nb, trn_num, tf, &code); |
---|
327 | if (code != 0) { |
---|
328 | printf(";%s\n", error_message(code)); |
---|
329 | dsc_destroy_name_blk(&nb); |
---|
330 | return; |
---|
331 | } |
---|
332 | |
---|
333 | if (tinfo.pref == 0 && tinfo.nref == 0) |
---|
334 | (void) sprintf (line, "--[%04d]--\n", tinfo.current); |
---|
335 | else if (tinfo.pref == 0) |
---|
336 | (void) sprintf (line, "--[%04d]-- (nref = [%04d])\n", |
---|
337 | tinfo.current, tinfo.nref); |
---|
338 | else if (tinfo.nref == 0) |
---|
339 | (void) sprintf (line, "--[%04d]-- (pref = [%04d])\n", |
---|
340 | tinfo.current, tinfo.pref); |
---|
341 | else |
---|
342 | (void) sprintf (line, |
---|
343 | "--[%04d]-- (pref = [%04d], nref = [%04d])\n", |
---|
344 | tinfo.current, tinfo.pref, tinfo.nref); |
---|
345 | twrite (tf, line, strlen (line), &code); |
---|
346 | |
---|
347 | tclose(tf, &code); |
---|
348 | (void) close(fd); |
---|
349 | if (code != 0) { |
---|
350 | printf(";%s\n", error_message(code)); |
---|
351 | dsc_destroy_name_blk(&nb); |
---|
352 | return; |
---|
353 | } |
---|
354 | #endif |
---|
355 | |
---|
356 | tinfo.subject = do_quote(tinfo.subject); |
---|
357 | printf("(%d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d)\n", |
---|
358 | tinfo.current, |
---|
359 | tinfo.prev, |
---|
360 | tinfo.next, |
---|
361 | tinfo.pref, |
---|
362 | tinfo.nref, |
---|
363 | tinfo.fref, |
---|
364 | tinfo.lref, |
---|
365 | tinfo.chain_index, |
---|
366 | short_time(&tinfo.date_entered), |
---|
367 | tinfo.num_lines, |
---|
368 | tinfo.num_chars, |
---|
369 | tinfo.subject, |
---|
370 | tinfo.author, |
---|
371 | tinfo.flags); |
---|
372 | |
---|
373 | dsc_destroy_name_blk(&nb); |
---|
374 | #ifndef EDSC_CACHE |
---|
375 | dsc_destroy_trn_info3(&tinfo); |
---|
376 | #endif |
---|
377 | } |
---|
378 | |
---|
379 | #ifdef EDSC_CACHE |
---|
380 | do_gtfc(args) |
---|
381 | char *args; |
---|
382 | { |
---|
383 | char *cp = args, *mtg_name, delim, *trn_string, *dir_string; |
---|
384 | trn_nums trn_num; |
---|
385 | int direction; |
---|
386 | name_blk nb; |
---|
387 | trn_info3 tinfo; |
---|
388 | int code; |
---|
389 | |
---|
390 | /* First get the direction number */ |
---|
391 | if (get_word(&cp, &dir_string, " ", &delim) < 0) { |
---|
392 | printf(";Missing direction number\n"); |
---|
393 | return; |
---|
394 | } |
---|
395 | |
---|
396 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
397 | printf(";Missing trn number\n"); |
---|
398 | return; |
---|
399 | } |
---|
400 | |
---|
401 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
402 | printf(";Missing meeting name\n"); |
---|
403 | return; |
---|
404 | } |
---|
405 | |
---|
406 | trn_num = atoi(trn_string); |
---|
407 | direction = atoi(dir_string); |
---|
408 | |
---|
409 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
410 | if (code != 0) { |
---|
411 | printf(";%s\n", error_message(code)); |
---|
412 | return; |
---|
413 | } |
---|
414 | |
---|
415 | while (!cache_transaction(&nb, trn_num, &cache_current)) |
---|
416 | ; |
---|
417 | if (cache_current->info_code) { |
---|
418 | printf(";%s\n", error_message(cache_current->info_code)); |
---|
419 | dsc_destroy_name_blk(&nb); |
---|
420 | return; |
---|
421 | } |
---|
422 | if (cache_current->text_code) { |
---|
423 | printf(";%s\n", error_message(cache_current->text_code)); |
---|
424 | dsc_destroy_name_blk(&nb); |
---|
425 | return; |
---|
426 | } |
---|
427 | cache_pc = 0; |
---|
428 | cache_working = 1; |
---|
429 | tinfo = cache_current->t_info; |
---|
430 | |
---|
431 | tinfo.subject = do_quote(tinfo.subject); |
---|
432 | printf("(\"%s\" %d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d)\n", |
---|
433 | cache_current->filename, |
---|
434 | tinfo.current, |
---|
435 | tinfo.prev, |
---|
436 | tinfo.next, |
---|
437 | tinfo.pref, |
---|
438 | tinfo.nref, |
---|
439 | tinfo.fref, |
---|
440 | tinfo.lref, |
---|
441 | tinfo.chain_index, |
---|
442 | short_time(&tinfo.date_entered), |
---|
443 | tinfo.num_lines, |
---|
444 | tinfo.num_chars, |
---|
445 | tinfo.subject, |
---|
446 | tinfo.author, |
---|
447 | tinfo.flags); |
---|
448 | |
---|
449 | dsc_destroy_name_blk(&nb); |
---|
450 | if (direction > 0 && direction <= 4) |
---|
451 | cache_current_direction = direction; |
---|
452 | } |
---|
453 | #endif /* EDSC_CACHE */ |
---|
454 | |
---|
455 | do_grt(args) |
---|
456 | char *args; |
---|
457 | { |
---|
458 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
459 | trn_nums trn_num; |
---|
460 | name_blk nb; |
---|
461 | trn_info tinfo; |
---|
462 | tfile tf; |
---|
463 | int code; |
---|
464 | |
---|
465 | /* First, we get the transaction number */ |
---|
466 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
467 | printf(";Missing trn number\n"); |
---|
468 | return; |
---|
469 | } |
---|
470 | |
---|
471 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
472 | printf(";Missing meeting name\n"); |
---|
473 | return; |
---|
474 | } |
---|
475 | |
---|
476 | trn_num = atoi(trn_string); |
---|
477 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
478 | if (code != 0) { |
---|
479 | printf(";%s\n", error_message(code)); |
---|
480 | return; |
---|
481 | } |
---|
482 | |
---|
483 | dsc_get_trn_info(&nb,trn_num,&tinfo,&code); |
---|
484 | if (code != 0) { |
---|
485 | printf(";%s\n", error_message(code)); |
---|
486 | dsc_destroy_name_blk(&nb); |
---|
487 | return; |
---|
488 | } |
---|
489 | |
---|
490 | printf("(%d)\n", |
---|
491 | tinfo.num_chars); |
---|
492 | |
---|
493 | tf = stdout_tf; |
---|
494 | dsc_get_trn(&nb, trn_num, tf, &code); |
---|
495 | |
---|
496 | dsc_destroy_name_blk(&nb); |
---|
497 | dsc_destroy_trn_info3(&tinfo); |
---|
498 | } |
---|
499 | |
---|
500 | do_at(args) |
---|
501 | char *args; |
---|
502 | { |
---|
503 | char *cp = args, *mtg_name, *file_name, delim, *trn_string; |
---|
504 | trn_nums trn_num,new_trn_num; |
---|
505 | name_blk nb; |
---|
506 | char subject[1000]; |
---|
507 | tfile tf; |
---|
508 | int fd, code; |
---|
509 | |
---|
510 | /* First, we get the transaction number */ |
---|
511 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
512 | printf(";Missing trn number\n"); |
---|
513 | return; |
---|
514 | } |
---|
515 | |
---|
516 | if (get_word(&cp, &file_name, " ", &delim) < 0) { |
---|
517 | printf(";Missing file name\n"); |
---|
518 | return; |
---|
519 | } |
---|
520 | |
---|
521 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
522 | printf(";Missing meeting name\n"); |
---|
523 | return; |
---|
524 | } |
---|
525 | |
---|
526 | trn_num = atoi(trn_string); |
---|
527 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
528 | if (code != 0) { |
---|
529 | printf(";%s\n", error_message(code)); |
---|
530 | return; |
---|
531 | } |
---|
532 | |
---|
533 | /* Read the subject */ |
---|
534 | if (gets(subject) == NULL) { |
---|
535 | printf(";End of file\n"); |
---|
536 | exit(1); |
---|
537 | } |
---|
538 | |
---|
539 | fd = open(file_name, O_RDONLY, 0); |
---|
540 | if (fd < 0) { |
---|
541 | printf(";Can't read transaction. %s\n", error_message(errno)); |
---|
542 | goto punt; |
---|
543 | } |
---|
544 | |
---|
545 | tf = unix_tfile(fd); |
---|
546 | dsc_add_trn(&nb, tf, subject, trn_num, &new_trn_num, &code); |
---|
547 | if (code != 0) { |
---|
548 | printf(";%s\n", error_message(code)); |
---|
549 | } else { |
---|
550 | printf("(%d)\n", new_trn_num); |
---|
551 | } |
---|
552 | |
---|
553 | close(fd); |
---|
554 | #ifdef EDSC_CACHE |
---|
555 | cache_itn(&nb, new_trn_num); |
---|
556 | #endif |
---|
557 | punt: |
---|
558 | dsc_destroy_name_blk(&nb); |
---|
559 | } |
---|
560 | |
---|
561 | do_nut(args) |
---|
562 | char *args; |
---|
563 | { |
---|
564 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
565 | trn_nums trn_num,cur_trn; |
---|
566 | name_blk nb; |
---|
567 | mtg_info m_info; |
---|
568 | trn_info t_info; |
---|
569 | int code,i; |
---|
570 | |
---|
571 | /* First, we get the transaction number */ |
---|
572 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
573 | printf(";Missing trn number\n"); |
---|
574 | return; |
---|
575 | } |
---|
576 | |
---|
577 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
578 | printf(";Missing meeting name\n"); |
---|
579 | return; |
---|
580 | } |
---|
581 | |
---|
582 | trn_num = atoi(trn_string); |
---|
583 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
584 | if (code != 0) { |
---|
585 | printf(";%s\n", error_message(code)); |
---|
586 | return; |
---|
587 | } |
---|
588 | |
---|
589 | dsc_get_mtg_info (&nb, &m_info, &code); |
---|
590 | if (code != 0) { |
---|
591 | printf(";%s\n", error_message(code)); |
---|
592 | return; |
---|
593 | } |
---|
594 | |
---|
595 | if (trn_num < m_info.first) { |
---|
596 | printf("(%d)\n", m_info.first); |
---|
597 | goto done2; |
---|
598 | } |
---|
599 | if (trn_num > m_info.last) { |
---|
600 | printf("(0)\n"); |
---|
601 | goto done2; |
---|
602 | } |
---|
603 | |
---|
604 | /* Now we try to find the next transaction. If the transaction |
---|
605 | is not deleted, we can do this in one step */ |
---|
606 | dsc_get_trn_info(&nb,trn_num,&t_info,&code); |
---|
607 | if (code == 0) { |
---|
608 | printf("(%d)\n", t_info.next); |
---|
609 | goto done; |
---|
610 | } |
---|
611 | |
---|
612 | /* Hmm. Deleted transaction. Try the next five transactions, hoping |
---|
613 | to get a non-deleted one */ |
---|
614 | for (i = 1; i <= 5; i++) { |
---|
615 | dsc_get_trn_info(&nb,trn_num+i,&t_info,&code); |
---|
616 | if (code == 0) { |
---|
617 | printf("(%d)\n", t_info.current); |
---|
618 | goto done; |
---|
619 | } |
---|
620 | } |
---|
621 | |
---|
622 | /* Hmmm. Try the first 5 transactions in the meeting, in case we |
---|
623 | hit a big gap after transaction [0001]. */ |
---|
624 | cur_trn = m_info.first; |
---|
625 | for (i = 0; i < 5; i++) { |
---|
626 | dsc_get_trn_info(&nb, cur_trn, &t_info, &code); |
---|
627 | if (code != 0) { |
---|
628 | printf(";%s\n", error_message(code)); |
---|
629 | goto done2; |
---|
630 | } |
---|
631 | if (t_info.next > trn_num) { |
---|
632 | printf("(%d)\n", t_info.next); |
---|
633 | goto done; |
---|
634 | } |
---|
635 | cur_trn = t_info.next; |
---|
636 | dsc_destroy_trn_info(&t_info); |
---|
637 | } |
---|
638 | |
---|
639 | /* Ok. We bite the bullet and loop until we can find something. */ |
---|
640 | code = DELETED_TRN; |
---|
641 | trn_num += 6; |
---|
642 | while (code == DELETED_TRN) { |
---|
643 | dsc_get_trn_info (&nb, trn_num, &t_info, &code); |
---|
644 | if (code == 0) { |
---|
645 | printf("(%d)\n", trn_num); |
---|
646 | goto done; |
---|
647 | } else if (code == DELETED_TRN) |
---|
648 | trn_num++; |
---|
649 | else { |
---|
650 | printf(";%s\n", error_message(code)); |
---|
651 | goto done2; |
---|
652 | } |
---|
653 | } |
---|
654 | |
---|
655 | done: |
---|
656 | dsc_destroy_trn_info(&t_info); |
---|
657 | done2: |
---|
658 | dsc_destroy_name_blk(&nb); |
---|
659 | dsc_destroy_mtg_info(&m_info); |
---|
660 | } |
---|
661 | |
---|
662 | do_grtn(args) |
---|
663 | char *args; |
---|
664 | { |
---|
665 | char *cp = args, *mtg_name, delim; |
---|
666 | name_blk nb; |
---|
667 | mtg_info m_info; |
---|
668 | trn_info3 t_info; |
---|
669 | int code, rnd_num, i; |
---|
670 | int randrp_retry = 15; |
---|
671 | struct timeval tv; |
---|
672 | int pid = getpid(); |
---|
673 | int active_transactions, rnd_trn; |
---|
674 | |
---|
675 | /* First, we get the meeting name */ |
---|
676 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
677 | printf(";Missing meeting name\n"); |
---|
678 | return; |
---|
679 | } |
---|
680 | |
---|
681 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
682 | if (code != 0) { |
---|
683 | printf(";%s\n", error_message(code)); |
---|
684 | return; |
---|
685 | } |
---|
686 | |
---|
687 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
688 | if (code != 0) { |
---|
689 | printf(";%s\n", error_message(code)); |
---|
690 | dsc_destroy_name_blk(&nb); |
---|
691 | return; |
---|
692 | } |
---|
693 | |
---|
694 | gettimeofday(&tv, (struct timezone *) NULL); |
---|
695 | srandom(tv.tv_sec ^ tv.tv_usec ^ pid); |
---|
696 | |
---|
697 | for (i=1;i<=randrp_retry;i++) { |
---|
698 | do { |
---|
699 | rnd_num = random(); |
---|
700 | active_transactions = (m_info.last - m_info.first); |
---|
701 | if (active_transactions != 0) { |
---|
702 | rnd_trn = (m_info.first + |
---|
703 | (rnd_num % active_transactions)); |
---|
704 | } else { |
---|
705 | rnd_trn = m_info.first; |
---|
706 | } |
---|
707 | dsc_get_trn_info3(&nb, rnd_trn, &t_info, &code); |
---|
708 | } while (code != 0); |
---|
709 | if (!t_info.pref) break; |
---|
710 | } |
---|
711 | |
---|
712 | t_info.subject = do_quote(t_info.subject); |
---|
713 | printf("(%d %d %d %d %d %d %d %d \"%s\" %d %d \"%s\" \"%s\" %d \"%s\")\n", |
---|
714 | t_info.current, |
---|
715 | t_info.prev, |
---|
716 | t_info.next, |
---|
717 | t_info.pref, |
---|
718 | t_info.nref, |
---|
719 | t_info.fref, |
---|
720 | t_info.lref, |
---|
721 | t_info.chain_index, |
---|
722 | short_time(&t_info.date_entered), |
---|
723 | t_info.num_lines, |
---|
724 | t_info.num_chars, |
---|
725 | t_info.subject, |
---|
726 | t_info.author, |
---|
727 | t_info.flags, |
---|
728 | t_info.signature ? t_info.signature : ""); |
---|
729 | |
---|
730 | dsc_destroy_name_blk(&nb); |
---|
731 | dsc_destroy_mtg_info(&m_info); |
---|
732 | } |
---|
733 | |
---|
734 | do_sfl(args) |
---|
735 | char *args; |
---|
736 | { |
---|
737 | char *cp = args, *mtg_name, delim, *trn_string, *flags_string; |
---|
738 | trn_nums trn_num; |
---|
739 | int flags; |
---|
740 | name_blk nb; |
---|
741 | int code; |
---|
742 | |
---|
743 | /* First, we get flag we should be setting */ |
---|
744 | if (get_word(&cp, &flags_string, " ", &delim) < 0) { |
---|
745 | printf(";Missing flags entry\n"); |
---|
746 | return; |
---|
747 | } |
---|
748 | |
---|
749 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
750 | printf(";Missing trn number\n"); |
---|
751 | return; |
---|
752 | } |
---|
753 | |
---|
754 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
755 | printf(";Missing meeting name\n"); |
---|
756 | return; |
---|
757 | } |
---|
758 | trn_num = atoi(trn_string); |
---|
759 | flags = atoi(flags_string); |
---|
760 | |
---|
761 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
762 | if (code != 0) { |
---|
763 | printf(";%s\n", error_message(code)); |
---|
764 | return; |
---|
765 | } |
---|
766 | |
---|
767 | dsc_set_trn_flags(&nb, trn_num, flags, &code); |
---|
768 | |
---|
769 | #ifdef EDSC_CACHE |
---|
770 | cache_it(&nb, trn_num); |
---|
771 | #endif |
---|
772 | |
---|
773 | dsc_destroy_name_blk(&nb); |
---|
774 | |
---|
775 | if (code != 0) { |
---|
776 | printf(";%s\n", error_message(code)); |
---|
777 | return; |
---|
778 | } |
---|
779 | |
---|
780 | printf("()\n"); |
---|
781 | } |
---|
782 | |
---|
783 | /* |
---|
784 | * Retrieve transaction |
---|
785 | */ |
---|
786 | do_rt(args) |
---|
787 | char *args; |
---|
788 | { |
---|
789 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
790 | trn_nums trn_num; |
---|
791 | name_blk nb; |
---|
792 | int code; |
---|
793 | |
---|
794 | /* First, we get the transaction number */ |
---|
795 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
796 | printf(";Missing trn number\n"); |
---|
797 | return; |
---|
798 | } |
---|
799 | |
---|
800 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
801 | printf(";Missing meeting name\n"); |
---|
802 | return; |
---|
803 | } |
---|
804 | |
---|
805 | trn_num = atoi(trn_string); |
---|
806 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
807 | if (code != 0) { |
---|
808 | printf(";%s\n", error_message(code)); |
---|
809 | return; |
---|
810 | } |
---|
811 | dsc_retrieve_trn(&nb, trn_num, &code); |
---|
812 | #ifdef EDSC_CACHE |
---|
813 | if (!code) |
---|
814 | cache_itn(&nb, trn_num); |
---|
815 | #endif |
---|
816 | dsc_destroy_name_blk(&nb); |
---|
817 | if (code != 0) { |
---|
818 | printf(";%s\n", error_message(code)); |
---|
819 | return; |
---|
820 | } |
---|
821 | printf("()\n"); |
---|
822 | |
---|
823 | |
---|
824 | } |
---|
825 | |
---|
826 | /* |
---|
827 | * Delete transaction |
---|
828 | */ |
---|
829 | do_dt(args) |
---|
830 | char *args; |
---|
831 | { |
---|
832 | char *cp = args, *mtg_name, delim, *trn_string; |
---|
833 | trn_nums trn_num; |
---|
834 | name_blk nb; |
---|
835 | int code; |
---|
836 | |
---|
837 | /* First, we get the transaction number */ |
---|
838 | if (get_word(&cp, &trn_string, " ", &delim) < 0) { |
---|
839 | printf(";Missing trn number\n"); |
---|
840 | return; |
---|
841 | } |
---|
842 | |
---|
843 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
844 | printf(";Missing meeting name\n"); |
---|
845 | return; |
---|
846 | } |
---|
847 | |
---|
848 | trn_num = atoi(trn_string); |
---|
849 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
850 | if (code != 0) { |
---|
851 | printf(";%s\n", error_message(code)); |
---|
852 | return; |
---|
853 | } |
---|
854 | |
---|
855 | dsc_delete_trn(&nb, trn_num, &code); |
---|
856 | #ifdef EDSC_CACHE |
---|
857 | if (!code) |
---|
858 | cache_itn(&nb, trn_num); |
---|
859 | #endif |
---|
860 | dsc_destroy_name_blk(&nb); |
---|
861 | if (code != 0) { |
---|
862 | printf(";%s\n", error_message(code)); |
---|
863 | return; |
---|
864 | } |
---|
865 | printf("()\n"); |
---|
866 | |
---|
867 | } |
---|