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