-
Notifications
You must be signed in to change notification settings - Fork 10
/
advance1.pas
2055 lines (1904 loc) · 44.1 KB
/
advance1.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
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Open Source 1.51.08
// Based on Dos Navigator (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
{$I STDEFINE.INC}
{AK155 = Alexey Korop, 2:461/155@fidonet}
{Cat = Aleksej Kozlov, 2:5030/1326.13@fidonet}
{Cat
28/08/2001 - ¬®£¨¥ ¨¬¥î騥áï äãªæ¨¨ ¯¥à¥¤¥« « ¤«ï ᮢ¬¥á⨬®á⨠á ⨯®¬
AnsiString; ¤®¡ ¢¨« «®£¨çë¥ äãªæ¨¨, à ¡®â î騥 á ⨯®¬ LongString
16/01/2002 - äãªæ¨¨ ¯®¨áª áâப¨ ¢ ¡ãä¥à¥ ⥯¥àì ¯®«ãç îâ ¯ à ¬¥âàë ⨯
LongInt ¢¬¥áâ® Word
}
unit Advance1; {String functions}
interface
uses
Defines, Dos {Cat}
;
var
{‘«¥¤ãî騥 âਠ⠡«¨æë ¨á¯®«ì§ãîâáï ¢¬¥áâ® XlatCP ¤«ï "¯¥à¥ª®¤¨à®¢ª¨"
Ascii-Ascii (á¬. ¯¥à¢ë¥ í«¥¬¥âë KeyMapDescr). ®í⮬㠮¨ ¤®«¦ë
¯à¨áãâá⢮¢ âì ¢á¥ âà¨, ¨ ¨¬¥® ¢ â ª®¬ ¯®à浪¥. }
UpCaseArray: TXlat;
{` ¥à¥¢®¤ ¢¥à娩 ॣ¨áâà ¢ ASCII`}
NullXlatTable: TXlat;
{` ’®¦¤¥á⢥ ï ¯¥à¥ª®¤¨à®¢ª `}
NullXlatTable1: TXlat;
LowCaseArray: TXlat;
{` ¥à¥¢®¤ ¨¦¨© ॣ¨áâà ¢ ASCII`}
function NewStr(const S: String): PString;
function NewLongStr(const S: LongString): PLongString;
procedure DisposeStr(var P: PString);
procedure DisposeLongStr(var P: PLongString);
procedure ReplaceP(var P: PString; S: String);
function CnvString(P: PString): String; {conversion: PString to String}
function CnvLongString(P: PLongString): LongString;
{conversion: PLongString to LongString}
function StrGrd(AMax, ACur: TSize; Wide: Byte; Rev: Boolean): String;
function Percent(AMax, ACur: TSize): String;
{` ®áâ஥¨¥ áâப¨ ¢¨¤ 57%; ¤«¨ - ª ª ¯®«ãç¨âáï. `}
procedure Hex8Lo(L: LongInt; var HexLo);
procedure AddStr(var S: String; C: Char);
{procedure DelFC(var s:String);}
{--- ' '-related string functions }
function CenterStr(const s: String; n: Byte): String; {DataCompBoy}
function AddSpace(const s: String; n: Byte): String;
function LongAddSpace(const s: LongString; n: LongInt): LongString;
function PredSpace(s: String; n: Byte): String;
function DelSpaces(s: String): String;
procedure DelSpace(var s: String);
procedure DelRight(var S: String);
procedure LongDelRight(var S: LongString);
function fDelRight(s: String): String;
procedure DelLeft(var S: String);
procedure LongDelLeft(var S: LongString);
function fDelLeft(s: String): String;
function Cut(p: String; len: Integer): String;
function CutH(p: String; len: Integer): String;
function Strg(C: Char; Num: Byte): String;
{` ‘®§¤ âì áâப㠤«¨®© Num, § ¯®«¥ãî ᨬ¢®«®¬ C `}
function LongStrg(C: Char; Num: LongInt): LongString;
{` ‘®§¤ âì áâப㠤«¨®© Num, § ¯®«¥ãî ᨬ¢®«®¬ C `}
{case functions}
function UpCase(c: Char): Char;
procedure UpStr(var s: String);
function UpStrg(s: String): String;
function LowCase(c: Char): Char;
procedure LowStr(var s: String);
function LowStrg(s: String): String;
procedure UpLowStr(var s: String); {JO}
function UpLowStrg(s: String): String; {JO}
procedure CapStr(var S: String);
procedure CapLongStr(var S: LongString; First, Last: Integer);
function CapStrg(S: String): String;
function CapLongStrg(const S: LongString; First, Last: Integer): LongString;
{procedure MakeCase(CaseSensitive: Boolean);}
function ItoS(a: LongInt): String;
function ZtoS(a: TSize): String;
function RtoS(a: Real; M, F: Integer): String;
function StoI(const s: String): LongInt;
function SStr(a: LongInt; B: Byte; C: Char): String;
function SSt2(a: LongInt; B: Byte; C: Char): String;
function FStr(a: TSize): String;
{` ‘âப®¢®¥ ¯à¥¤áâ ¢«¥¨¥ à §¬¥à .
„«¨ १ã«ìâ â - ¥ ¡®«¥¥ 12 ᨬ¢®«®¢, ¢¥¤ãé¨å ¯à®¡¥«®¢ ¥â.
’ਠ¤ë à §¤¥«ïîâáï ¢ ᮮ⢥âá⢨¨ á áâனª ¬¨ áâà ë `}
function FileSizeStr(X: TSize): String;
{` ‘âப®¢®¥ ¯à¥¤áâ ¢«¥¨¥ ¤«¨ë ä ©« .
„«¨ १ã«ìâ â - 9 ᨬ¢®«®¢, ¯à¨¦¨¬ ¢¯à ¢®.
’ਠ¤ë à §¤¥«ïîâáï ¢ ᮮ⢥âá⢨¨ á áâனª ¬¨ áâà ë `}
function Hex2(a: Byte): Str2;
function Hex4(a: Word): Str4;
function Hex8(a: LongInt): Str8;
function HexFilePos(C: Comp): String;
{`9 hex-æ¨äà`}
function HexChar(a: Byte): Char;
function Replace(const Pattern, ReplaceString: String; var S: String)
: Boolean;
function Dec2(w: Word): Str2;
{` ®¢® ¤¢¥ ¤¥áïâ¨çë¥ æ¨äàë (¬« ¤è¨¥) `}
function fReplace(const SubFrom, SubTo: String; S: String): String;
function PosChar(C: Char; const S: String): Byte;
function CharCount(C: Char; const S: String): Byte; {DataCompBoy}
function SecToStr(t: Word): String;
{` ¢à¥¬ï, á ãçñ⮬ à §¤¥«¨â¥«ï ¢à¥¬¥¨, १ã«ìâ â ⨯ 12:34:56 `}
function FormatTimeStr(H, M, SS: Word): String; {DataCompBoy}
{` ¢à¥¬ï, á ãçñ⮬ ä®à¬ â ¨ à §¤¥«¨â¥«ï ¢à¥¬¥¨, १ã«ìâ â ¬®¦¥â
¡ëâì ⨯ 01:23:45pm `}
function FormatDateTime(const DT: DateTime; Time: Boolean): String; {cat}
procedure MakeCurrency(R: Real; var S: String);
function GetDateTime(Time: Boolean): String;
function Real2Str(X: Real; n: Byte): String;
function Long2Str(X: LongInt; l: Byte): String;
function Long0Str(X: LongInt; l: Byte): String;
function ToHex(I: Word): String;
procedure DelDoubles(const St: String; var Source: String);
procedure AnsiDelDoubles(const St: String; var Source: AnsiString);
procedure LongDelDoubles(const St: LongString; var Source: LongString);
procedure MakeDate(const Day, Month, Year, Hour, Min: Word;
var S: String);
procedure MakeDateFull(const Day, Month: Word; {-$VOL moidfied}
Year, Hour: Word;
const Min: Word;
var S: String;
const YFull: Boolean);
function DumpStr
{` ‘ä®à¬¨à®¢ âì ¯à¥¤áâ ¢«¥¨¥ Hex+Text c 9-§ çë¬
¤à¥á®¬ á«¥¢ . ¥à¢ë© Hex-ᨬ¢®« - S[12]`}
(var B; Addr: Comp; Count: Integer; Filter: Byte): String;
function MemEqual(var Buf1; var Buf2; Len: Word): Boolean;
type
BMTable = array[0..255] of Byte;
{` Boyer-Moore index-table data definition. `}
procedure Create_BMTable
( {output} var BMT: BMTable;
{input/output} var Pattern: String;
ExactCase: Boolean);
procedure Create_BackBMTable
( {output} var BMT: BMTable;
{input/output} var Pattern: String;
ExactCase: Boolean);
function BMsearch(
{` Boyer-Moore Search function. ¥§ã«ìâ â - ¨¤¥ªá (®â 1)
ç « ©¤¥®£® ⥪áâ ¨«¨ 0, ¥á«¨ ⥪áâ ¥ ©¤¥ }
const BMT: BMTable;
{` ¤®«¦ ¡ëâì ¯®áâ஥ § à ¥¥ `}
var Buffer;
BuffSize: LongInt;
const Pattern: String;
const UpXlatArray: TXlat
{` ᮢ¬¥é ¥â ¯¥à¥ª®¤¨à®¢ªã ¨§ ª®¤¨à®¢ª¨ Buffer ¢ ASCII ¨
¯¥à¥¢®¤ ¢¥à娩 ॣ¨áâà (¥á«¨ ¤®). ‚ ¯à®á⥩襬 á«ãç ¥, ª®£¤
㦥 ॣ¨áâ஧ ¢¨á¨¬ë© ¯®¨áª ¢ ASCII, íâ® ¡ã¤¥â NullXlatTAble`}
): LongInt;
{`}
function BackBMsearch(
{` Boyer-Moore Search function. ‘¤¥« ¨§ BMsearch}
const BMT: BMTable;
var Buffer;
BuffSize: LongInt;
const Pattern: String;
const UpXlatArray: TXlat
): LongInt;
{`}
function BackSearchForAllCP(S: String; var B; l: LongInt;
CaseSensitive: Boolean): LongInt; {-$VIV 14.05.99}
function SearchForAllCP(S: String; var B; l: LongInt;
CaseSensitive: Boolean): LongInt;
procedure CompressString(var S: LongString);
{AK155}
function PosLastDot(StrToMake: String): Byte;
{` ®§¨æ¨ï â®çª¨ à áè¨à¥¨ï. …᫨ à áè¨à¥¨ï ¥â - ¤«¨ ¯«îá 1 `}
function IsDummyDir(const DirName: String): Boolean;
procedure CopyShortString(const s1, s2: ShortString);
{` Š®¯¨àã¥â áâப㠢 ᮮ⢥âá⢨¨ á ¥ñ ¤«¨®©, ¥§ ¢¨á¨¬® ®â ⮣®,
ª ª ®¯¨á áâப -¯®«ãç ⥫ì. ˆá¯®«ì§ã¥âáï ¤«ï ª®¯¨à®¢ ¨ï ¤«¨®£®
¨¬¥¨ ¢ TFileRec, ª®â®à®¥ á¨â ªá¨ç¥áª¨ ¨¬¥¥â ¤«¨ã 12,
ä ªâ¨ç¥áª¨ ¯à®¤®«¦ ¥âáï ¢ ¯®«¥ Dummy`}
{/AK155}
function SPos(SubStr, S: String; Start: Integer): Integer;
{` € «®£ Pos, ⮫쪮 ¯®¨áª ç¨ ¥âáï á S[Start] `}
function MinBufSize(x: TFileSize; y: LongInt): LongInt;
{` Œ¥ì襥 ç¨á«® ¨§ à §¬¥à ä ©« ¨ à §¬¥à ¡ãä¥à `}
function Positive(x: TFileSize): TFileSize;
{` §¬¥à ä ©« , ®£à ¨ç¥ë© ᨧã ã«ñ¬ `}
function i32(x: TFileSize): LongInt;
{` TFileSize -> LongInt `}
function CompToFSize(x: Comp): TFileSize;
{` Comp -> TFileSize `}
function FSizeMod(x: TFileSize; y: LongInt): LongInt;
{` Žáâ ⮪ ®â ¤¥«¥¨ï x y `}
function Str2Comp(const s: String): Comp;
implementation
uses
DnIni, Startup, Commands, Advance, UKeyMap
;
procedure AddStr(var S: String; C: Char);
begin
S := S+C
end; {Cat}
function UpCase(c: Char): Char;
{AK155}
begin
UpCase := UpCaseArray[C]
end;
function LowCase(c: Char): Char;
{AK155}
begin
LowCase := LowCaseArray[C]
end;
function Dec2(w: Word): Str2;
begin
w := abs(w) mod 100;
Result := HexChar(w div 10) + HexChar(w mod 10);
end;
function StrGrd(AMax, ACur: TSize; Wide: Byte; Rev: Boolean): String;
var
A: Byte;
begin
if AMax = 0 then
A := Wide
else
A := Round((ACur*Wide)/AMax);
if Rev then
StrGrd := Strg(#177, Wide-A)+Strg(#219, A)
else
StrGrd := Strg(#219, A)+Strg(#177, Wide-A);
end;
function Percent(AMax, ACur: TSize): String;
begin
if AMax = 0 then
Percent := {0}'100%' {AK155}
else
Percent := ItoS(Trunc((ACur*100)/AMax)) + '%';
end;
procedure Hex8Lo(L: LongInt; var HexLo);
{$IFNDEF NOASM}
assembler;
{$USES EDI, EBX, EDX, ECX} {&Frame-}
asm
cld
xor dx,dx
mov edi,[HexLo]
lea ebx,[HexStr]
mov dx,[word ptr L+2]
call @@OutWord
mov dx,[word ptr L+0]
call @@OutWord
jmp @@LEnd
@@OutWord: {DX-word}
mov ax,dx
mov cl,12
shr ax,cl
xlat
stosb
mov al,dh
and al,0Fh
xlat
stosb
mov al,dl
mov cl,4
shr al,cl
xlat
stosb
mov al,dl
and al,0Fh
xlat
stosb
retn
@@LEnd:
end;
{$ELSE}
type
ChArr = array[1..8] of Char;
var
i: integer;
begin { Hex8Lo }
for i := 1 to 8 do ChArr(HexLo)[i] := HexStr[L shr (32-(i*4)) and $F];
end { Hex8Lo };
{$ENDIF}
{Cat: ¯®-¬®¥¬ã, ¢áñ ¯à®é¥... íâ® ¦¥ System.Delete(s, 1, 1)... ¢ëª¨ã« 䨣}
(*
procedure DelFC(var s:String);
begin
if Length(s) > 0 then
begin
Move(s[2], s[1], Length(s)-1);
SetLength(s, Length(s)-1)
end;
end;
*)
function CenterStr(const s: String; n: Byte): String;
begin
if Length(s) >= n then
CenterStr := Copy(s, 1, n)
else
CenterStr := Copy(Strg(#32, (n-Length(s)) div 2)+s+Strg(#32,
(n-Length(s)) div 2+1), 1, n);
end;
function AddSpace(const s: String; n: Byte): String;
{$IFNDEF NOASM}
assembler;
{&Frame-} {$USES ESI, EDI, ECX}
asm
cld
mov esi, s
mov edi, @Result
lodsb
mov ah, N
xor ecx, ecx
cmp al, ah
jae @JustCopy
mov [edi], ah
inc edi
mov cl, al
rep movsb
sub ah, al
mov al, ' '
mov cl, ah
rep stosb
jmp @LEnd
@JustCopy:
stosb
mov cl, al
rep movsb
@LEnd:
end;
{$ELSE}
var
s2: String;
begin { AddSpace }
s2 := s;
if Length(s) < n then
begin
FillChar(s2[Length(s2)+1], n-Length(s2), ' ');
s2[0] := Char(n);
end;
AddSpace := s2;
end { AddSpace };
{$ENDIF}
{Cat}
function LongAddSpace(const s: LongString; n: LongInt): LongString;
var
s2: LongString;
L: LongInt;
begin
s2 := s;
L := Length(s);
if L < n then
begin
SetLength(s2, n);
FillChar(s2[L+1], n-L, ' ');
end;
LongAddSpace := s2;
end;
{/Cat}
function PredSpace;
begin
if Length(s) >= n then
PredSpace := s
else
begin
FillChar(FreeStr[1], 255, ' ');
Move(s[1], FreeStr[Succ(n-Length(s))], Length(s));
SetLength(FreeStr, n);
PredSpace := FreeStr
end
end;
procedure DelSpace;
{$IFNDEF NOASM}
assembler;
{&Frame-} {$USES EBX, EDI, ESI, ECX}
asm
mov ebx, S
xor ecx, ecx
mov cl, [ebx]
jcxz @@1
mov edi, 1
mov esi, 1
xor al, al
mov [ebx], al
@@2:
mov al, [ebx+edi]
cmp al, ' '
jz @@3
cmp al, 9
jz @@3
mov [ebx+esi], al
inc byte ptr [ebx]
inc esi
@@3:
inc edi
loop @@2
@@1:
end;
{$ELSE}
var
a, b, j: Byte;
begin { DelSpace }
if s = '' then
Exit;
b := 1;
j := Length(s);
s[0] := #0;
for a := 1 to j do
if not (s[a] in [' ', #9]) then
begin
s[b] := s[a];
Inc(s[0]);
Inc(b);
end;
end { DelSpace };
{$ENDIF}
function DelSpaces;
begin
DelSpace(s);
DelSpaces := s;
end;
procedure DelRight(var S: String);
{$IFNDEF NOASM}
assembler;
{&Frame-} {$USES ESI, EBX}
asm
mov esi, S
movzx ebx, byte ptr [esi] {¤«¨ }
inc ebx
@@Next:
dec ebx
{á¯¥æ¨ «ìë© «¨§ ¤«¨ë 0 ¥ 㦥, â ª ª ª 0 - íâ® ¥ ¯à®¡¥« ¨ ¥ Tab}
mov al, byte ptr [esi+ebx]
cmp al, ' '
je @@Next
cmp al, 9
je @@Next
mov byte ptr[esi], bl
end;
{$ELSE NoAsm}
var
L: Byte absolute S;
begin
while L > 0 do
begin
if S[L] <> ' ' then
Break;
Dec(L);
end;
end { DelRight };
{$ENDIF}
procedure LongDelRight(var S: LongString);
var
I, I0: LongInt;
begin
I := Length(S);
I0 := I;
while (I > 0) and (S[I] = ' ') do
Dec(I);
if I0 <> I then
SetLength(S, I);
end;
function fDelRight(s: String): String;
begin
DelRight(s);
fDelRight := s
end;
procedure DelLeft(var S: String);
{$IFNDEF NOASM}
assembler;
{&Frame-} {$USES ESI, EDI, ECX}
asm
cld
mov esi, S {From}
mov edi, S
xor ecx, ecx
mov cl, byte ptr [esi]
inc cl
inc edi
@@SearhNoSpace:
inc esi
dec cl
jz @@DoMove
mov al, [esi]
cmp al, ' '
je @@SearhNoSpace
cmp al, 9
je @@SearhNoSpace
@@DoMove: cmp esi, edi
je @@Exit
mov byte ptr [edi-1], cl
or cl, cl
jz @@Exit
xor ch, ch
{ shr cl, 1}
{ rep movsw}
rep movsb
@@Exit:
end;
{$ELSE}
var
I: Byte;
SL: Byte absolute S;
begin { DelLeft }
I := 1;
while (SL >= I) and (S[I] in [#9, ' ']) do
Inc(I);
if I > 1 then
begin
Dec(SL, I-1);
Move(S[I], S[1], SL);
end;
end { DelLeft };
{$ENDIF}
procedure LongDelLeft(var S: LongString);
var
I: LongInt;
begin
I := 1;
while (I <= Length(S)) and (S[I] in [#9, ' ']) do
Inc(I);
if I > 1 then
S := Copy(S, I, Length(S)-I+1);
end;
function fDelLeft(s: String): String;
begin
DelLeft(s);
fDelLeft := s
end;
(*
Procedure LowStr(var s : string);
var i:integer;
begin for i:=1 to Length(s) do
{if s[i]<>#0 then} s[i]:=LowCaseArray[s[i]]; {AK155}
end;
*)
function LowStrg(s: String): String;
begin
LowStr(s);
LowStrg := s;
end;
function UpStrg(s: String): String;
begin
UpStr(s);
UpStrg := s;
end;
procedure UpLowStr(var s: String); {JO}
begin
if UpperCaseSorting then
UpStr(s)
else
LowStr(s);
end;
function UpLowStrg(s: String): String; {JO}
begin
if UpperCaseSorting then
begin
UpStr(s);
UpLowStrg := s;
end
else
begin
LowStr(s);
UpLowStrg := s;
end;
end;
(*
Procedure CapStr(var S: String);
var
I: Integer;
begin
I:=1;
repeat
While (I<=Length(S)) and (S[I] in BreakChars) do Inc(I);
If I>Length(S) then break;
S[I]:=UpCase(S[I]);
While (I<Length(S)) and (not (S[I] in BreakChars)) do begin
Inc(I); S[I]:=LowCase(S[I]);
end;
until I>=Length(S);
end;
*)
function CapStrg(S: String): String;
begin
CapStr(S);
CapStrg := S;
end;
{Cat}
function CapLongStrg(const S: LongString; First, Last: Integer): LongString;
begin
Result := S;
CapLongStr(Result, First, Last);
end;
{/Cat}
{Cat}
procedure UpStr(var s: String);
begin
XLatBuf(s[1], Length(s), UpCaseArray);
end;
procedure LowStr(var s: String);
begin
XLatBuf(s[1], Length(s), LowCaseArray);
end;
procedure CapStr(var S: String);
var
I: LongInt;
begin
I := 1;
repeat
while (I <= Length(S)) and (S[I] in BreakChars) do
Inc(I);
if I > Length(S) then
Break;
S[I] := UpCase(S[I]);
while (I < Length(S)) and (not (S[I] in BreakChars)) do
begin
Inc(I);
S[I] := LowCase(S[I]);
end;
until I >= Length(S);
end;
procedure CapLongStr(var S: LongString; First, Last: Integer);
var
I: LongInt;
begin
if Last > Length(S) then
Last := Length(S);
if First > Last then
Exit;
SetLength(S, Length(S));
I := First;
{ …᫨ á«®¢® ç¨ ¥âáï ¢¥ ãç á⪠- ¯à¯ã᪠¥¬ ¥£® }
if (I <> 1) and not (S[I-1] in BreakChars) then
while not (S[I] in BreakChars) do
begin
if I = Last then
Exit;
Inc(I);
end;
while True do
begin
{ யãáª à §¤¥«¨â¥«¥© ¯¥à¥¤ á«®¢®¬ }
while I <= Last do
begin
if not (S[I] in BreakChars) then
Break;
Inc(I);
end;
if I > Last then
Exit;
{ ¥à¢ãî ¡ãª¢ã á«®¢ - ¢¥à娩 ॣ¨áâà }
S[I] := UpCase(S[I]);
{ Žáâ «ìë¥ ¡ãª¢ë á«®¢ - ¨¦¨© ॣ¨áâà }
while I < Last do
begin
Inc(I);
if S[I] in BreakChars then
Break;
S[I] := LowCase(S[I]);
end;
Inc(I);
end;
end;
function Cut;
begin
(* X-Man *)
if len < 0 then
len := 0;
Cut := FormatLongName(p, len, 0, 0, nfmNull)
end;
function CutH;
begin
(* X-Man *)
if len < 0 then
len := 0;
CutH := FormatLongName(p, len, 0, flnHighlight+flnHandleTildes, nfmNull)
end;
function Strg(C: Char; Num: Byte): String;
begin
SetLength(Result, Num);
FillChar(Result[1], Num, C);
end;
function LongStrg(C: Char; Num: LongInt): LongString;
begin
SetLength(Result, Num);
FillChar(Result[1], Num, C);
end;
{/Cat}
function ItoS(a: LongInt): String;
var
s: String[12];
begin
Str(a, s);
ItoS := s;
end;
function ZtoS(a: TSize): String;
var
s: String[20];
begin
Str(a: 0: 0, s);
ZtoS := s;
end;
function RtoS(a: Real; M, F: Integer): String;
var
s: String[20];
begin
Str(a: M: F, s);
RtoS := s;
end;
function StoI(const s: String): LongInt;
var
i: LongInt;
j: Integer;
begin
Val(s, i, j);
StoI := i;
end;
function SStr(a: LongInt; B: Byte; C: Char): String;
var
s: String[40];
i: Integer;
begin
Str(a: B, s);
i := 1;
while i < B do
begin
if s[i] = ' ' then
s[i] := C
else
i := 255;
Inc(i);
end;
SStr := s;
end;
function SSt2(a: LongInt; B: Byte; C: Char): String;
var
s: String[40];
begin
Str(a: B, s);
while (s[1] = ' ') do
begin
Delete(s, 1, 1); {DelFC(s);}
s := s+' '
end;
while B > 0 do
begin
if s[B] = ' ' then
s[B] := C
else
B := 1;
Dec(B);
end;
SSt2 := s;
end;
const
Magnif: string[4] = 'KMGT';
function SizeStr(a: TSize; MaxVal: TSize): String;
var
i, j, b: Integer;
begin
if a >= 0 then
begin
i := 0;
if a >= MaxVal then
MaxVal := MaxVal / 10; // ¬¥áâ® ¤«ï ¡ãª¢ë ¬®¦¨â¥«ï
while a >= MaxVal do
begin
a := a/1024;
inc(i);
end;
Str(a: 0: 0, Result);
if CountryInfo.ThouSep[0] > #0 then
begin
b := 2 + (Length(Result)-1) mod 3;
for j := (Length(Result)-1) div 3 downto 1 do
Insert(CountryInfo.ThouSep[1], Result, b + 3*(j-1));
end;
if i <> 0 then
Result := Result + Magnif[i];
end
else
Result := '?';
end { SizeStr };
function FStr(a: TSize): String;
begin
Result := SizeStr(a, 1000000000);
end;
function FileSizeStr;
begin
Result := SizeStr(X, 10000000);
if Length(Result) > 9 then
Delete(Result, 2, 1) { 㤠«ï¥¬ ¯¥à¢ë© à §¤¥«¨â¥«ì}
else
Result := PredSpace(Result, 9);
end;
function Hex2;
begin
Hex2 := HexChar(a shr 4)+HexChar(a)
end;
function Hex4;
begin
Hex4 := HexChar(Hi(a) shr 4)+HexChar(Hi(a))+
HexChar(Lo(a) shr 4)+HexChar(Lo(a));
end;
function Hex8;
var
s: Str8;
begin
s[0] := #8;
Hex8Lo(a, s[1]);
Hex8 := s;
end;
function HexFilePos(C: Comp): String;
var
FilePosRec: record lo32, hi32: Longint end absolute C;
begin
Result := HexChar($0F and FilePosRec.hi32) + Hex8(FilePosRec.lo32);
end;
function HexChar(a: Byte): Char;
{$IFNDEF NOASM}
assembler;
asm
mov al,a
and al,0Fh
add al,'0'
cmp al,58
jc @@Loc1
add al,7
@@Loc1:
end;
{$ELSE}
begin
a := a and 15;
if a < 10 then
HexChar := Char(Ord('0')+a)
else
HexChar := Char(Ord('A')+a-10);
end;
{$ENDIF}
function Replace;
var
I, J, K: Integer;
begin
J := 1;
K := 1;
Replace := False;
if (Pattern = '') or (S = '') then
Exit;
repeat
I := Pos(Pattern, Copy(S, J, MaxStringLength));
if I > 0 then
begin
Delete(S, J+I-1, Length(Pattern));
Insert(ReplaceString, S, J+I-1);
Replace := True;
end;
K := I;
Inc(J, I+Length(ReplaceString)-1);
until I = 0;
end;
function fReplace(const SubFrom, SubTo: String; S: String): String;
var
P: Integer;
begin
repeat
P := Pos(SubFrom, S);
if P <> 0 then
begin