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 #include <stdio.h>
37 #include <fcntl.h>
38 #include <dos.h>
39 #include <mowse.h>
40 #include <bft.h>
41
42 #define SEEK_START 0
43 #define SEEK_CURRENT 1
44 #define SEEK_EOF 2
45
46 #define DOS_STAR_FIRST 0x4E
47 #define DOS_STAR_NEXT 0x4F
48 #define DOS_SET_DTA 0x1A
49
50 #define MAXLONG 0x7FFFFFFF
51
52 int _stack = STACKSIZE;
53
54 struct dta_struct
55 {
56 char filler[30];
57 char name[13];
58 } dta;
59
60 long lseek ();
61 char *stptok();
62 char *striptok();
63 int bftmajcap();
64
65
66
67
68
69
70
71
72
73
74
75
76
77 main (argc)
78
79 int argc;
80 {
81 int majnum;
82 int majnumr;
83 int com_id;
84 int code;
85 mcb *mcb_ptr;
86 bft_data_ptr data_ptr;
87
88
89
90
91 if (argc > 1)
92 {
93 printf ("BFT: Unexpected argument.\n Usage: bft_load\n");
94 return;
95 }
96
97
98
99 majnum = 0;
100 if (findnumb ("BFT", WSLOCAL, &majnum) == 0)
101 {
102 fprintf (stderr, "BFT: Already loaded.\n");
103 return;
104 }
105
106
107
108 data_ptr = (bft_data_ptr) malloc (sizeof (bft_data));
109 if (data_ptr == NULL)
110 {
111 fprintf (stderr, "BFT: Memory allocation error.\n");
112 return;
113 }
114
115
116
117 data_ptr->source_file[0] = 0;
118 data_ptr->source_flags = 0L;
119 data_ptr->destination_file[0] = 0;
120 data_ptr->destination_flags = 0L;
121 data_ptr->inbuffpos = 0;
122 data_ptr->outbuffpos = 0;
123 data_ptr->inpos = 0L;
124 data_ptr->outpos = 0L;
125 data_ptr->inbufflen = 0;
126 data_ptr->inbuffer[0] = '\0';
127 data_ptr->outbuffer[0] = '\0';
128 data_ptr->expand_dirname[0] = '\0';
129
130
131
132 if ((code = cretinst("BFT", bftmajcap, MAXARGSTRING, MAXARGSTRING, data_ptr, &mcb_ptr)) != 0)
133 {
134 free (data_ptr);
135 return (bfterror (code, "Loading BFT.", NULL));
136 }
137
138
139
140 majnumr = 0;
141 if (findnumb ("bft_main_", WSREMOTE, &majnumr) != 0)
142 {
143 if ((code = execom ("bft_main_", WSREMOTE, &com_id, mcb_ptr)) != 0)
144 {
145 destinst (&mcb_ptr);
146 free (data_ptr);
147 bfterror (code, "Loading remote bft_main_.", NULL);
148 return;
149 }
150 }
151
152
153
154 stayres (mcb_ptr);
155 }
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 bftmajcap (minum, sender, arg_string, arg_len, data_ptr, mcb_ptr)
174
175 int minum;
176 int sender;
177 int arg_len;
178 char *arg_string;
179 bft_data_ptr *data_ptr;
180 mcb *mcb_ptr;
181 {
182 char temp_str[MAXARGSTRING];
183
184
185
186
187 switch(minum)
188 {
189 case(BFT_SHUT_DOWN):
190 bft_shut_down(mcb_ptr);
191 break;
192
193 case(CHECK_FILE_LENGTH):
194 check_length(arg_string,arg_len,mcb_ptr,data_ptr);
195 break;
196
197 case(EXPAND_PC_PATH):
198 expand_pc_path(arg_string,arg_len,mcb_ptr,data_ptr);
199 break;
200
201 case(INITIATE_FETCH):
202 init_fetch (arg_string, arg_len, mcb_ptr, data_ptr);
203 break;
204
205 case(INITIATE_STORE):
206 init_store (arg_string, arg_len, mcb_ptr, data_ptr);
207 break;
208
209 case(POSITION_FILE_POINTER):
210 position_pointer (arg_string, arg_len, mcb_ptr, data_ptr);
211 break;
212
213 case(READ_ERROR):
214 read_err (arg_string, arg_len, mcb_ptr, data_ptr);
215 break;
216
217 case(REC_DATA):
218 rec_data(arg_string,arg_len,mcb_ptr,data_ptr);
219 break;
220
221 case(REC_EOF):
222 receive_eof(arg_string,arg_len,mcb_ptr,data_ptr);
223 break;
224
225 case(SEND_DATA):
226 send_data(arg_string,arg_len,mcb_ptr,data_ptr);
227 break;
228
229 case(SYSTEM_ERROR):
230 system_shutdown();
231 break;
232
233 case(WRITE_ERROR):
234 write_err (arg_string, arg_len, mcb_ptr, data_ptr);
235 break;
236
237 case(MESSAGE_TOO_LONG):
238 bfterror (BFT_INVALID_MINOR, "message_too_long", mcb_ptr);
239 system_shutdown();
240 break;
241
242 case(EXECUTE_COMMAND_REPLY):
243 execute_command_reply(arg_string,arg_len,mcb_ptr,data_ptr);
244 break;
245
246 case(FAIL_CAPABILITY):
247 bfterror (BFT_INVALID_MINOR, "fail_capability", mcb_ptr);
248 system_shutdown();
249 break;
250
251 case(GET_STATUS):
252 bfterror (BFT_INVALID_MINOR, "get_status", mcb_ptr);
253 system_shutdown();
254 break;
255
256 case(QUERY_REPLY):
257 bfterror (BFT_INVALID_MINOR, "query_reply", mcb_ptr);
258 system_shutdown();
259 break;
260
261 case(RESET_APPLICATION):
262 bfterror (BFT_INVALID_MINOR, "reset_application", mcb_ptr);
263 system_shutdown();
264 break;
265
266 case(RESUME_APPLICATION):
267 bfterror (BFT_INVALID_MINOR, "resume_application", mcb_ptr);
268 system_shutdown();
269 break;
270
271 case(RESPONSE_CONNECT):
272 bfterror (BFT_INVALID_MINOR, "response_connect", mcb_ptr);
273 system_shutdown();
274 break;
275
276 case(RESPONSE_DISCONNECT):
277 disconnect_response(mcb_ptr);
278 break;
279
280 case(REQUEST_CONNECT):
281 bfterror (BFT_INVALID_MINOR, "request_connect", mcb_ptr);
282 system_shutdown();
283 break;
284
285 case(REQUEST_DISCONNECT):
286 disconnect_request(mcb_ptr,sender);
287 break;
288
289 case(SUSPEND_APPLICATION):
290 bfterror (BFT_INVALID_MINOR, "suspend_application", mcb_ptr);
291 system_shutdown();
292 break;
293
294 case(TERMINATE_APPLICATION):
295 putbgmes(mcb_ptr,0,"BFT","BFT terminating.");
296 destinst(&mcb_ptr);
297 break;
298
299 case(WAKE_UP):
300 bfterror (BFT_INVALID_MINOR, "wake_up", mcb_ptr);
301 system_shutdown();
302 break;
303
304 default:
305 sprintf (temp_str, "%d", minum);
306 bfterror (BFT_INVALID_MINOR, temp_str, mcb_ptr);
307 system_shutdown();
308 break;
309 }
310 }
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330 bft_shut_down(mcb_ptr)
331
332 mcb *mcb_ptr;
333 {
334 int majnum;
335
336
337
338
339 putbgmes (mcb_ptr, 0, "BFT", "BFT is shutting down.");
340
341
342
343 majnum = 0;
344 if (findnumb("bft_main_",WSREMOTE,&majnum) != 0)
345 {
346 putbgmes (mcb_ptr, 0, "BFT", "BFT major capability not found. BFT aborted.");
347 return(0);
348 }
349
350 disrqst (majnum, mcb_ptr);
351 }
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373 check_length (p_arg_string, p_arg_len, p_mcb_ptr, p_data_ptr)
374
375 int p_arg_len;
376 char *p_arg_string;
377 mcb *p_mcb_ptr;
378 bft_data_ptr p_data_ptr;
379 {
380 char token[MAXARGSTRING];
381 char *arg_pos;
382 int fp_dest;
383 char message[MAXARGSTRING];
384 int message_len;
385 char temp_str[MAXARGSTRING];
386 int buff_pos;
387 int buff_len;
388 int line_cnt;
389 int open_mode;
390
391
392
393
394 arg_pos = p_arg_string;
395 arg_pos = striptok (arg_pos, p_data_ptr->destination_file);
396 arg_pos = striptok (arg_pos, token);
397 char2long (token, &p_data_ptr->destination_flags);
398
399
400
401 open_mode = O_RDONLY;
402 if (p_data_ptr->destination_flags & BFT_BINARY)
403 open_mode |= O_RAW;
404
405 if ((fp_dest = open (p_data_ptr->destination_file, open_mode)) == -1)
406 {
407 sprintf (temp_str, "%s opening %s.", getsyserr (errno), p_data_ptr->destination_file);
408 message[0] = 0;
409 message_len = 0;
410 message_len = addtoken (message, message_len, temp_str, 0);
411 executeb (WRITE_ERROR, message, message_len, p_mcb_ptr);
412 return;
413 }
414
415
416
417 if (p_data_ptr->destination_flags & BFT_BINARY)
418 sprintf (temp_str, "%ld", lseek (fp_dest, 0L, SEEK_EOF));
419 else
420 {
421 p_data_ptr->outpos = 0;
422 if ((line_cnt = count_lines (fp_dest, p_data_ptr->outbuffer, &p_data_ptr->outpos, &buff_len, &buff_pos)) == -1)
423 {
424 sprintf (temp_str, "%s line counting %s.", getsyserr (errno), p_data_ptr->destination_file);
425 message[0] = 0;
426 message_len = 0;
427 message_len = addtoken (message, message_len, temp_str, 0);
428 executeb (WRITE_ERROR, message, message_len, p_mcb_ptr);
429 close (fp_dest);
430 return;
431 }
432 sprintf (temp_str, "%d", line_cnt);
433
434
435
436 p_data_ptr->outpos -= (buff_len - buff_pos);
437 }
438 close(fp_dest);
439
440
441
442 p_data_ptr->outbuffpos = 0;
443
444
445
446 message_len = 0;
447 message[0] = 0;
448 message_len = addtoken (message, message_len, temp_str, 0);
449
450 executeb (POSITION_FILE_POINTER, message, message_len, p_mcb_ptr);
451 }
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 count_lines (fp, buff, file_pos, buff_len, buff_pos)
472
473 int fp;
474 char *buff;
475 long *file_pos;
476 int *buff_len;
477 int *buff_pos;
478 {
479 long line_cnt;
480 int last_eol;
481 int status;
482 long max_count;
483 int i;
484
485
486
487
488 max_count = (*file_pos == 0) ? MAXLONG : *file_pos;
489
490 line_cnt = 0;
491 while (line_cnt < max_count)
492 {
493 if ((status = read (fp, buff, DISKBUFF)) <= 0)
494 {
495 if (*file_pos != 0)
496 return (-1);
497 else
498 {
499 *file_pos = lseek (fp, 0L, SEEK_CURRENT);
500 return ((int)line_cnt);
501 }
502 }
503
504
505
506 for (i = 0, last_eol = 0; (i < status) && (line_cnt < max_count); i++)
507 {
508 if (buff[i] == LF)
509 {
510 line_cnt += 1;
511 last_eol = i+1;
512 }
513 }
514
515
516
517 *buff_len = status;
518 *buff_pos = last_eol;
519 }
520
521
522
523 *file_pos = lseek (fp, 0L, SEEK_CURRENT);
524 return ((int)line_cnt);
525 }
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547 expand_pc_path (arg_string, arg_len, mcb_ptr, data_ptr)
548
549 int arg_len;
550 char *arg_string;
551 mcb *mcb_ptr;
552 bft_data_ptr data_ptr;
553 {
554 char path[PATHNAMESIZE];
555 char *arg_pos;
556 char message[MAXARGSTRING];
557 int message_len;
558 char request_id[2];
559 char entryname[ENTRYNAMESIZE];
560 char direction[2];
561 char locator[2];
562 int code;
563
564
565
566
567 arg_pos = arg_string;
568 arg_pos = striptok (arg_pos, locator);
569 arg_pos = striptok (arg_pos, path);
570 arg_pos = striptok (arg_pos, request_id);
571 arg_pos = striptok (arg_pos, direction);
572
573
574
575 set_dta (&dta);
576
577 if (locator[0] == BFT_FIRST)
578 {
579 getpath (path);
580 expand_path (path, data_ptr->expand_dirname, entryname);
581 sprintf (path, "%s\\%s", data_ptr->expand_dirname, entryname);
582 code = 1;
583
584 if (stpbrk (path, "*?") != NULL)
585 {
586 code = findfirst (path);
587 sprintf (path, "%s\\%s", data_ptr->expand_dirname, dta.name);
588 }
589 }
590 else
591 {
592 code = findnext ();
593 sprintf (path, "%s\\%s", data_ptr->expand_dirname, dta.name);
594 }
595
596 if (code == 0)
597 path[0] = '\0';
598
599
600
601 message[0] = 0;
602 message_len = 0;
603 message_len = addtoken (message, message_len, path, strlen (path));
604 message_len = addtoken (message, message_len, request_id, 0);
605 message_len = addtoken (message, message_len, direction, 1);
606 executeb (FULL_PC_PATH, message, message_len, mcb_ptr);
607
608 return;
609 }
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628 init_fetch (arg_string, arg_len, mcb_ptr, data_ptr)
629
630 int arg_len;
631 char *arg_string;
632 mcb *mcb_ptr;
633 bft_data_ptr data_ptr;
634 {
635 char *arg_pos;
636 char token [MAXARGSTRING];
637 char out_str [MAXARGSTRING];
638 int out_len;
639 char temp_str [MAXARGSTRING];
640 int temp_len;
641 int fp_source;
642
643
644
645
646 arg_pos = arg_string;
647 arg_pos = striptok (arg_pos, data_ptr->source_file);
648 arg_pos = striptok (arg_pos, token);
649 char2long (token, &data_ptr->source_flags);
650
651
652
653 fp_source = open (data_ptr->source_file, O_RDONLY | O_RAW);
654 if (fp_source == -1)
655 {
656 sprintf (out_str, "%s opening %s.", getsyserr (errno), data_ptr->source_file);
657 temp_str[0]=0;
658 temp_len = 0;
659 temp_len = addtoken (temp_str, temp_len, out_str, 0);
660 data_ptr->source_file[0]=0;
661 executeb (READ_ERROR, temp_str, temp_len, mcb_ptr);
662 return;
663 }
664
665
666
667 data_ptr->inbuffpos = 0;
668 data_ptr->inpos = 0L;
669 close(fp_source);
670
671
672
673 out_str[0] = 0;
674 out_len = 0;
675 bftmajcap (SEND_DATA, 0, out_str, out_len, data_ptr, mcb_ptr);
676 return;
677 }
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697 init_store (arg_string, arg_len, mcb_ptr, data_ptr)
698
699 int arg_len;
700 char *arg_string;
701 mcb *mcb_ptr;
702 bft_data_ptr data_ptr;
703 {
704 char *arg_pos;
705 char token [MAXARGSTRING];
706 char temp_str [STRINGSIZE];
707 int temp_len;
708 char out_str [MAXARGSTRING];
709 int out_len;
710 int fp_dest;
711
712
713
714
715 arg_pos = arg_string;
716 arg_pos = striptok (arg_pos, data_ptr->destination_file);
717 arg_pos = striptok (arg_pos, token);
718 char2long (token, &data_ptr->destination_flags);
719
720
721
722 fp_dest = open (data_ptr->destination_file, O_WRONLY | O_RAW | O_CREAT | O_TRUNC);
723 if (fp_dest == -1)
724 {
725 sprintf (out_str, "%s opening %s.", getsyserr (errno), data_ptr->destination_file);
726 temp_str[0]=0;
727 temp_len = 0;
728 temp_len = addtoken (temp_str, temp_len, out_str, 0);
729
730 executeb (WRITE_ERROR, temp_str, temp_len, mcb_ptr);
731 return;
732 }
733
734
735
736 data_ptr->outbuffpos = 0;
737 close (fp_dest);
738
739
740
741 executeb (SEND_DATA, out_str, 0, mcb_ptr);
742 }
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763 position_pointer (arg_string, arg_len, mcb_ptr, data_ptr)
764
765 int arg_len;
766 char *arg_string;
767 mcb *mcb_ptr;
768 bft_data_ptr data_ptr;
769 {
770 char token[MAXARGSTRING];
771 char *arg_pos;
772 char temp_str [STRINGSIZE];
773 char out_str [MAXARGSTRING];
774 int out_len;
775 int fp_source;
776 int line_pos;
777 int i;
778 int open_mode;
779
780
781
782
783 arg_pos = arg_string;
784 arg_pos = striptok (arg_pos, data_ptr->source_file);
785 arg_pos = striptok (arg_pos, token);
786 data_ptr->inpos = (long) atoi (token);
787 arg_pos = striptok (arg_pos, token);
788 char2long (token, &data_ptr->source_flags);
789
790
791
792 open_mode = O_RDONLY;
793 if (data_ptr->source_flags & BFT_BINARY)
794 open_mode |= O_RAW;
795 fp_source = open (data_ptr->source_file, open_mode);
796 if (fp_source == -1)
797 {
798 sprintf (temp_str, "%s opening %s.", getsyserr (errno), data_ptr->source_file);
799 out_str[0]=0;
800 out_len = 0;
801 out_len = addtoken (out_str, out_len, temp_str, 0);
802 executeb (READ_ERROR, out_str, out_len, mcb_ptr);
803 data_ptr->source_file[0]=0;
804 return;
805 }
806
807
808
809 data_ptr->inbufflen = 0;
810 data_ptr->inbuffpos = 0;
811
812
813
814 if (!(data_ptr->source_flags & BFT_BINARY))
815 {
816 if (count_lines (fp_source, data_ptr->inbuffer, &data_ptr->inpos, &data_ptr->inbufflen, &data_ptr->inbuffpos) == -1)
817 {
818 sprintf (temp_str, "%s positioning %s.", getsyserr (errno), data_ptr->source_file);
819 out_str[0]=0;
820 out_len = 0;
821 out_len = addtoken (out_str, out_len, temp_str, 0);
822 executeb (READ_ERROR, out_str, out_len, mcb_ptr);
823 data_ptr->source_file[0]=0;
824 close (fp_source);
825 return;
826 }
827 }
828 close(fp_source);
829
830
831
832 out_str[0] = 0;
833 out_len = 0;
834 bftmajcap (SEND_DATA, 0, out_str, out_len, data_ptr, mcb_ptr);
835 }
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855 rec_data (arg_string, arg_len, mcb_ptr, data_ptr)
856
857 int arg_len;
858 char *arg_string;
859 mcb *mcb_ptr;
860 bft_data_ptr data_ptr;
861 {
862 int i;
863 char out_str [MAXARGSTRING];
864 int out_len;
865 char temp_str [MAXARGSTRING];
866 int temp_len;
867
868
869
870
871 i = put_data (arg_string, arg_len, data_ptr);
872
873
874
875 if (i != arg_len)
876 {
877 sprintf (out_str, "%s writing %s.", getsyserr (errno), data_ptr->destination_file);
878 temp_str[0]=0;
879 temp_len = 0;
880 temp_len = addtoken (temp_str, temp_len, out_str, 0);
881 executeb (WRITE_ERROR, temp_str, temp_len, mcb_ptr);
882 data_ptr->destination_file[0]=0;
883 return;
884 }
885
886
887
888 out_str[0]=0;
889 out_len = 0;
890 executeb (SEND_DATA, out_str, out_len, mcb_ptr);
891 return;
892 }
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910 receive_eof (arg_string, arg_len, mcb_ptr, data_ptr)
911
912 int arg_len;
913 char *arg_string;
914 mcb *mcb_ptr;
915 bft_data_ptr data_ptr;
916 {
917 int fp_dest;
918 int open_mode;
919 int status;
920 char out_str [MAXARGSTRING];
921 int out_len;
922 char temp_str [MAXARGSTRING];
923 int temp_len;
924
925
926
927
928 open_mode = O_RDWR;
929 if (data_ptr->destination_flags & BFT_BINARY)
930 open_mode |= O_RAW;
931 fp_dest = open (data_ptr->destination_file, open_mode);
932
933
934
935 if (fp_dest == -1)
936 {
937 sprintf (temp_str, "%s opening %s.", getsyserr (errno), data_ptr->destination_file);
938 out_str[0]=0;
939 out_len = 0;
940 out_len = addtoken (out_str, out_len, temp_str, 0);
941 executeb (WRITE_ERROR, out_str, out_len, mcb_ptr);
942 return;
943 }
944
945
946
947 lseek (fp_dest, 0L, SEEK_EOF);
948 status = write (fp_dest, data_ptr->outbuffer, data_ptr->outbuffpos);
949
950
951
952 if (status < 0)
953 {
954 close(fp_dest);
955 sprintf (out_str, "%s writing %s", getsyserr (errno), data_ptr->destination_file);
956 temp_str[0]=0;
957 temp_len = 0;
958 temp_len = addtoken (temp_str, temp_len, out_str, 0);
959 executeb (WRITE_ERROR, temp_str, temp_len, mcb_ptr);
960 return;
961 }
962 else if (data_ptr->destination_flags & BFT_NOTIFY)
963 putbgmes (mcb_ptr, 0, "BFT", "Completed transfer of %s.", data_ptr->destination_file);
964
965
966
967 data_ptr->outbuffpos = 0;
968 close (fp_dest);
969
970
971
972 data_ptr->destination_file[0] = 0;
973
974 return;
975 }
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995 read_err (arg_string, arg_len, mcb_ptr, data_ptr)
996
997 char *arg_string;
998 int arg_len;
999 mcb *mcb_ptr;
1000 bft_data_ptr data_ptr;
1001 {
1002 char message[MAXARGSTRING];
1003 int message_len;
1004
1005
1006
1007
1008 message_len = (arg_len > WSPAKSIZ) ? WSPAKSIZ : arg_len;
1009 strncpy (message, arg_string, message_len);
1010 message[message_len] = 0;
1011 putbgmes (mcb_ptr, 0, "BFT", message);
1012
1013
1014
1015 data_ptr->destination_file[0] = 0;
1016
1017
1018
1019 message[0] = 0;
1020 message_len = 0;
1021 executeb (INITIATE_STORE, message, message_len, mcb_ptr);
1022 }
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042 write_err (arg_string, arg_len, mcb_ptr, data_ptr)
1043
1044 char *arg_string;
1045 int arg_len;
1046 mcb *mcb_ptr;
1047 bft_data_ptr data_ptr;
1048 {
1049 char message[MAXARGSTRING];
1050 int message_len;
1051
1052
1053
1054
1055 message_len = (arg_len > WSPAKSIZ) ? WSPAKSIZ : arg_len;
1056 strncpy (message, arg_string, message_len);
1057 message[message_len] = 0;
1058 putbgmes(mcb_ptr, 0, "BFT", message);
1059
1060
1061
1062 data_ptr->source_file[0] = 0;
1063
1064
1065
1066 message[0] = 0;
1067 message_len = 0;
1068 executeb (INITIATE_FETCH, message, message_len, mcb_ptr);
1069 }
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088 send_data (arg_string, arg_len, mcb_ptr, data_ptr)
1089
1090 int arg_len;
1091 char *arg_string;
1092 mcb *mcb_ptr;
1093 bft_data_ptr data_ptr;
1094 {
1095 int i;
1096 char out_str [MAXARGSTRING];
1097 int out_len;
1098 char temp_str [MAXARGSTRING];
1099
1100
1101
1102
1103 i = get_data(out_str,BUFFSIZE,data_ptr);
1104 out_str[i]=0;
1105 out_len = 0;
1106
1107
1108
1109 if (i>0)
1110 {
1111 out_len = i;
1112 executeb(REC_DATA,out_str,out_len,mcb_ptr);
1113 return;
1114 }
1115
1116
1117
1118 else if (i==0)
1119 executeb(REC_EOF,out_str,out_len,mcb_ptr);
1120
1121
1122
1123 else
1124 {
1125 sprintf (temp_str, "%s reading %s.", getsyserr (errno), data_ptr->source_file);
1126 out_str[0]=0;
1127 out_len = 0;
1128 out_len = addtoken (out_str, out_len, temp_str, 0);
1129 executeb (READ_ERROR, out_str, out_len, mcb_ptr);
1130 }
1131
1132 data_ptr->source_file[0]=0;
1133 }
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148 disconnect_request (mcb_ptr,sender)
1149
1150 mcb *mcb_ptr;
1151 int sender;
1152 {
1153 disresp (WSACCEPT, sender, mcb_ptr);
1154 destinst (&mcb_ptr);
1155 }
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169 disconnect_response (mcb_ptr)
1170
1171 mcb *mcb_ptr;
1172 {
1173 destinst(&mcb_ptr);
1174 }
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189 execute_command_reply()
1190 {
1191 return;
1192 }
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217 int get_data (buffer, length, data_ptr)
1218
1219 int length;
1220 char *buffer;
1221 bft_data_ptr data_ptr;
1222 {
1223 int fp_source;
1224 int status;
1225 int i;
1226 int open_mode;
1227 long file_pos;
1228
1229
1230
1231
1232 if (data_ptr->inbuffpos == 0)
1233 {
1234 open_mode = O_RDONLY;
1235 if (data_ptr->source_flags & BFT_BINARY)
1236 open_mode |= O_RAW;
1237 fp_source = open (data_ptr->source_file, open_mode);
1238
1239
1240
1241 if (fp_source == -1)
1242 return (-1);
1243
1244
1245
1246 file_pos = lseek (fp_source, data_ptr->inpos, SEEK_START);
1247 if (file_pos == -1L)
1248 {
1249 close (fp_source);
1250 return (-1);
1251 }
1252
1253
1254
1255 status = read (fp_source, data_ptr->inbuffer, DISKBUFF);
1256 if (status < 1)
1257 {
1258 close (fp_source);
1259 return (status);
1260 }
1261
1262
1263
1264 data_ptr->inpos = lseek (fp_source, 0L, SEEK_CURRENT);
1265 data_ptr->inbufflen = status;
1266 close (fp_source);
1267 }
1268
1269
1270
1271 if ((data_ptr->inbuffpos + length) > data_ptr->inbufflen)
1272 length = data_ptr->inbufflen - data_ptr->inbuffpos;
1273
1274
1275
1276 for (i=0;i<length;i++)
1277 buffer[i] = data_ptr->inbuffer[i+data_ptr->inbuffpos];
1278
1279
1280
1281 if ((data_ptr->inbuffpos + length) == data_ptr->inbufflen)
1282 data_ptr->inbuffpos = 0;
1283 else
1284 data_ptr->inbuffpos = data_ptr->inbuffpos + length;
1285
1286 return (length);
1287 }
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303 put_data (buffer, length, data_ptr)
1304
1305 int length;
1306 char *buffer;
1307 bft_data_ptr data_ptr;
1308 {
1309 int fp_dest;
1310 int status;
1311 int i;
1312 char temp_str[100];
1313 int open_mode;
1314 long file_pos;
1315
1316
1317
1318
1319 if ((data_ptr->outbuffpos+length ) > DISKBUFF)
1320 {
1321 open_mode = O_RDWR;
1322 if (data_ptr->destination_flags & BFT_BINARY)
1323 open_mode |= O_RAW;
1324 fp_dest = open (data_ptr->destination_file, open_mode);
1325 if (fp_dest == -1)
1326 return (-1);
1327
1328
1329
1330 if (data_ptr->outpos == 0)
1331 file_pos = lseek (fp_dest, 0L, SEEK_EOF);
1332 else
1333 {
1334 file_pos = lseek (fp_dest, data_ptr->outpos, SEEK_START);
1335 data_ptr->outpos = 0;
1336 }
1337 if (file_pos == -1L)
1338 {
1339 close (fp_dest);
1340 return (-1);
1341 }
1342
1343
1344
1345 status = write (fp_dest, data_ptr->outbuffer, data_ptr->outbuffpos);
1346 if (status < 1)
1347 {
1348 close (fp_dest);
1349 return (status);
1350 }
1351
1352 data_ptr->outbuffpos = 0;
1353 close (fp_dest);
1354 }
1355
1356
1357
1358
1359 for (i=0;i<length;i++)
1360 data_ptr->outbuffer[i+data_ptr->outbuffpos] = buffer[i];
1361
1362 data_ptr->outbuffpos += length;
1363
1364 return (length);
1365 }
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381 executeb (minum, arg_string, arg_len, mcb_ptr)
1382
1383 int minum;
1384 int arg_len;
1385 mcb *mcb_ptr;
1386 char *arg_string;
1387 {
1388 int majnum;
1389 int code;
1390
1391
1392 majnum = 0;
1393 if ((code = findnumb ("bft_main_", WSREMOTE, &majnum)) != 0)
1394 {
1395 putbgmes (mcb_ptr, code, "BFT", "Finding Multics BFT capability.");
1396 return(0);
1397 }
1398 else
1399 return (execap (majnum, minum, arg_string, arg_len, mcb_ptr));
1400 }
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416 expand_path (path, dirname, entryname)
1417
1418 char *path;
1419 char *dirname;
1420 char *entryname;
1421 {
1422 int i;
1423 int indx;
1424 char token[MU_ENTRYNAME_SIZE];
1425 char *sp;
1426
1427
1428 for (i = 0, indx = 0; path[i] != '\0'; i++)
1429 {
1430 if (path[i] == '\\')
1431 indx = i;
1432 }
1433
1434
1435
1436 indx = (indx <= PATHNAMESIZE) ? indx : PATHNAMESIZE;
1437 strncpy (dirname, path, indx);
1438
1439 XXX
1440
1441 sp = &(path[indx+1]);
1442 sp = stptok (sp, token, sizeof (token), ".");
1443 strncpy (entryname, token, 8);
1444
1445
1446
1447 if (*sp == '.')
1448 {
1449 sp += 1;
1450 strcat (entryname, ".");
1451 }
1452
1453 XXX
1454
1455 sp = stptok (sp, token, sizeof (token), ".");
1456 if (strlen (token) > 0)
1457 strncat (entryname, token, 3);
1458 }
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471 findfirst(str)
1472
1473 short str;
1474 {
1475 union REGS sysregs;
1476 int code;
1477
1478 sysregs.h.ah = DOS_STAR_FIRST;
1479 sysregs.x.cx = 0;
1480 sysregs.x.dx = str;
1481 code = intdos (&sysregs,&sysregs);
1482 code &= 01;
1483 return (!code);
1484 }
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494 findnext()
1495 {
1496 union REGS sysregs;
1497 int code;
1498
1499 sysregs.h.ah = DOS_STAR_NEXT;
1500 code = intdos (&sysregs,&sysregs);
1501 code &= 01;
1502 return (!code);
1503 }
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515 set_dta (offset)
1516
1517 short offset;
1518 {
1519 union REGS sysregs;
1520
1521 sysregs.h.ah = DOS_SET_DTA;
1522 sysregs.x.dx = offset;
1523 intdos (&sysregs,&sysregs);
1524 }