-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathptprocs.pas
1250 lines (1184 loc) · 28.1 KB
/
ptprocs.pas
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Unit PTProcs;
InterFace
Uses
{$IfDef UNIX}
linux,
{$EndIf}
DOS, Strings,
Types, GeneralP, Log,
TickType, TickCons, PTVar;
Procedure WriteTime;
Function Pack(Packer: Byte; Arc: String; fn: String): Boolean;
Function UnPack(UnPacker: Byte; Arc: String; Dir: String): Boolean;
Procedure ReplaceFiles(FSpec: String);
Function RandName: String8;
Function TicErrorStr(ErrNum: Byte): String;
Procedure GetFileDesc(FName: String; Desc: PChar2);
Procedure SetFileDesc(FName: String; Desc: PChar2);
Procedure SetLongName(Path: DirStr; SName: String12; LName: String40);
Function Match(s1, s2: String): Boolean;
Procedure AddAutoArea(Name: String);
Procedure AddTossArea(Name, BBSArea: String);
Procedure WriteAutoArea;
Procedure WriteTossArea;
Procedure WriteBBSArea;
Procedure DelPT;
Procedure PurgeDupes;
Function GetMsgID : String;
Implementation
Procedure WriteTime;
Var
Date: TimeTyp;
Begin
Now(Date);
With Date do WriteLn('Time: ', Hour, ':', Min, ':', Sec, '.', Sec100);
End;
Function RandName: String8;
Begin
RandName := WordToHex(word(Random($FFFF)))+WordToHex(word(Random($FFFF)));
End;
Function UnPack(UnPacker: Byte; Arc: String; Dir: String): Boolean;
Var
CurUnPacker : TUnPacker;
i: LongInt;
UPNum: Byte;
s: String;
Error: Integer;
DidUnpack: Boolean;
Found: LongInt;
Begin
UPNum := 0;
CurUnPacker.Index := 255;
DidUnpack := False;
Found := 0;
For i := 1 to Cfg^.NumUnPacker do If (Cfg^.UnPacker[i].Index = UnPacker) then
Begin
CurUnPacker := Cfg^.UnPacker[i];
Found := i;
i := Cfg^.NumUnPacker + 1;
End;
If ((Found = 0) and (UnPacker <> 0)) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Unknown UnPacker: #'+IntToStr(UnPacker));
Exit;
End;
Repeat
If ((UnPacker = 0) and (CurUnPacker.Index <> 0)) then
Begin
Inc(UPNum);
CurUnPacker := Cfg^.UnPacker[UPNum];
End;
s := CurUnPacker.Cmd;
i := Pos('%A', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(Arc, s, i);
i := Pos('%A', s);
End;
i := Pos('%s', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(Arc, s, i);
i := Pos('%s', s);
End;
i := Pos('%D', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(Dir, s, i);
i := Pos('%D', s);
End;
ChDir(Dir);
{$IfDef OS2}
{$IfDef VIRTUALPASCAL}
Exec(GetEnv('COMSPEC'), '/C '+s);
Error := DOSExitCode;
{$Else}
{$IfDef FPC}
Exec(GetEnv('COMSPEC'), '/C '+s);
Error := DOSExitCode;
{$Else}
Error := DOSExitCode(Exec(GetEnv('COMSPEC'), '/C '+s));
{$EndIf}
{$EndIf}
{$Else}
{$IfDef UNIX}
Shell(s);
Error := DOSExitCode;
{$Else}
SwapVectors;
Exec(GetEnv('COMSPEC'), '/C '+s);
Error := DOSExitCode;
SwapVectors;
{$EndIf}
{$EndIf}
WriteLn('Exitcode ', Error);
DidUnPack := DidUnPack or (Error = 0);
If (Unpacker <> 0) and (Error > 0) then If (Error = 1) then
Begin
LogSetCurLevel(LogHandle, 3);
LogWriteLn(LogHandle, 'Called "'+s+'"');
LogWriteLn(LogHandle, 'UnPacker returned warning (errorlevel 1)');
End
Else
Begin
LogSetCurLevel(LogHandle, 2);
LogWriteLn(LogHandle, 'Called "'+s+'"');
LogWriteLn(LogHandle, 'UnPacker returned error (errorlevel '+IntToStr(Error)+')');
End;
Until ((UnPacker <> 0) or (CurUnPacker.Index = 0) or (UPNum = Cfg^.NumUnPacker));
UnPack := DidUnPack;
End;
Function Pack(Packer: Byte; Arc: String; fn: String): Boolean;
Var
CurPacker : TPacker;
i: LongInt;
s: String;
s1: String;
Error: Integer;
Found: LongInt;
Begin
Found := 0;
For i := 1 to Cfg^.NumPacker do If (Cfg^.Packer[i].Index = Packer) then
Begin
CurPacker := Cfg^.Packer[i];
Found := i;
End;
If (Found = 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Unknown Packer: #'+IntToStr(Packer));
Exit;
End;
s := CurPacker.Cmd;
i := Pos('%A', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(Arc, s, i);
i := Pos('%A', s);
End;
i := Pos('%F', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(fn, s, i);
i := Pos('%F', s);
End;
i := Pos('$a', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(Arc, s, i);
i := Pos('$a', s);
End;
i := Pos('$f', s);
While (i <> 0) do
Begin
Delete(s, i, 2);
Insert(fn, s, i);
i := Pos('$f', s);
End;
i := Pos('%', s);
While (i <> 0) do
Begin
Delete(s, i, 1);
s1 := Copy(s, i, Pos('%', s) - i);
Delete(s, i, (Pos('%', s) - i)+1);
Insert(GetEnv(UpStr(s1)), s, i);
i := Pos('%', s);
End;
{$IfDef OS2}
{$IfDef VIRTUALPASCAL}
Exec(GetEnv('COMSPEC'), '/C '+s);
Error := DosExitCode;
{$Else}
{$IfDef FPC}
Exec(GetEnv('COMSPEC'), '/C '+s);
Error := DOSExitCode;
{$Else}
Error := DosExitCode(Exec(GetEnv('COMSPEC'), '/C '+s));
{$EndIf}
{$EndIf}
{$Else}
{$IfDef UNIX}
Shell(s);
Error := DOSExitCode;
{$Else}
SwapVectors;
Exec(GetEnv('COMSPEC'), '/C '+s);
Error := DosExitCode;
SwapVectors;
{$EndIf}
{$EndIf}
If (Error > 0) then If (Error = 1) then
Begin
LogSetCurLevel(LogHandle, 3);
LogWriteLn(LogHandle, 'Called "'+s+'"');
LogWriteLn(LogHandle, 'Packer returned warning (errorlevel 1)');
End
Else
Begin
LogSetCurLevel(LogHandle, 2);
LogWriteLn(LogHandle, 'Called "'+s+'"');
LogWriteLn(LogHandle, 'Packer returned error (errorlevel '+IntToStr(Error)+')');
End;
Pack := (Error < 1);
End;
Procedure ReplaceFiles(FSpec: String);
Var
{$IfDef SPEED}
SRec: TSearchRec;
{$Else}
SRec: SearchRec;
{$EndIf}
f: File;
Dir: String;
Name: String;
Ext: String;
Begin
If (Pos('.', FSpec) = 0) then SRec.Name := FSpec + '.*'
Else SRec.Name := FSpec;
FindFirst(FSpec, AnyFile, SRec);
While (DosError = 0) Do
Begin
FSplit(FSpec, Dir, Name, Ext);
If (CurArea^.MoveTo <> '') then
Begin
DelFile(CurArea^.MoveTo + DirSep + SRec.Name);
If not MoveFile(Dir + SRec.Name, CurArea^.MoveTo + DirSep + SRec.Name) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t move "'+Dir + SRec.Name+'" to "'+CurArea^.MoveTo + DirSep+ SRec.Name +'"!');
End;
End
Else
Begin
If not DelFile(Dir + SRec.Name) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t delete "'+Dir + SRec.Name+'"!');
End;
End;
FindNext(SRec);
End;
{$IfDef OS2}
FindClose(SRec);
{$EndIf}
End;
Function TicErrorStr(ErrNum: Byte): String;
Begin
Case ErrNum of
bt_NoFile: TicErrorStr := 'File locked or not in InBound';
bt_CRC: TicErrorStr := 'CRC-Error';
bt_UnKnownArea: TicErrorStr := 'Unknown area';
bt_NotConnected: TicErrorStr := 'Sender not connected to area';
bt_NoSend: TicErrorStr := 'Sender not SEND-connected to area';
bt_WrongPwd: TicErrorStr := 'Wrong password';
bt_CouldntMove: TicErrorStr := 'Couldn''t move file';
bt_Dupe: TicErrorStr := 'Dupe';
bt_NotForUs: TicErrorStr := 'Not for us';
bt_Unlisted: TicErrorStr := 'Unlisted sender';
Else TicErrorStr := 'Unknown error';
End;
End;
Procedure GetFileDesc(FName: String; Desc: PChar2);
Var
s: String;
f: Text;
Dir, Name, Ext: String;
ppos: word;
i: word;
Begin
PPos := 0;
Desc^[0] := #0;
FSplit(FName, Dir, Name, Ext);
{$IfNDef UNIX}
Name := UpStr(Name);
Ext := UpStr(Ext);
{$EndIf}
Assign(f, Dir + 'files.bbs');
{$I-} ReSet(f); {$I+}
If (IOResult = 0) then
Begin
While (not EOF(f)) do
Begin
ReadLn(f, s);
If (s[Byte(s[0])] = #13) then s[0] := Char(Byte(s[0])-1);
{$IfDef UNIX}
If (Pos(Name+Ext, s) = 1) then Break;
{$Else}
If (Pos(Name+Ext, UpStr(s)) = 1) then Break;
{$EndIf}
End;
{$IfDef UNIX}
If (Pos(Name+Ext, s) = 1) then
{$Else}
If (Pos(Name+Ext, UpStr(s)) = 1) then
{$EndIf}
Begin
Delete(s, 1, Length(Name)+Length(Ext));
s := KillSpcs(s);
If ((s[1] = '[') and (s[2] in Digits)) then
Begin
While (s[1] <> ']') do Delete(s, 1, 1);
Delete(s, 1, 1);
End;
s := KillSpcs(s);
For i := 1 to Byte(s[0]) do Desc^[PPos + i - 1] := s[i];
PPos := Byte(s[0]) + 3;
Desc^[PPos-2] := #13;
Desc^[PPos-1] := #10;
While (not EOF(f)) do
Begin
ReadLn(f, s);
If (s[Byte(s[0])] = #13) then s[0] := Char(Byte(s[0])-1);
If (s[2] = ' ') then
Begin
KillLeadingSpcs(s);
For i := 1 to Byte(s[0]) do Desc^[PPos + i - 1] := s[i];
PPos := Byte(s[0]) + 3;
Desc^[PPos-2] := #13;
Desc^[PPos-1] := #10;
End
Else Break;
End;
Desc^[PPos] := #0;
End;
{$I-} Close(f); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t close "'+Dir+'files.bbs"!');
End;
End;
End;
Procedure SetFileDesc(FName: String; Desc: PChar2);
Var
FilesBBS: Text;
FilesTMP: Text;
Dir: DirStr;
Name: NameStr;
Ext: ExtStr;
Error: Integer;
NewFilesBBS: Boolean;
Line: String;
FoundOldDesc: Boolean;
i: Byte;
CRLF: PChar2;
FirstLine: Boolean;
CurDesc: PChar2;
CRLFPos: Pointer;
Begin
{init vars}
FoundOldDesc := False;
{get names of files.bbs and files.tmp, open them}
FSplit(FName, Dir, Name, Ext);
{$IfNDef UNIX}
Name := UpStr(Name) + UpStr(Ext);
{$Else}
Name := Name + Ext;
{$EndIf}
Assign(FilesBBS, Dir + 'files.bbs');
Assign(FilesTMP, Dir + 'files.tmp');
{$I-} ReSet(FilesBBS); {$I+}
NewFilesBBS := (IOResult <> 0);
{$I-} ReWrite(FilesTMP); {$I+}
Error := IOResult;
If (Error <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not open "'+Dir+'files.tmp" for writing!');
If (not NewFilesBBS) then Close(FilesBBS);
Exit;
End;
{if files.bbs existed, copy it to files.tmp and look for the filename}
If not NewFilesBBS then
Begin
While not EOF(FilesBBS) do
Begin
ReadLn(FilesBBS, Line);
{filenames begin at first char of line}
{$IfDef UNIX}
If (Pos(Name, Line) = 1) then
{$Else}
If (Pos(Name, UpStr(Line)) = 1) then
{$EndIf}
Begin
FoundOldDesc := True;
{skip old description}
If (not EOF(FilesBBS)) then ReadLn(FilesBBS, Line)
Else Line := '';
While (Line[2] = ' ') and (not EOF(FilesBBS)) do
Begin
ReadLn(FilesBBS, Line);
{descriptions have a space at the second char of line}
End;
If (Line[2] = ' ') then Line := '';
Break;
End;
WriteLn(FilesTMP, Line);
End;
End;
{write (new) entry}
Write(FilesTMP, Name+' ');
{add DownLoadCounter}
If (Cfg^.AddDLC) then
Begin
Write(FilesTMP, '['+Copy('0000000000', 1, Cfg^.DLCDig)+'] ');
End;
{write description}
If (Desc <> NIL) and (Desc^[0] > #0) then
Begin
GetMem(CRLF, 3); CRLF^[0] := #13; CRLF^[1] := #10; CRLF^[2] := #0;
FirstLine := True;
CurDesc := Desc;
While (StrPos(Pointer(CurDesc), Pointer(CRLF)) <> NIL) do
Begin
CRLFPos := StrPos(Pointer(CurDesc), Pointer(CRLF));
If FirstLine then
Begin
FirstLine := False;
While (CurDesc <> CRLFPos) do
Begin
Write(filesTMP, CurDesc^[0]);
CurDesc := @CurDesc^[1];
End;
If not Cfg^.SingleDescLine then WriteLn(FilesTMP);
End
Else
Begin
{add LongDescChar + Spaces}
If not Cfg^.SingleDescLine then
Begin
Write(FilesTMP, Cfg^.LDescString);
If (Cfg^.DescPos > 2) then Write(FilesTMP, Copy(Leer, 1, Cfg^.DescPos-1));
End
Else Write(FilesTMP, ' ');
While (CurDesc <> CRLFPos) do
Begin
Write(filesTMP, CurDesc^[0]);
CurDesc := @CurDesc^[1];
End;
If not Cfg^.SingleDescLine then WriteLn(FilesTMP);
End;
CurDesc := @CurDesc^[2]; {skip CR/LF}
End;
{add last line}
If (CurDesc^[0] <> #0) then
Begin
If FirstLine then
Begin
FirstLine := False;
While (CurDesc^[0] <> #0) do
Begin
Write(filesTMP, CurDesc^[0]);
CurDesc := @CurDesc^[1];
End;
If not Cfg^.SingleDescLine then WriteLn(FilesTMP);
End
Else
Begin
{add LongDescChar + Spaces}
If not Cfg^.SingleDescLine then
Begin
Write(FilesTMP, Cfg^.LDescString);
If (Cfg^.DescPos > 2) then Write(FilesTMP, Copy(Leer, 1, Cfg^.DescPos-1));
End
Else Write(FilesTMP, ' ');
While (CurDesc^[0] <> #0) do
Begin
Write(filesTMP, CurDesc^[0]);
CurDesc := @CurDesc^[1];
End;
If not Cfg^.SingleDescLine then WriteLn(FilesTMP);
End;
End;
FreeMem(CRLF, 3);
End
Else
Begin
WriteLn(FilesTMP, '<no description available>');
End;
{copy remaining entries of files.bbs if any}
If (not NewFilesBBS) and (FoundOldDesc) then
Begin
{check if EOF occured while skipping old description}
If (Line <> '') then
Begin
WriteLn(FilesTMP, Line);
While not EOF(FilesBBS) do
Begin
ReadLn(FilesBBS, Line);
WriteLn(FilesTMP, Line);
End;
End;
End;
{close files, replace files.bbs by files.tmp}
If not NewFilesBBS then Close(FilesBBS);
Close(FilesTMP);
{$IfDef UNIX}
ChMod(Dir+'files.tmp', FilePerm);
{$EndIf}
If not RepFile(Dir+'files.tmp', Dir+'files.bbs') then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t replace "'+Dir+'files.bbs"!');
End;
End;
Procedure SetLongName(Path: DirStr; SName: String12; LName: String40);
Var
f1, f2: Text;
Found: Boolean;
s, SNameU: String;
Begin
{$IfNDef UNIX}
SNameU := UpStr(SName);
{$EndIf}
Found := False;
Assign(f1, Path+DirSep+'files.lng');
Assign(f2, Path+DirSep+'files.tmp');
{$I-} ReWrite(f2); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not open "'+Path+DirSep+'files.tmp"!');
Exit;
End;
{$I-} ReSet(f1); {$I+}
If (IOResult = 0) then {copy file}
Begin
While not EOF(f1) do
Begin
ReadLn(f1, s);
If (s[Byte(s[0])] = #13) then s[0] := Char(Byte(s[0])-1);
{$IfDef UNIX}
If (copy(s, 1, Pos(' ', s)-1) = SName) then {replace entry}
{$Else}
If (UpStr(copy(s, 1, Pos(' ', s)-1)) = SNameU) then {replace entry}
{$EndIf}
Begin
Found := True;
{$IfDef UNIX}
WriteLn(f2, SName + ' ' + LName);
{$Else}
WriteLn(f2, SNameU + ' ' + LName);
{$EndIf}
End
Else WriteLn(f2, s);
End;
{$I-} Close(f1); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not close "'+Path+DirSep+'files.lng"!');
End;
{$I-} Erase(f1); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not delete "'+Path+DirSep+'files.lng"!');
End;
End;
{$IfDef UNIX}
If not Found then WriteLn(f2, SName + ' ' + LName); {append entry}
{$Else}
If not Found then WriteLn(f2, SNameU + ' ' + LName); {append entry}
{$EndIf}
{$I-} Close(f2); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not close "'+Path+DirSep+'files.tmp"!');
End
Else
Begin
{$IfDef UNIX}
ChMod(Path+DirSep+'files.tmp', FilePerm);
{$EndIf}
End;
{$I-} Rename(f2, Path+DirSep+'files.lng'); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not rename "'+Path+DirSep+'files.tmp" to "'+Path+DirSep+'files.lng"!');
End;
End;
Function Match(s1, s2: String): Boolean;
Var
i: Byte;
Begin
If (s2 = '') or (s1 = '') then
Begin
Match := False;
Exit;
End;
If (Pos('*', s2) = 0) and (Pos('?', s2) = 0) then Match := (s1 = s2)
Else
Begin
For i := 1 to Length(s2) do
Begin
If (s2[i] = '*') then
Begin
Match := True;
Exit;
End
Else If (s2[i] = '?') then Continue
Else If (s1[i] <> s2[i]) then
Begin
Match := False;
Exit;
End;
End;
Match := True;
End;
End;
Procedure WriteAutoArea;
Var
f: Text;
Begin
If (AutoAddList = NIL) then exit;
If (Cfg^.NewAreasLst = '') then exit;
WriteLn('writing newareas.pt');
Assign(f, Cfg^.NewAreasLst);
{$I-} Append(f); {$I+}
If (IOResult <> 0) then
Begin
Assign(f, Cfg^.NewAreasLst);
{$I-} ReWrite(f); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t open "'+ Cfg^.NewAreasLst+'"!');
Exit;
End;
End;
CurAutoAddList := AutoAddList;
While (CurAutoAddList <> NIL) do
Begin
WriteLn(f, CurAutoAddList^.Name);
CurAutoAddList := CurAutoAddList^.Next;
End;
Close(f);
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t close "'+ Cfg^.NewAreasLst+'"!');
End
Else
Begin
{$IfDef UNIX}
ChMod(Cfg^.NewAreasLst, FilePerm);
{$EndIf}
End;
End;
Procedure WriteTossArea;
Var
f: Text;
Error1, Error2: Integer;
Begin
If (TossList = NIL) then exit;
If (Cfg^.AreasLog = '') then exit;
Assign(f, Cfg^.AreasLog);
{$I-} Append(f); {$I+}
Error1 := IOResult;
If (Error1 <> 0) then
Begin
Assign(f, Cfg^.AreasLog);
{$I-} ReWrite(f); {$I+}
Error2 := IOResult;
If (Error2 <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t open '+ Cfg^.AreasLog +
': Error '+IntToStr(Error1)+', '+IntToStr(Error2)+'!');
Exit;
End;
End;
CurTossList := TossList;
While (CurTossList <> NIL) do
Begin
WriteLn(f, CurTossList^.Name);
CurTossList := CurTossList^.Next;
End;
Close(f);
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t close '+ Cfg^.AreasLog+ '!');
End
Else
Begin
{$IfDef UNIX}
ChMod(Cfg^.AreasLog, FilePerm);
{$EndIf}
End;
End;
Procedure WriteBBSArea;
Var
f: Text;
Error1, Error2: Integer;
Begin
If (TossList = NIL) then exit;
If (Cfg^.BBSAreaLog = '') then exit;
Assign(f, Cfg^.BBSAreaLog);
{$I-} Append(f); {$I+}
Error1 := IOResult;
If (Error1 <> 0) then
Begin
Assign(f, Cfg^.BBSAreaLog);
{$I-} ReWrite(f); {$I+}
Error2 := IOResult;
If (Error2 <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t open '+ Cfg^.BBSAreaLog +
': Error '+IntToStr(Error1)+', '+IntToStr(Error2)+'!');
Exit;
End;
End;
CurTossList := TossList;
While (CurTossList <> NIL) do
Begin
If (CurTossList^.BBSArea = '') then WriteLn(f, CurTossList^.Name)
Else WriteLn(f, CurTossList^.BBSArea);
CurTossList := CurTossList^.Next;
End;
Close(f);
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t close '+ Cfg^.BBSAreaLog + '!');
End
Else
Begin
{$IfDef UNIX}
ChMod(Cfg^.BBSAreaLog, FilePerm);
{$EndIf}
End;
End;
Procedure AddAutoArea(Name: String);
Begin
If (AutoAddList = NIL) then
Begin
New(AutoAddList);
CurAutoAddList := AutoAddList;
CurAutoAddList^.Next := NIL;
CurAutoAddList^.Prev := NIL;
CurAutoAddList^.Name := Name;
End
Else
Begin
CurAutoAddList := AutoAddList;
Repeat
If CurAutoAddList^.Name = Name then Break;
If CurAutoAddList^.Next <> NIL then CurAutoAddList := CurAutoAddList^.Next
Else Break;
Until False;
If (CurAutoAddList^.Name <> Name) then
Begin
New(CurAutoAddList^.Next);
CurAutoAddList^.Next^.Prev := CurAutoAddList;
CurAutoAddList := CurAutoAddList^.Next;
CurAutoAddList^.Next := NIL;
CurAutoAddList^.Name := Name;
End;
End;
End;
Procedure AddTossArea(Name, BBSArea: String);
Begin
If (TossList = NIL) then
Begin
New(TossList);
CurTossList := TossList;
CurTossList^.Next := NIL;
CurTossList^.Prev := NIL;
CurTossList^.Name := Name;
CurTossList^.BBSArea := BBSArea;
End
Else
Begin
CurTossList := TossList;
Repeat
If CurTossList^.Name = Name then Break;
If CurTossList^.Next <> NIL then CurTossList := CurTossList^.Next
Else Break;
Until False;
If (CurTossList^.Name <> Name) then
Begin
New(CurTossList^.Next);
CurTossList^.Next^.Prev := CurTossList;
CurTossList := CurTossList^.Next;
CurTossList^.Next := NIL;
CurTossList^.Name := Name;
CurTossList^.BBSArea := BBSArea;
End;
End;
End;
Procedure DelAll(Dir: String);
Var
f: File;
{$IfDef SPEED}
SRec: TSearchRec;
{$Else}
SRec: SearchRec;
{$EndIf}
Begin
{$IfDef VER70}
FindFirst(Dir + DirSep + '*.*', AnyFile - Directory, SRec);
{$Else}
FindFirst(Dir + DirSep + '*', AnyFile - Directory, SRec);
{$EndIf}
While (DOSError = 0) do
Begin
WriteLn('deleting "'+Dir+DirSep+SRec.Name+'"');
Assign(f, Dir+DirSep+SRec.Name);
{$I-} Erase(f); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Could not delete "'+Dir+DirSep+SRec.Name+'"!');
End;
FindNext(SRec);
End;
{$IfDef OS2}
FindClose(SRec);
{$EndIf}
End;
Procedure DelPT;
Var
f: File;
Error: Integer;
DoEnd: Boolean;
PTC, PTCC: PPTList;
{$IfDef SPEED}
SRec: TSearchRec;
{$Else}
SRec: SearchRec;
{$EndIf}
Procedure ReadList;
Begin
New(PTC);
PTCC := PTC;
PTCC^.Prev := NIL;
PTCC^.Next := NIL;
Read(PTList, PTCC^.a);
While not EOF(PTList) Do
Begin
New(PTCC^.Next);
PTCC^.Next^.Prev := PTCC;
PTCC := PTCC^.Next;
PTCC^.Next := NIL;
Read(PTList, PTCC^.a);
End;
{$I-} Close(PTList); {$I+}
If (IOResult <> 0) then
Begin
LogSetCurLevel(LogHandle, 1);
LogWriteLn(LogHandle, 'Couldn''t close PTList!');
End;
End;
Procedure Sort; {Bubblesort}
Var
Swapped: Boolean;
Procedure Swap(var a, b: TPTListEntry);
Var
c: TPTListEntry;
Begin
c := a;
a := b;
b := c;
End;
Begin
Repeat
PTCC := PTC;
Swapped := False;
While (PTCC^.Next <> NIL) do With PTCC^ do
Begin
If a.FileName > PTCC^.Next^.a.FileName then
Begin
Swap(PTCC^.a, PTCC^.Next^.a);
Swapped := True;
End;
PTCC := PTCC^.Next;
End;
Until not Swapped;
End;
Procedure DispList;
Begin
If PTC = NIL then Exit;
PTCC := PTC;
Repeat
If PTCC^.Next <> Nil then PTCC := PTCC^.Next
Else If PTCC^.Prev <> Nil then
Begin
PTCC := PTCC^.Prev;
Dispose(PTCC^.Next);
PTCC^.Next := Nil;
End;
Until (PTCC = PTC);
Dispose(PTC);
PTC := NIL;
PTCC := NIL;
End;
Function Search(fn: String):Boolean;
Var
p: Pointer;
a1: TNetAddr;
Begin
Search := False;
PTCC := PTC;
While (PTCC <> NIL) and (PTCC^.Next <> NIL) do
Begin
{$IfDef UNIX}
If (PTCC^.a.FileName = fn) then
{$Else}
If (UpStr(PTCC^.a.FileName) = UpStr(fn)) then
{$EndIf}
Begin
If (PTCC^.a.TICName[1] = '!') then
Begin
CurUser := Cfg^.Users;
Str2Addr(Copy(PTCC^.a.TICName, 2, Length(PTCC^.a.TICName)-1), a1);