1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #include <stdio.h>
49 #include <mowse.h>
50 #include <bft.h>
51
52 #define CANCEL_SW 0x001
53 #define DISPLAY_SW 0x002
54 #define FETCH_SW 0x004
55 #define LOAD_SW 0x008
56 #define RECOVER_SW 0x010
57 #define STORE_SW 0x020
58 #define UNLOAD_SW 0x040
59
60
61
62 #define NAME "BFT"
63 #define USAGE_CANCEL "\n Usage: bft cancel request_id {request_id ...}\n"
64 #define USAGE_UNLOAD "\n Usage: bft unload\n"
65 #define USAGE_RECOVER "\n Usage: bft unload\n"
66 #define USAGE_BFT "\n Usage: bft KEY {path1 {path2...path1N path2N}} {/Control_args}\n"
67 #define USAGE_FETCH "\n Usage: bft FETCH {path1 {path2...path1N path2N}} {/Control_args}\n"
68 #define USAGE_STORE "\n Usage: bft STORE {path1 {path2...path1N path2N}} {/Control_args}\n"
69 #define USAGE_KEYS "\n (s)tore, (f)etch, (c)ancel, (ls) list, (l)oad, (u)nload, (r)ecover\n"
70
71
72
73 int argp;
74 int argcount;
75 char **argval;
76 char *arg;
77 long flags;
78 int priority;
79 int control_sw;
80
81 char *find_option ();
82 char *stripquote();
83 char *upper();
84 int bft_cancel ();
85 int bft_fetch ();
86 int bft_load ();
87 int bft_display ();
88 int bft_recover ();
89 int bft_store ();
90 int bft_unload ();
91
92
93
94 main (argc, argv)
95
96 int argc;
97 char **argv;
98 {
99 int code;
100 int (*key_procedure)();
101
102
103
104 code = 0;
105 flags = 0;
106 priority = 3;
107 control_sw = 0;
108
109 argcount = argc;
110 argval = argv;
111 flags = 0;
112
113
114
115 if (argcount < 1)
116 {
117 fprintf (stderr, "%s: Wrong number of arguments.\n%s", NAME, USAGE_BFT);
118 return;
119 }
120
121
122
123 argp = 0;
124 if ((code = get_arg (0)) != 0)
125 {
126 bfterror (code, USAGE_BFT, NULL);
127 return;
128 }
129
130
131
132 if (!strcmp (argval[argp],"cancel") || !strcmp (argval[argp],"c"))
133 {
134 control_sw |= CANCEL_SW;
135 key_procedure = bft_cancel;
136 }
137 else if (!strcmp (argval[argp],"fetch") || !strcmp (argval[argp],"f"))
138 {
139 control_sw |= FETCH_SW;
140 key_procedure = bft_fetch;
141 }
142 else if (!strcmp (argval[argp],"load") || !strcmp (argval[argp],"l") || !strcmp (argval[argp],"ld"))
143 {
144 control_sw |= LOAD_SW;
145 key_procedure = bft_load;
146 }
147 else if (!strcmp (argval[argp],"list") || !strcmp (argval[argp],"ls"))
148 {
149 control_sw |= DISPLAY_SW;
150 key_procedure = bft_display;
151 }
152 else if (!strcmp (argval[argp],"recover") || !strcmp (argval[argp],"r"))
153 {
154 control_sw |= RECOVER_SW;
155 key_procedure = bft_recover;
156 }
157 else if (!strcmp (argval[argp],"store") || !strcmp (argval[argp],"s"))
158 {
159 control_sw |= STORE_SW;
160 key_procedure = bft_store;
161 }
162 else if (!strcmp (argval[argp],"unload") || !strcmp (argval[argp],"u") || !strcmp (argval[argp],"uld"))
163 {
164 control_sw |= UNLOAD_SW;
165 key_procedure = bft_unload;
166 }
167 else
168 {
169 fprintf (stderr, "BFT: Keyword not accepted: %s.%s", arg, USAGE_KEYS);
170 return;
171 }
172
173
174
175 if ((code = parse_args ()) != 0)
176 {
177 bfterror (code, USAGE_BFT, NULL);
178 return;
179 }
180
181
182
183 argp = 0;
184 get_arg (0);
185 (*key_procedure) ();
186 }
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 bft_cancel ()
202 {
203 int code;
204 char id[PATHNAMESIZE];
205 int passed;
206 char request_type;
207
208
209 passed = 0;
210
211
212
213 while (argp < argcount - 1)
214 {
215 if (code = get_arg (1))
216 {
217 bfterror (code, arg, NULL);
218 if (passed > 0)
219 printf ("BFT: %d reques%s submitted for cancellation.\n", passed, ((passed == 1) ? "t" : "ts"));
220 return (code);
221 }
222
223
224
225 if (arg[0] != '/')
226 {
227 strncpy (id, arg, PATHNAMESIZE);
228 code = bftcan (BFT_PATH_ID, stripquote (id));
229 }
230 else
231 {
232 request_type = arg[1];
233
234 arg = find_option ();
235 if (arg == NULL)
236 code = BFT_EXPECTING;
237 else
238 {
239 strncpy (id, arg, PATHNAMESIZE);
240
241 if (request_type == 'I')
242 code = bftcan (BFT_TIME_ID, stripquote (id));
243 else if (request_type == 'E')
244 code = bftcan (BFT_ENTRY_ID, stripquote (id));
245 }
246 }
247
248
249
250 if (code != 0)
251 {
252 bfterror (code, "Executing bft cancel.", NULL);
253 if (passed > 0)
254 printf ("BFT: %d reques%s submitted for cancellation.\n", passed, ((passed == 1) ? "t" : "ts"));
255 return (code);
256 }
257 else
258 passed += 1;
259 }
260
261 if (passed > 0)
262 printf ("BFT: %d reques%s submitted for cancellation.\n", passed, ((passed == 1) ? "t" : "ts"));
263
264 return (0);
265 }
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 bft_display ()
281 {
282 fprintf (stderr, "BFT: PC version of BFT does not implement queue list. Use Multics list.\n");
283 }
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 bft_fetch ()
304 {
305 char mu_path[MAXARGSTRING];
306 char pc_path[PATHNAMESIZE];
307 int passed;
308 int code;
309
310 passed = 0;
311
312
313
314 while (argp < argcount - 1)
315 {
316
317
318
319 if (code = get_arg (0))
320 {
321 bfterror (code, USAGE_FETCH, NULL);
322 if (passed > 0)
323 printf ("BFT: %d reques%s submitted for fetching.\n", passed, ((passed == 1) ? "t" : "ts"));
324 return (code);
325 }
326
327 strncpy (mu_path, arg, PATHNAMESIZE);
328 strncpy (pc_path, "===", PATHNAMESIZE);
329
330
331
332 code = get_arg (0);
333 if ((code != 0)&&(code != BFT_NOARG))
334 {
335 bfterror (code, arg, NULL);
336 if (passed > 0)
337 printf ("BFT: %d reques%s submitted for fetching.\n", passed, ((passed == 1) ? "t" : "ts"));
338 return (code);
339 }
340 else if (code == 0)
341 strcpy (pc_path, arg);
342
343
344
345 getpath (pc_path);
346
347 code = bftfetch (stripquote (mu_path), pc_path, flags, priority);
348 if (code != 0)
349 {
350 bfterror (code, pc_path, NULL);
351 if (passed > 0)
352 printf ("BFT: %d reques%s submitted for fetching.\n", passed, ((passed == 1) ? "t" : "ts"));
353 return (code);
354 }
355 else
356 passed += 1;
357 }
358
359
360 if (passed > 0)
361 printf ("BFT: %d reques%s submitted for fetching.\n", passed, ((passed == 1) ? "t" : "ts"));
362
363 return (0);
364 }
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381 bft_load ()
382 {
383
384
385
386 printf ("BFT: load is not implemented. Use bft_load.\n");
387 }
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404 bft_recover ()
405 {
406 int code;
407
408
409
410 if ((code = bftrecfe ()) != 0)
411 return (bfterror (code, "Recovering fetch requests.", NULL));
412
413
414
415 if ((code = bftrecst ()) != 0)
416 return (bfterror (code, "Recovering store requests.", NULL));
417 }
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437 bft_store ()
438 {
439 char mu_path[MAXARGSTRING];
440 char pc_path[PATHNAMESIZE];
441 int passed;
442 int code;
443
444
445 passed = 0;
446
447
448
449 while (argp < argcount - 1)
450 {
451
452
453
454 if ((code = get_arg (0)) != 0)
455 {
456 bfterror (code, USAGE_STORE, NULL);
457 if (passed > 0)
458 printf ("BFT: %d reques%s submitted for storing.\n", passed, ((passed == 1) ? "t" : "ts"));
459 return (code);
460 }
461
462 strncpy (pc_path, arg, PATHNAMESIZE);
463 strncpy (mu_path, "===", PATHNAMESIZE);
464
465
466
467 code = get_arg (0);
468 if ((code != 0)&&(code != BFT_NOARG))
469 {
470 bfterror (code, arg, NULL);
471 if (passed > 0)
472 printf ("BFT: %d reques%s submitted for storing.\n", passed, ((passed == 1) ? "t" : "ts"));
473 return (code);
474 }
475 else if (code == 0)
476 strcpy (mu_path, arg);
477
478
479
480 getpath (pc_path);
481
482 code = bftstore (pc_path, stripquote (mu_path), flags, priority);
483 if (code != 0)
484 {
485 bfterror (code, pc_path, NULL);
486 if (passed > 0)
487 printf ("BFT: %d reques%s submitted for storing.\n", passed, ((passed == 1) ? "t" : "ts"));
488 return (code);
489 }
490 else
491 passed += 1;
492 }
493
494 if (passed > 0)
495 printf ("BFT: %d reques%s submitted for storing.\n", passed, ((passed == 1) ? "t" : "ts"));
496
497 return (0);
498 }
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514 bft_unload ()
515 {
516 int code;
517
518
519
520
521 if ((code = bftunld ()) != 0)
522 return (bfterror (code, "Unloading.", NULL));
523 }
524
525
526
527
528
529
530
531
532
533
534
535
536
537 char *find_option ()
538 {
539
540 if (arg[2] != 0)
541 return (&(arg[2]));
542
543 argp += 1;
544 arg = argval[argp];
545
546 if (arg[0] == '/')
547 return (NULL);
548 else if (argp < argcount)
549 return (arg);
550 else
551 return (NULL);
552 }
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567 get_arg (special)
568
569 int special;
570 {
571 int queue;
572 int code;
573
574
575
576
577 while (1)
578 {
579 argp += 1;
580
581 if (argp >= argcount)
582 return (BFT_NOARG);
583
584
585
586 arg = argval[argp];
587 if (arg[0] != '/')
588 return (0);
589
590
591
592 switch (toupper (arg[1]))
593 {
594 case 'E':
595 case 'I':
596 if (special)
597 return (0);
598 else
599 find_option ();
600 break;
601
602 case 'N':
603 case 'F':
604 case 'Q':
605 find_option ();
606 break;
607
608 default:
609 break;
610 }
611 }
612 }
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636 parse_args ()
637
638 {
639 int code;
640 int queue;
641
642 code = 0;
643
644 for (argp = 1; argp < argcount; argp++)
645 {
646 arg = argval[argp];
647
648 if (arg[0] == '/')
649 {
650 switch (toupper (arg[1]))
651 {
652 case 'F':
653 if (!(control_sw & STORE_SW || control_sw & FETCH_SW))
654 code = BFT_INCOMPATIBLE;
655 else if ((arg = find_option ()) == NULL)
656 code = BFT_EXPECTING;
657 else if (!strcmp (upper (arg), "ASCII"))
658 flags &= ~BFT_BINARY;
659 else if (!strcmp (upper (arg), "BINARY"))
660 flags |= BFT_BINARY;
661 else
662 code = BFT_BADOPT;
663 break;
664
665 case 'N':
666 if (!(control_sw & STORE_SW || control_sw & FETCH_SW))
667 code = BFT_INCOMPATIBLE;
668 else if ((arg = find_option ()) == NULL)
669 code = BFT_EXPECTING;
670 else if (!strcmp (upper (arg), "OFF"))
671 flags &= ~BFT_NOTIFY;
672 else if (!strcmp (upper (arg), "ON"))
673 flags |= BFT_NOTIFY;
674 else
675 code = BFT_BADOPT;
676 break;
677
678 case 'Q':
679 if (!(control_sw & STORE_SW || control_sw & FETCH_SW))
680 code = BFT_INCOMPATIBLE;
681 else if ((arg = find_option ()) == NULL)
682 code = BFT_EXPECTING;
683 else if (strlen (arg) != 1)
684 code = BFT_BADOPT;
685 else if (!isdigit (arg[0]))
686 code = BFT_BADOPT;
687 else
688 {
689 queue = (int) (arg[0] - '0');
690 if ((queue < BFT_MIN_PRIORITY) || (queue > BFT_MAX_PRIORITY))
691 code = BFT_INVALID_PRIORITY;
692 else
693 priority = queue;
694 }
695 break;
696
697 case 'I':
698 if (!(control_sw & CANCEL_SW))
699 code = BFT_INCOMPATIBLE;
700 break;
701
702 case 'E':
703 if (!(control_sw & CANCEL_SW))
704 code = BFT_INCOMPATIBLE;
705 break;
706
707 default:
708 code = BFT_BADARG;
709 break;
710 }
711
712 if (code != 0)
713 return (code);
714 }
715 }
716
717 return (0);
718 }
719
720
721
722
723
724
725
726
727
728
729
730 char *upper (str)
731
732 char *str;
733 {
734 int i;
735
736 for (i = 0; str[i]; i++)
737 str[i] = toupper (str[i]);
738
739 return (str);
740 }