-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointlst.pas
2580 lines (2477 loc) · 92 KB
/
pointlst.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 PointLst;
INTERFACE
{$I VERSION.INC}
Uses
Use32,
Objects,StrUnit,Dos,Incl,Address,Logger,Parser,Memory,{TpDos,}Validate,MCommon,
Crc_32,Face,Os_Type,FileIO,PntL_Obj
{$IFDEF SPLE}
,Ple_Incl,
PBar,
MsgBox
{$ELSE}
,Script
{$ENDIF}
;
Const
EBossTag='BOSS,';
EPointTag='POINT,';
ZoneTag='ZONE';
RegionTag='REGION';
HostTag='HOST';
DownTag='DOWN';
HoldTag='HOLD';
PvtTag='PVT';
POS_COMMENT=1;
POS_BOSS=2;
POS_POINT=4;
POS_SKIP=8;
POS_ERROR=16;
Var
CurrentPoints:PPointsCollection;
CurrentComments:PCommentsCollection;
{$IFNDEF SPLE}
BossRecArray:PBossRecSortedCollection;
{$ENDIF}
IsBossFoundInSegment:Boolean;
SegmentBossString:String;
MessageBody:PMessageBody;
PSegmentErrorsMap:PMessageBody;
PMessageErrorsMap:PMessageBody;
_flgPointListOpened:Boolean;
{PntListName:String;}
Validat:PPXPictureValidator;
Validator:PPXPictureValidator;
{Const
_fattrNull=0;
_fattrSystem=1;
_fattrModem=2;
_fattrCompress=4;
_fattrMailer=8;
_fattrUser=16;}
Type
PFlagRecord=^TFlagRecord;
TFlagRecord=Object(TObject)
PFlag:PString;
TStringOffset:Word; {reserved}
{ TAttrib:Word;}
Constructor Init(AString:String;AOffset:Word);
Destructor Done;Virtual;
End;
Type
PPointStringFlags=^TPointStringFlags;
TPointStringFlags=Object(TCollection)
{ Destructor Done;Virtual;}
End;
Type
PPointStringRecord=^TPointStringRecord;
TPointStringRecord=Object(TObject)
PSignature,
PNumber,
PStationName,
PLocation,
PSysOpName,
PPhone,
PSpeed:PString;
PFlags:PPointStringFlags;
{ PErrorsMap:PMessageBody;}
{ Function GetStringField(Var AString:String;Var BeginPos:Word):String;}
Function NewField(S:String):PString;
Procedure DisposeField(P:PString);
Constructor Init(AString:String);
Destructor Done;Virtual;
End;
Function InitPointList(PointListName:String):Boolean;
Procedure ReadPointListToMemory(Var PointList:Text);
Procedure WritePointListToDisk;
Function SearchForBoss(BossAddr:TAddress):Integer;
Function DeleteBossByIndex(Index:Integer):Boolean;
Function DeleteBossByAddress(Addr:TAddress):Boolean;
Function GetStringField(Var AString:String;Var BeginPos:Word;Var StringPos:Word):String;
{Function IsPointStringValid(Var S:String):Boolean;}
Function IsValidPointString(BossStr:String;S:String;Var PErrorsMap:PMessageBody):Boolean;
{Procedure CollectErrorsInMessage(WrongString:String;Flag:Word);}
{Procedure LogErrorsMap(PErrorsMap:PMessageBody);}
{Procedure CollectErrorsInPointList_(ListName:String;WrongString:String;Flag:Word);}
Function ProcessPoint(BossIndex:Integer;Point:String;Flag:Integer):Integer;
Function ReplaceBossComments(BossIndex:Integer;NewComments:PCommentsCollection):Boolean;
Function GetBossAddressByIndex(Index:Integer):String;
Procedure LoadExcludeList;
Function IsInExcludeList(BossStr:String):Boolean;
Procedure GetLoHiChars(Var LoChar,HiChar:Char);
IMPLEMENTATION
Procedure GetLoHiChars(Var LoChar,HiChar:Char);
Var
Posit:Byte;
_LoChar,_HiChar:String;
Tmp:String;
Begin
Tmp:=GetVar(AllowedCharsTag.Tag,_varNONE);
Tmp:=StrUp(StrTrim(Tmp));
Posit:=Pos('..',Tmp);
LoChar:=#33;
HiChar:=#126;
If Posit=0 Then
Begin
Exit;
End
Else
Begin
_LoChar:=StrTrim(Copy(Tmp,1,Posit-1));
_HiChar:=StrTrim(Copy(Tmp,Posit+2,Length(Tmp)));
If _LoChar<>'' Then
{ LoChar:=Char(Byte(StrToInt(_LoChar)));}
LoChar:=Char(Byte(StrToInt(_LoChar)));
If _HiChar<>'' Then
{ HiChar:=ByteToChar(Byte(StrToInt(_HiChar)));}
HiChar:=Chr(Byte(StrToInt(_HiChar)));
End;
End;
Function IsItTXXFlag(S:String):Boolean;
Begin
IsItTXXFlag:=False;
If (S[1]='U') And (S[2]='T') And ((S[3] in ['a'..'z']) or (S[3] in ['A'..'Z'])) And
((S[4] in ['a'..'z']) or (S[4] in ['A'..'Z'])) Then
IsItTXXFlag:=True;
End;
Procedure UpCaseFlags(Var PFlags:PPointStringFlags;ExcludeTXXFlag:Boolean);
Var
PFlag:PFlagRecord;
Counter:Integer;
Begin
If PFlags<>Nil Then
Begin
For Counter:=0 To Pred(PFlags^.Count) Do
Begin
PFlag:=PFlags^.At(Counter);
If ExcludeTXXFlag Then
Begin
If Not IsItTXXFlag(PFlag^.PFlag^) Then
PFlag^.PFlag^:=StrUp(PFlag^.PFlag^);
End
Else
PFlag^.PFlag^:=StrUp(PFlag^.PFlag^);
End;
End;
End;
Constructor TFlagRecord.Init(AString:String;AOffset:Word);
Begin
Inherited Init;
If StrTrim(AString)<>'' Then
Begin
PFlag:=MCommon.NewStr(AString);
TStringOffset:=AOffset;
{ TAttrib:=_fattrNull;}
{ System.Delete(AString,1,EndPos);}
End
Else
Begin
PFlag:=Nil;
TStringOffset:=0;
{ TAttrib:=_fattrNull;}
{ AString:='';}
End
End;
Destructor TFlagRecord.Done;
Begin
If PFlag<>Nil Then
Begin
DisposeStr(PFlag);
PFlag:=Nil;
End;
Inherited Done;
End;
Function GetStringField(Var AString:String;Var BeginPos:Word;Var StringPos:Word):String;
Var
EndPos:Word;
Begin
If BeginPos=0 Then
Begin
GetStringField:='';
Exit;
End;
EndPos:=Pos(',',Copy(AString,BeginPos,Length(AString)))+BeginPos;
If (EndPos<>0) And (EndPos<>BeginPos) Then
Begin
GetStringField:=Copy(AString,BeginPos,EndPos-BeginPos-1);
StringPos:=BeginPos;
BeginPos:=EndPos;
End
Else
Begin
GetStringField:=Copy(AString,BeginPos,Length(AString));
StringPos:=StringPos+(EndPos-StringPos);
BeginPos:=0;
End;
End;
Function TPointStringRecord.NewField(S:String):PString;
Begin
If StrTrim(S)<>'' Then
NewField:=MCommon.NewStr(S)
Else
NewField:=Nil;
End;
Procedure TPointStringRecord.DisposeField(P:PString);
Begin
If P<>Nil Then
Begin
DisposeStr(P);
P:=Nil;
End;
End;
Constructor TPointStringRecord.Init(AString:String);
Var
BeginPos,EndPos,StringPos:Word;
Begin
Inherited Init;
PSignature:=Nil;
PNumber:=Nil;
PStationName:=Nil;
PLocation:=Nil;
PSysOpName:=Nil;
PPhone:=Nil;
PSpeed:=Nil;
PFlags:=Nil;
{ PErrorsMap:=Nil;}
If StrTrim(AString)='' Then
Exit;
BeginPos:=1;
StringPos:=1;
PSignature:=NewField(GetStringField(AString,BeginPos,StringPos));
If PSignature<>Nil Then
Begin
PSignature^:=StrDown(PSignature^);
PSignature^[1]:=UpCase(PSignature^[1]);
End;
PNumber:=NewField(GetStringField(AString,BeginPos,StringPos));
PStationName:=NewField(GetStringField(AString,BeginPos,StringPos));
PLocation:=NewField(GetStringField(AString,BeginPos,StringPos));
PSysOpName:=NewField(GetStringField(AString,BeginPos,StringPos));
PPhone:=NewField(GetStringField(AString,BeginPos,StringPos));
PSpeed:=NewField(GetStringField(AString,BeginPos,StringPos));
If BeginPos<>0 Then
Begin
PFlags:=New(PPointStringFlags,Init(5,5));
While BeginPos>0 Do
Begin
PFlags^.Insert(
New(PFlagRecord,Init(GetStringField(AString,BeginPos,StringPos),StringPos)));
End;
End;
End;
Destructor TPointStringRecord.Done;
Begin
DisposeField(PSignature);
DisposeField(PNumber);
DisposeField(PStationName);
DisposeField(PLocation);
DisposeField(PSysOpName);
DisposeField(PPhone);
DisposeField(PSpeed);
If PFlags<>Nil Then
PFlags^.Done;
Inherited Done;
{ If PErrorsMap<>Nil Then
PErrorsMap^.Done;}
End;
Var
IsEventFound:Boolean;
WhatDoOnEvent:Byte;
OnWhatString:String;
Procedure ForEachEvent(Pnt:Pointer);
Var
Event,WhatDo:String;
Begin
If IsEventFound Then
Exit;
If Pnt=Nil Then
Exit;
GetTwoTrimmedParamsFromString(PString(Pnt)^,Event,WhatDo);
Event:=StrUp(StrTrim(Event));
WhatDo:=StrUp(StrTrim(WhatDo));
If (Event='') Or (WhatDo='') Then
Exit;
If OnWhatString=Event Then
Begin
IsEventFound:=True;
If WhatDo=ErrorTag Then
WhatDoOnEvent:=_evtError
Else
If WhatDo=WarningTag Then
WhatDoOnEvent:=_evtWarning
Else
If WhatDo=IgnoreTag Then
WhatDoOnEvent:=_evtIgnore;
End;
End;
Function GetWhatDoOnEvent(OnWhat:String):Byte;
Begin
IsEventFound:=False;
GetWhatDoOnEvent:=_evtError;
WhatDoOnEvent:=_evtError;
OnWhatString:=OnWhat;
ForEachVar(EventTag.Tag,ForEachEvent);
GetWhatDoOnEvent:=WhatDoOnEvent;
End;
Var
IsValidPhone,
IsValidSpeed:Boolean;
Procedure ForEachPhoneMask(Pnt:Pointer;Data:Pointer);
Var
Pict,Phone:String;
Begin
If IsValidPhone Then
Exit;
Pict:=PString(Pnt)^;
Phone:=PString(Data)^;
If StrTrim(Pict)='' Then
Exit;
{ If Validator= Nil Then
Validator:=New(PPxPictureValidator,Init(' ',False));
Validator^.Pic:=PString(Pnt);}
If Validator= Nil Then
Validator:=New(PPxPictureValidator,Init(Pict,False))
Else
Begin
If Validator^.Pic<>Nil Then
DisposeStr(Validator^.Pic);
Validator^.Pic:=MCommon.NewStr(Pict);
End;
DoUpCase:=False;
IsValidPhone:=Validator^.IsValid(Phone)=True;
End;
Procedure ForEachSpeed(Pnt:Pointer;Data:Pointer);
Var
Pict,Speed:String;
Begin
If IsValidSpeed Then
Exit;
Pict:=PString(Pnt)^;
Speed:=PString(Data)^;
If StrTrim(Pict)='' Then
Exit;
{ If Validator= Nil Then
Validator:=New(PPxPictureValidator,Init(' ',False));
Validator^.Pic:=PString(Pnt);}
If Validator= Nil Then
Validator:=New(PPxPictureValidator,Init(Pict,False))
Else
Begin
If Validator^.Pic<>Nil Then
DisposeStr(Validator^.Pic);
Validator^.Pic:=MCommon.NewStr(Pict);
End;
DoUpCase:=False;
IsValidSpeed:=Validator^.IsValid(Speed)=True;
End;
Function GetSystemFlags(AllFlags:PPointStringFlags):PPointStringFlags;
Var
Counter:Integer;
Result_:PPointStringFlags;
PTempFlag:PFlagRecord;
Begin
GetSystemFlags:=Nil;
Result_:=Nil;
If AllFlags<>Nil Then
Begin
For Counter:=0 To Pred(AllFlags^.Count) Do
Begin
PTempFlag:=AllFlags^.At(Counter);
If PTempFlag^.PFlag<>Nil Then
Begin
If PTempFlag^.PFlag^='U' Then
Break;
If Result_=Nil Then
Result_:=New(PPointStringFlags,Init(3,3));
Result_^.Insert(New(PFlagRecord,Init(PTempFlag^.PFlag^,PTempFlag^.TStringOffset)));
End;
End;
End;
GetSystemFlags:=Result_;
End;
Function GetUserFlags(AllFlags:PPointStringFlags):PPointStringFlags;
Var
Counter:Integer;
Result_:PPointStringFlags;
PTempFlag:PFlagRecord;
IsUserFlagsPresent:Boolean;
Begin
GetUserFlags:=Nil;
Result_:=Nil;
IsUserFlagsPresent:=False;
If AllFlags<>Nil Then
Begin
For Counter:=0 To Pred(AllFlags^.Count) Do
Begin
PTempFlag:=AllFlags^.At(Counter);
If PTempFlag^.PFlag<>Nil Then
Begin
If IsUserFlagsPresent Then
Begin
If Result_=Nil Then
Result_:=New(PPointStringFlags,Init(3,3));
Result_^.Insert(New(PFlagRecord,Init('U'+PTempFlag^.PFlag^,PTempFlag^.TStringOffset)));
End;
If PTempFlag^.PFlag^='U' Then
IsUserFlagsPresent:=True;
End;
End;
End;
GetUserFlags:=Result_;
End;
Function CheckForDupeFlags(SystemFlags,UserFlags:PPointStringFlags):PPointStringFlags;
Var
Result_:PPointStringFlags;
Counter,Counter1:Integer;
PTempFlag:PFlagRecord;
Begin
CheckForDupeFlags:=Nil;
Result_:=Nil;
If SystemFlags<>Nil Then
Begin
For Counter:=0 To Pred(SystemFlags^.Count) Do
Begin
PTempFlag:=SystemFlags^.At(Counter);
If PTempFlag^.PFlag<>Nil Then
Begin
For Counter1:=0 To Pred(SystemFlags^.Count) Do
Begin
If (Counter<>Counter1) And (PFlagRecord(SystemFlags^.At(Counter1))^.PFlag<>Nil) Then
Begin
If PTempFlag^.PFlag^=PFlagRecord(SystemFlags^.At(Counter1))^.PFlag^ Then
Begin
If Result_=Nil Then
Result_:=New(PPointStringFlags,Init(1,1));
Result_^.Insert(New(PFlagRecord,Init(PFlagRecord(SystemFlags^.At(Counter1))^.PFlag^,
PFlagRecord(SystemFlags^.At(Counter1))^.TStringOffset)));
End;
End;
End;
End;
End;
End;
If UserFlags<>Nil Then
Begin
For Counter:=0 To Pred(UserFlags^.Count) Do
Begin
PTempFlag:=UserFlags^.At(Counter);
If PTempFlag^.PFlag<>Nil Then
Begin
For Counter1:=0 To Pred(UserFlags^.Count) Do
Begin
If (Counter<>Counter1) And (PFlagRecord(UserFlags^.At(Counter1))^.PFlag<>Nil) Then
Begin
If PTempFlag^.PFlag^=PFlagRecord(UserFlags^.At(Counter1))^.PFlag^ Then
Begin
If Result_=Nil Then
Result_:=New(PPointStringFlags,Init(1,1));
Result_^.Insert(New(PFlagRecord,Init(PFlagRecord(UserFlags^.At(Counter1))^.PFlag^,
PFlagRecord(UserFlags^.At(Counter1))^.TStringOffset)));
End;
End;
End;
End;
End;
End;
CheckForDupeFlags:=Result_;
End;
Var
_IsValidSystemFlag,
_IsValidUserFlag:Boolean;
Procedure ForEachSystemFlags(Point:Pointer;Data:Pointer);
Var
Pict,Flag:String;
Begin
If _IsValidSystemFlag Then
Exit;
If Data=Nil Then
Exit;
Pict:=PString(Point)^;
Flag:=PString(Data)^;
If StrTrim(Pict)='' Then
Exit;
If Validator= Nil Then
Validator:=New(PPxPictureValidator,Init(Pict,False))
Else
Begin
If Validator^.Pic<>Nil Then
DisposeStr(Validator^.Pic);
Validator^.Pic:=MCommon.NewStr(Pict);
End;
DoUpCase:=False;
_IsValidSystemFlag:=Validator^.IsValid(Flag)=True;
End;
Procedure ForEachUserFlags(Point:Pointer;Data:Pointer);
Var
Pict,Flag:String;
Begin
If _IsValidUserFlag Then
Exit;
If Data=Nil Then
Exit;
Pict:=PString(Point)^;
Flag:=PString(Data)^;
If StrTrim(Pict)='' Then
Exit;
If Validator= Nil Then
Validator:=New(PPxPictureValidator,Init(Pict,False))
Else
Begin
If Validator^.Pic<>Nil Then
DisposeStr(Validator^.Pic);
Validator^.Pic:=MCommon.NewStr(Pict);
End;
DoUpCase:=False;
_IsValidUserFlag:=Validator^.IsValid(Flag)=True;
End;
Function CheckSystemFlags(SystemFlags:PPointStringFlags):PPointStringFlags;
Var
Counter:Integer;
Result_:PPointStringFlags;
Begin
_IsValidSystemFlag:=False;
Result_:=Nil;
If SystemFlags<>Nil Then
Begin
For Counter:=0 To Pred(SystemFlags^.Count) Do
Begin
ForEachVarWithData(SystemFlagsTag.Tag,PFlagRecord(SystemFlags^.At(Counter))^.PFlag,ForEachSystemFlags);
If Not _IsValidSystemFlag Then
Begin
If Result_=Nil Then
Result_:=New(PPointStringFlags,Init(1,1));
Result_^.Insert(New(PFlagRecord,Init(
PFlagRecord(SystemFlags^.At(Counter))^.PFlag^,
PFlagRecord(SystemFlags^.At(Counter))^.TStringOffset
)));
_IsValidSystemFlag:=False;
End
Else
Begin
_IsValidSystemFlag:=False;
End;
End;
End;
CheckSystemFlags:=Result_;
End;
Function CheckUserFlags(UserFlags:PPointStringFlags):PPointStringFlags;
Var
Counter:Integer;
Result_:PPointStringFlags;
Begin
_IsValidUserFlag:=False;
Result_:=Nil;
If UserFlags<>Nil Then
Begin
For Counter:=0 To Pred(UserFlags^.Count) Do
Begin
ForEachVarWithData(UserFlagsTag.Tag,PFlagRecord(UserFlags^.At(Counter))^.PFlag,ForEachUserFlags);
If Not _IsValidUserFlag Then
Begin
If Result_=Nil Then
Result_:=New(PPointStringFlags,Init(1,1));
Result_^.Insert(New(PFlagRecord,Init(
PFlagRecord(UserFlags^.At(Counter))^.PFlag^,
PFlagRecord(UserFlags^.At(Counter))^.TStringOffset
)));
_IsValidUserFlag:=False;
End
Else
Begin
_IsValidUserFlag:=False;
End;
End;
End;
CheckUserFlags:=Result_;
End;
Function IsTXXFlagPresent(Flags:PPointStringFlags;Var FlagPos:Byte;Var Flag:String):Boolean;
Var
Counter:Integer;
Begin
IsTXXFlagPresent:=False;
FlagPos:=0;
Flag:='';
If (Flags=Nil) Then
Exit;
For Counter:=0 To Pred(Flags^.Count) Do
Begin
If (PFlagRecord(Flags^.At(Counter))^.PFlag<>Nil) And
(Copy(PFlagRecord(Flags^.At(Counter))^.PFlag^,1,2)='UT') And
(Length(PFlagRecord(Flags^.At(Counter))^.PFlag^)=4) And
((PFlagRecord(Flags^.At(Counter))^.PFlag^[3] In ['a'..'z']) Or
(PFlagRecord(Flags^.At(Counter))^.PFlag^[3] In ['A'..'Z'])) And
((PFlagRecord(Flags^.At(Counter))^.PFlag^[4] In ['a'..'z']) Or
(PFlagRecord(Flags^.At(Counter))^.PFlag^[4] In ['A'..'Z'])) Then
Begin
FlagPos:=PFlagRecord(Flags^.At(Counter))^.TStringOffset;
Flag:=PFlagRecord(Flags^.At(Counter))^.PFlag^;
IsTXXFlagPresent:=True;
Break;
End;
End;
End;
Function IsFlagsContainsFlag(Flags:PPointStringFlags;Flag:String;Var FlagPos:Byte):Boolean;
Var
Counter:Integer;
Begin
IsFlagsContainsFlag:=False;
FlagPos:=0;
If (Flags=Nil) Or (StrTrim(Flag)='') Then
Exit;
For Counter:=0 To Pred(Flags^.Count) Do
Begin
If (PFlagRecord(Flags^.At(Counter))^.PFlag<>Nil) And
(PFlagRecord(Flags^.At(Counter))^.PFlag^=Flag) Then
Begin
FlagPos:=PFlagRecord(Flags^.At(Counter))^.TStringOffset;
IsFlagsContainsFlag:=True;
Break;
End;
End;
End;
Function CheckRedundantFlags(SystemFlags,UserFlags:PPointStringFlags):PMessageBody;
Var
Result_:PMessageBody;
ImpliesCollection:PValueCollection;
Counter,Counter1:Integer;
OneFlag,RedundantFlags,OneOfRedundant:String;
BeginPos,StringPos:Word;
FlagPos:Byte;
Begin
Result_:=Nil;
ImpliesCollection:=Nil;
BeginPos:=1;
ImpliesCollection:=GetValueCollectionPointer(ImpliesFlagsTag);
If ImpliesCollection<>Nil Then
Begin
For Counter:=0 To Pred(ImpliesCollection^.Count) Do
Begin
GetTwoTrimmedParamsFromString(PString(ImpliesCollection^.At(Counter))^,OneFlag,RedundantFlags);
If IsFlagsContainsFlag(SystemFlags,OneFlag,FlagPos) Then
Begin
While BeginPos>0 Do
Begin
OneOfRedundant:=GetStringField(RedundantFlags,BeginPos,StringPos);
If (IsFlagsContainsFlag(SystemFlags,OneOfRedundant,FlagPos) or
IsFlagsContainsFlag(UserFlags,OneOfRedundant,FlagPos)) Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Redundant flag ['+OneOfRedundant+'] at position ['+IntToStr(FlagPos)+
'] implies into flag ['+OneFlag+']'));
End
Else
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Излишний флаг ['+OneOfRedundant+'] по смещению ['+IntToStr(FlagPos)+
'] уже подразумевается флагом ['+OneFlag+']'));
End;
End
Else
Begin
If (Copy(OneOfRedundant,1,2)='UT') And
(Length(OneOfRedundant)=4) Then
Begin
If IsTXXFlagPresent(UserFlags,FlagPos,OneOfRedundant) Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Redundant flag ['+OneOfRedundant+'] at position ['+IntToStr(FlagPos)+
'] implies into flag ['+OneFlag+']'));
End
Else
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Излишний флаг ['+OneOfRedundant+'] по смещению ['+IntToStr(FlagPos)+
'] уже подразумевается флагом ['+OneFlag+']'));
End;
End;
End;
End;
End;
BeginPos:=1;
End
Else
If IsFlagsContainsFlag(UserFlags,OneFlag,FlagPos) Then
Begin
BeginPos:=1;
While BeginPos>0 Do
Begin
OneOfRedundant:=GetStringField(RedundantFlags,BeginPos,StringPos);
If (IsFlagsContainsFlag(UserFlags,OneOfRedundant,FlagPos) or
IsFlagsContainsFlag(SystemFlags,OneOfRedundant,FlagPos)) Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Redundant flag ['+OneOfRedundant+'] at position ['+IntToStr(FlagPos)+
'] implies into flag ['+OneFlag+']'));
End
Else
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Излишний флаг ['+OneOfRedundant+'] по смещению ['+IntToStr(FlagPos)+
'] уже подразумевается флагом ['+OneFlag+']'));
End;
End
Else
Begin
If (Copy(OneOfRedundant,1,2)='UT') And
(Length(OneOfRedundant)=4) Then
Begin
If IsTXXFlagPresent(UserFlags,FlagPos,OneOfRedundant) Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Redundant flag ['+OneOfRedundant+'] at position ['+IntToStr(FlagPos)+
'] implies into flag ['+OneFlag+']'));
End
Else
Begin
If Result_=Nil Then
Result_:=New(PMessageBody,Init(2,2));
Result_^.Insert(NewStr(' · Излишний флаг ['+OneOfRedundant+'] по смещению ['+IntToStr(FlagPos)+
'] уже подразумевается флагом ['+OneFlag+']'));
End;
End;
End;
End;
End;
End;
End;
End;
CheckRedundantFlags:=Result_;
End;
Function IsValidPointString(BossStr:String;S:String;Var PErrorsMap:PMessageBody):Boolean;
Var
PPointString:PPointStringRecord;
LoChar,HiChar:Char;
PntStringInMap:Boolean;
BeginPos,EndPos:Word;
Counter:Word;
{ErrorsCounter:Word;}
SystemFlags,
UserFlags,DupeFlags,
NotValidSystemFlags,
NotValidUserFlags:PPointStringFlags;
RedundantFlags:PMessageBody;
GarbagePos,LastGarbagePos:Byte;
WhatDoOnError:Byte;
Procedure PutPntStringAtMap;
Begin
{$IFNDEF SPLE}
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr('File: '+GetFNameAndExt(PntListName)))
Else
PErrorsMap^.Insert(NewStr('Файл: '+GetFNameAndExt(PntListName)));
If (PPointString<>Nil) And (PPointString^.PNumber<>Nil) Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr('Pointstring ('+
GetStringAddressFromString(BossStr)+'.'+PPointString^.PNumber^+') contains errors: '))
Else
PErrorsMap^.Insert(NewStr('Поинтстрока ('+
GetStringAddressFromString(BossStr)+'.'+PPointString^.PNumber^+') содержит ошибки: '))
End
Else
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr('Pointstring ('+GetStringAddressFromString(BossStr)+'.?) contains errors: '))
Else
PErrorsMap^.Insert(NewStr('Поинтстрока ('+GetStringAddressFromString(BossStr)+'.?) содержит ошибки: '));
End;
PErrorsMap^.Insert(NewStr(RArrow+S));
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr('Errors:'))
Else
PErrorsMap^.Insert(NewStr('Ошибки:'));
If StrUp(GetVar(LogPntStringErrorsTag.Tag,_varNONE))=Yes Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('!File: '+GetFNameAndExt(PntListName))
Else
LogWriteLn('!Файл: '+GetFNameAndExt(PntListName));
If (PPointString<>Nil) And (PPointString^.PNumber<>Nil) Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('!Pointstring ('+
GetStringAddressFromString(BossStr)+'.'+PPointString^.PNumber^+') contains errors: ')
Else
LogWriteLn('!Поинтстрока ('+
GetStringAddressFromString(BossStr)+'.'+PPointString^.PNumber^+') содержит ошибки: ')
End
Else
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('!Pointstring ('+GetStringAddressFromString(BossStr)+'.?) contains errors: ')
Else
LogWriteLn('!Поинтстрока ('+GetStringAddressFromString(BossStr)+'.?) содержит ошибки: ')
End;
LogWriteLn('!'+RArrow+S);
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('!Errors:')
Else
LogWriteLn('!Ошибки:')
End;
PntStringInMap:=True;
{$ENDIF}
End;
Begin
IsValidPointString:=True;
{ErrorsCounter:=0;}
GarbagePos:=0;
LastGarbagePos:=0;
IsValidPhone:=False;
IsValidSpeed:=False;
PntStringInMap:=False;
WhatDoOnError:=_evtError;
PPointString:=Nil;
UserFlags:=Nil;
SystemFlags:=Nil;
DupeFlags:=Nil;
NotValidSystemFlags:=Nil;
NotValidUserFlags:=Nil;
RedundantFlags:=Nil;
If StrTrim(S)='' Then
Begin
IsValidPointString:=False;
Exit;
End;
If PErrorsMap=Nil Then
PErrorsMap:=New(PMessageBody,Init(5,5));
{************ Поиск пpобелов и недопyстимых символов***********}
If StrTrim(PntListName)='' Then
PntListName:='MESSAGE';
GetLoHiChars(LoChar,HiChar);
For Counter:=1 To Length(S) Do
Begin
If Not (S[Counter] In [LoChar..HiChar]) Then
Begin
WhatDoOnError:=GetWhatDoOnEvent(BadCharacterTag);
If WhatDoOnError=_evtError Then
IsValidPointString:=False;
{ Inc(ErrorsCounter);}
{$IFNDEF SPLE}
If WhatDoOnError<>_evtIgnore Then
Begin
If Not PntStringInMap Then
Begin
PutPntStringAtMap;
End;
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr(' ■ Bad character at position ['+
IntToStr(Counter)+']:'+S[Counter]))
Else
PErrorsMap^.Insert(NewStr(' ■ Недопустимый символ по смещению ['+
IntToStr(Counter)+']:'+S[Counter]));
If StrUp(GetVar(LogPntStringErrorsTag.Tag,_varNONE))=Yes Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('! ■ Bad character at position ['+
IntToStr(Counter)+']:'+S[Counter])
Else
LogWriteLn('! ■ Недопустимый символ по смещению ['+
IntToStr(Counter)+']:'+S[Counter])
End;
End;
{$ENDIF}
End;
End;
GarbagePos:=Pos(',,',S);
While GarbagePos>0 Do
Begin
WhatDoOnError:=GetWhatDoOnEvent(BadCharacterTag);
If WhatDoOnError=_evtError Then
IsValidPointString:=False;
{$IFNDEF SPLE}
If WhatDoOnError<>_evtIgnore Then
Begin
If Not PntStringInMap Then
Begin
PutPntStringAtMap;
End;
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr(' ■ Duplicate commas at position ['+
IntToStr(GarbagePos+LastGarbagePos)+']'))
Else
PErrorsMap^.Insert(NewStr(' ■ Повторяющиеся запятые по смещению ['+
IntToStr(GarbagePos+LastGarbagePos)+']'));
If StrUp(GetVar(LogPntStringErrorsTag.Tag,_varNONE))=Yes Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('! ■ Duplicate commas at position ['+
IntToStr(GarbagePos+LastGarbagePos)+']')
Else
LogWriteLn('! ■ Повторяющиеся запятые по смещению ['+
IntToStr(GarbagePos+LastGarbagePos)+']')
End;
End;
{$ENDIF}
LastGarbagePos:=GarbagePos+LastGarbagePos;
GarbagePos:=Pos(',,',Copy(S,LastGarbagePos+2,Length(S)));
Inc(LastGarbagePos);
End;
If (S[Length(S)]=',')
{$IFNDEF SPLE}
And (GetVar(SplitCharTag.Tag,_varNONE)<>',')
{$ENDIF}
Then
Begin
WhatDoOnError:=GetWhatDoOnEvent(BadCharacterTag);
If WhatDoOnError=_evtError Then
IsValidPointString:=False;
{$IFNDEF SPLE}
If WhatDoOnError<>_evtIgnore Then
Begin
If Not PntStringInMap Then
Begin
PutPntStringAtMap;
End;
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
PErrorsMap^.Insert(NewStr(' ■ String must not ends with comma'))
Else
PErrorsMap^.Insert(NewStr(' ■ Строка не должна оканчиваться запятой'));
If StrUp(GetVar(LogPntStringErrorsTag.Tag,_varNONE))=Yes Then
Begin
If StrUp(GetVar(LanguageTag.Tag,_varNONE))=EnglishTag Then
LogWriteLn('! ■ String must not ends with comma')
Else