Skip to content

Latest commit

 

History

History
557 lines (502 loc) · 15.8 KB

file6.pas

File metadata and controls

557 lines (502 loc) · 15.8 KB
 
Nov 18, 2000
Nov 18, 2000
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
{$A+,B+,D-,E+,F+,I+,L+,N-,O+,R-,S+,V-}
unit file6;
interface
uses
crt,dos,
{rcg11172000 no overlay under Linux.}
{overlay,}
file0, file1, file2, file4, file9,
execbat,
common;
procedure delbatch(n:integer);
procedure mpkey(var s:astr);
function bproline1(cline:astr):astr;
procedure bproline(var cline:astr; filespec:astr);
function okprot(prot:protrec; ul,dl,batch,resume:boolean):boolean;
procedure showprots(ul,dl,batch,resume:boolean);
function findprot(cs:astr; ul,dl,batch,resume:boolean):integer;
procedure batchdl;
procedure listbatchfiles;
procedure removebatchfiles;
procedure clearbatch;
implementation
procedure delbatch(n:integer);
var c:integer;
begin
if ((n>=1) and (n<=numbatchfiles)) then begin
batchtime:=batchtime-batch[n].tt;
if (n<>numbatchfiles) then
for c:=n to numbatchfiles-1 do batch[c]:=batch[c+1];
dec(numbatchfiles);
end;
end;
procedure mpkey(var s:astr);
var sfqarea,smqarea:boolean;
begin
sfqarea:=fqarea; smqarea:=mqarea;
fqarea:=FALSE; mqarea:=FALSE;
mmkey(s);
fqarea:=sfqarea; mqarea:=smqarea;
end;
function bproline2(cline:astr):astr;
var s:astr;
begin
s:=substall(cline,'%C',start_dir);
s:=substall(s,'%G',copy(systat.gfilepath,1,length(systat.gfilepath)-1));
bproline2:=s;
end;
function bproline1(cline:astr):astr;
var s,s1:astr;
begin
if ((not incom) and (not outcom)) then s1:=cstrl(modemr.waitbaud) else s1:=spd;
s:=substall(cline,'%B',s1);
s:=substall(s,'%L',bproline2(protocol.dlflist));
s:=substall(s,'%P',cstr(modemr.comport));
s:=substall(s,'%T',bproline2(protocol.templog));
bproline1:=bproline2(s);
end;
procedure bproline(var cline:astr; filespec:astr);
const lastpos:integer=-1;
begin
if (pos('%F',cline)<>0) then begin
lastpos:=pos('%F',cline)+length(filespec);
cline:=substall(cline,'%F',filespec);
end else begin
insert(' '+filespec,cline,lastpos);
inc(lastpos,length(filespec)+1);
end;
end;
function okprot(prot:protrec; ul,dl,batch,resume:boolean):boolean;
var s:astr;
begin
okprot:=FALSE;
with prot do begin
if (ul) then s:=ulcmd else if (dl) then s:=dlcmd else s:='';
if (s='NEXT') and ((ul) or (batch) or (resume)) then exit;
if (s='BATCH') and ((batch) or (resume)) then exit;
if (batch<>(xbisbatch in xbstat)) then exit;
if (resume<>(xbisresume in xbstat)) then exit;
if (not (xbactive in xbstat)) then exit;
if (not aacs(acs)) then exit;
if (s='') then exit;
end;
okprot:=TRUE;
end;
procedure showprots(ul,dl,batch,resume:boolean);
var s:astr;
i:integer;
abort,next:boolean;
begin
nofile:=TRUE;
if (resume) then printf('protres')
else begin
if (batch) and (ul) then printf('protbul');
if (batch) and (dl) then printf('protbdl');
if (not batch) and (ul) then printf('protsul');
if (not batch) and (dl) then printf('protsdl');
end;
if (nofile) then begin
seek(xf,0);
abort:=FALSE; next:=FALSE; i:=0;
while ((i<=filesize(xf)-1) and (not abort)) do begin
read(xf,protocol);
if (okprot(protocol,ul,dl,batch,resume)) then sprint(protocol.descr);
if (not empty) then wkey(abort,next);
inc(i);
end;
end;
end;
(* XF should be OPEN --
returns:
(-1):Ascii (xx):Xmodem (xx):Xmodem-CRC (xx):Ymodem
(-10):Quit (-11):Next (-12):Batch (-99):Invalid (or no access)
else, the protocol #
*)
function findprot(cs:astr; ul,dl,batch,resume:boolean):integer;
var s:astr;
i:integer;
done:boolean;
begin
findprot:=-99;
if (cs='') then exit;
seek(xf,0);
done:=FALSE; i:=0;
while ((i<=filesize(xf)-1) and (not done)) do begin
read(xf,protocol);
with protocol do
if (cs=ckeys) then
if (okprot(protocol,ul,dl,batch,resume)) then begin
if (ul) then s:=ulcmd else if (dl) then s:=dlcmd else s:='';
if (s='ASCII') then begin done:=TRUE; findprot:=-1; end
else if (s='QUIT') then begin done:=TRUE; findprot:=-10; end
else if (s='NEXT') then begin done:=TRUE; findprot:=-11; end
else if (s='BATCH') then begin done:=TRUE; findprot:=-12; end
else if (s<>'') then begin done:=TRUE; findprot:=i; end;
end;
inc(i);
end;
end;
procedure batchdl;
var batfile,tfil:text; {@4 file list file}
xferstart,xferend,tooktime,batchtime1:datetimerec;
nfn,snfn,s,s1,s2,i,logfile:astr;
st,tott,tooktime1:real;
tblks,tblks1,cps,lng:longint;
tpts,tpts1,tnfils,tnfils1:integer;
sx,sy,hua,n,p,toxfer,rcode:integer;
c:char;
swap,done1,dok,kabort,nomore,readlog:boolean;
function tempfile(i:integer):astr;
begin
tempfile:='temp'+cstr(i)+'.$$$';
end;
procedure sprtcl(c:char; s:astr);
var wnl:boolean;
begin
if copy(s,length(s),1)<>#0 then wnl:=TRUE else wnl:=FALSE;
if not wnl then s:=copy(s,1,length(s)-1);
sprompt('^3'+c+'^1) ^4'+s);
if wnl then nl;
end;
procedure addnacc(i:integer; s:astr);
var f:ulfrec;
oldboard,pl,rn:integer;
begin
if (i<>-1) then begin
oldboard:=fileboard; fileboard:=i;
s:=sqoutsp(stripname(s));
recno(s,pl,rn); {* opens ulff *}
if rn<>0 then begin
seek(ulff,rn); read(ulff,f);
inc(f.nacc);
seek(ulff,rn); write(ulff,f);
end;
fileboard:=oldboard;
close(ulff);
end;
end;
procedure chopoffspace(var s:astr);
begin
if (pos(' ',s)<>0) then s:=copy(s,1,pos(' ',s)-1);
end;
procedure figuresucc;
var filestr,statstr:astr;
foundit:boolean;
function wasok:boolean;
var i:integer;
foundcode:boolean;
begin
foundcode:=FALSE;
for i:=1 to 6 do
if (protocol.dlcode[i]<>'') and
(protocol.dlcode[i]=copy(statstr,1,length(protocol.dlcode[i]))) then
foundcode:=TRUE;
wasok:=FALSE;
if ((foundcode) and (not (xbxferokcode in protocol.xbstat))) then exit;
if ((not foundcode) and (xbxferokcode in protocol.xbstat)) then exit;
wasok:=TRUE;
end;
begin
readlog:=FALSE;
if (protocol.templog<>'') then begin
assign(batfile,bproline1(protocol.templog));
{$I-} reset(batfile); {$I+}
if (ioresult=0) then begin
assign(tfil,bproline1(protocol.dloadlog));
{$I-} append(tfil); {$I+}
if (ioresult<>0) then rewrite(tfil);
readlog:=TRUE;
while (not eof(batfile)) do begin
readln(batfile,s); writeln(tfil,s);
filestr:=copy(s,protocol.logpf,length(s)-(protocol.logpf-1));
statstr:=copy(s,protocol.logps,length(s)-(protocol.logps-1));
chopoffspace(filestr);
foundit:=FALSE; n:=0;
while ((n<numbatchfiles) and (not foundit)) do begin
inc(n);
if (allcaps(batch[n].fn)=allcaps(filestr)) then foundit:=TRUE;
end;
if (foundit) then begin
if (wasok) then begin
sysoplog(#3#5+'Batch downloaded "'+stripname(batch[n].fn)+'"');
inc(tnfils);
inc(tblks,batch[n].blks);
inc(tpts,batch[n].pts);
loaduboard(batch[n].section);
if (not (fbnoratio in memuboard.fbstat)) then begin
inc(tnfils1);
inc(tblks1,batch[n].blks);
inc(tpts1,batch[n].pts);
end;
addnacc(batch[n].section,batch[n].fn);
delbatch(n);
end else
sysoplog(#3#7+'Tried batch download "'+stripname(batch[n].fn)+'"');
end else
sysoplog(#3#7+'*Batch downloaded unauthorized file? "'+filestr+'"');
end;
close(batfile);
close(tfil);
end;
end;
if (not readlog) then begin
while (toxfer>0) do begin
sysoplog(#3#5+'Batch download "'+stripname(batch[1].fn)+'"');
inc(tnfils);
inc(tblks,batch[1].blks);
inc(tpts,batch[1].pts);
loaduboard(batch[1].section);
if (not (fbnoratio in memuboard.fbstat)) then begin
inc(tnfils1);
inc(tblks,batch[1].blks);
inc(tpts1,batch[1].pts);
end;
addnacc(batch[1].section,batch[1].fn);
delbatch(1); dec(toxfer);
end;
end;
end;
begin
if (numbatchfiles=0) then begin
nl; print('Batch queue empty.');
end else begin
nl;
print('Checking batch download request...');
tott:=0.0;
for n:=1 to numbatchfiles do
tott:=tott+batch[n].tt;
nl;
print('Number files in batch .. : '+cstr(numbatchfiles));
print('Batch download time .... : '+ctim(tott));
print('Time left online ....... : '+ctim(nsl));
if (tott>nsl) then begin
nl;
print('Insufficient time for download!!');
print('You must remove some files from your batch queue.');
exit;
end;
reset(xf);
done1:=FALSE;
repeat
nl;
sprompt('^4Batch Protocol (^0?^4=^0list^4) : ^3'); mpkey(i);
if (i='?') then begin
nl;
showprots(FALSE,TRUE,TRUE,FALSE);
end else begin
p:=findprot(i,FALSE,TRUE,TRUE,FALSE);
if (p=-99) then print('Invalid entry.') else done1:=TRUE;
end;
until (done1) or (hangup);
if (p<>-10) then begin
seek(xf,p); read(xf,protocol); close(xf);
nl; sprint(#3#7+'Hangup after transfer?');
prt('(A)bort (N)o (Y)es (M)aybe : '); onek(c,'ANYM'^M);
if (c=^M) then c:='N';
hua:=pos(c,'ANYM');
dok:=TRUE;
if (hua<>1) then begin
tblks:=0; tpts:=0; tnfils:=0;
tblks1:=0; tpts1:=0; tnfils1:=0;
nl; nl;
nfn:=bproline1(protocol.dlcmd);
toxfer:=0; tott:=0.0;
if (pos('%F',protocol.dlcmd)<>0) then begin
done1:=FALSE;
while ((not done1) and (toxfer<numbatchfiles)) do begin
inc(toxfer); snfn:=nfn;
bproline(nfn,batch[toxfer].fn);
if (length(nfn)>protocol.maxchrs) then done1:=TRUE
else tott:=tott+batch[toxfer].tt;
end;
end;
if (protocol.dlflist<>'') then begin
tott:=0.0;
assign(batfile,bproline1(protocol.dlflist));
rewrite(batfile);
for n:=1 to numbatchfiles do begin
writeln(batfile,batch[n].fn);
inc(toxfer); tott:=tott+batch[n].tt;
end;
close(batfile);
end;
(* output x-fer batch file *)
assign(batfile,'tgtemp1.bat'); rewrite(batfile);
if (protocol.envcmd<>'') then
writeln(batfile,bproline1(protocol.envcmd));
writeln(batfile,nfn);
writeln(batfile,'exit');
close(batfile);
(* delete old log file *)
if (exist(bproline1(protocol.templog))) then begin
assign(batfile,bproline1(protocol.templog));
{$I-} erase(batfile); {$I+}
end;
r2dt(batchtime,batchtime1);
if (useron) then
print('Transmitting batch - Time: '+longtim(batchtime1));
if (useron) then shel(caps(thisuser.name)+' is batch downloading!')
else shel('Sending file(s)...');
getdatetime(xferstart);
swap:=systat.swapshell;
systat.swapshell:=FALSE;
shelldos(FALSE,'tgtemp1',rcode);
systat.swapshell:=swap;
shel2;
getdatetime(xferend);
timediff(tooktime,xferstart,xferend);
(* delete TGTEMP1.BAT batch file *)
assign(batfile,'tgtemp1.bat');
{$I-} erase(batfile); {$I+}
figuresucc;
tooktime1:=dt2r(tooktime);
if (tooktime1>=1.0) then begin
cps:=tblks; cps:=cps*128;
cps:=trunc(cps/tooktime1);
end else
cps:=0;
showuserfileinfo;
commandline('');
nl; nl;
s:='Download totals: ';
if (tnfils=0) then s:=s+'No' else s:=s+cstr(tnfils);
s:=s+' file'; if (tnfils<>1) then s:=s+'s';
lng:=tblks; lng:=lng*128;
s:=s+', '+cstrl(lng)+' bytes';
if (tpts<>0) then begin
s:=s+', '+cstr(tpts)+' file point';
if (tpts<>1) then s:=s+'s';
end;
s:=s+'.';
star(s);
if (tnfils1<>tnfils) then begin
if (tnfils<tnfils1) then tnfils1:=tnfils;
s:='Download charges: ';
if (tnfils1=0) then s:=s+'No' else s:=s+cstr(tnfils1);
s:=s+' file'; if (tnfils1<>1) then s:=s+'s';
lng:=tblks1; lng:=lng*128;
s:=s+', '+cstrl(lng)+' bytes';
if (tpts1<>0) then begin
s:=s+', '+cstr(tpts1)+' file point';
if (tpts1<>1) then s:=s+'s';
end;
s:=s+'.';
star(s);
end;
star('Download time: '+longtim(tooktime));
star('Transfer rate: '+cstr(cps)+' cps');
thisuser.dk:=thisuser.dk+(tblks1 div 8);
inc(thisuser.downloads,tnfils1);
dec(thisuser.filepoints,tpts1);
inc(systat.todayzlog.downloads,tnfils);
inc(systat.todayzlog.dk,tblks div 8);
if (numbatchfiles<>0) then begin
tblks:=0; tpts:=0;
for n:=1 to numbatchfiles do begin
inc(tblks,batch[n].blks);
inc(tpts,batch[n].pts);
end;
lng:=tblks; lng:=lng*128;
s:='Not transferred: '+cstr(numbatchfiles)+' file';
if (numbatchfiles<>1) then s:=s+'s';
s:=s+', '+cstrl(lng)+' bytes';
if (tpts<>0) then begin
s:=s+', '+cstr(tpts)+' file point';
if (tpts<>1) then s:=s+'s';
end;
s:=s+'.';
star(s);
end;
case hua of
3:hangup:=TRUE;
4:begin
nl;
nl;
print('System will automatically hang up in 30 seconds.');
print('Hit [H] to hang up now, any other key to abort.');
st:=timer;
while (tcheck(st,30)) and (empty) do;
if (empty) then hangup:=TRUE;
if (not empty) then
if upcase(inkey)='H' then
hangup:=TRUE;
end;
end;
end;
end;
end;
end;
procedure listbatchfiles;
var tot:record
pts:integer;
blks:longint;
tt:real;
end;
s:astr;
i:integer;
abort,next:boolean;
begin
if (numbatchfiles=0) then begin
nl; print('Batch queue empty.');
end else begin
abort:=FALSE; next:=FALSE;
with tot do begin
pts:=0; blks:=0; tt:=0.0;
end;
nl;
printacr(#3#4+'##:Filename.Ext Area Pts Bytes hh:mm:ss',abort,next);
printacr(#3#4+'--------------- ---- ----- ------- --------',abort,next);
i:=1;
while (not abort) and (not hangup) and (i<=numbatchfiles) do begin
with batch[i] do begin
if section=-1 then s:=#3#7+'Unli' else s:=#3#5+mrn(cstr(section),4);
s:=#3#3+mn(i,2)+#3#4+':'+#3#5+align(stripname(fn))+' '+
s+' '+#3#4+mrn(cstr(pts),5)+' '+
#3#4+mrn(cstrl(blks*128),7)+' '+#3#7+ctim(tt);
if (section<>-1) then begin
loaduboard(section);
if (fbnoratio in memuboard.fbstat) then s:=s+#3#5+' <No-Ratio>';
end;
printacr(s,abort,next);
tot.pts:=tot.pts+pts;
tot.blks:=tot.blks+blks;
tot.tt:=tot.tt+tt;
end;
inc(i);
end;
printacr(#3#4+'--------------- ---- ----- ------- --------',abort,next);
with tot do
s:=#3#3+mln('Totals:',20)+' '+#3#4+mrn(cstr(pts),5)+' '+
#3#4+mrn(cstrl(blks*128),7)+' '+#3#7+ctim(tt);
printacr(s,abort,next);
end;
end;
procedure removebatchfiles;
var s:astr;
i:integer;
begin
if numbatchfiles=0 then begin
nl; print('Batch queue empty.');
end else
repeat
nl;
prt('File # to remove (1-'+cstr(numbatchfiles)+') (?=list) : ');
input(s,2); i:=value(s);
if (s='?') then listbatchfiles;
if (i>0) and (i<=numbatchfiles) then begin
print('"'+stripname(batch[i].fn)+'" deleted out of queue.');
delbatch(i);
end;
if (numbatchfiles=0) then print('Queue now empty.');
until (s<>'?');
end;
procedure clearbatch;
begin
nl;
if pynq('Clear queue? ') then begin
numbatchfiles:=0;
batchtime:=0.0;
print('Queue now empty.');
end;
end;
end.