5 function space ( n
:integer):string ;
6 function replicate(ch
:char; n
:integer):string ;
7 function trim (str
:string;c
:boolean=false):string ;
8 function alike (a
,b
:string;var d
, p
: integer): boolean;
9 function center (str
:string;n
:integer):string ;
10 function UpSt ( s
:string ):string;
11 function LoSt ( s
:string ):string;
12 function lpad ( s
:string;n
:integer;c
:char):string;
13 function rpad ( s
:string;n
:integer;c
:char):string;
14 function addbackslash(p
: string) : string;
15 function match (sm
: string; var st
: string) : boolean;
16 function lines (p
, l
, s
: longint) : string;
17 function LoCase (c
: char) : char;
18 function JustPathName(PathName
: string) : string;
19 function JustFileName(PathName
: string) : string;
20 function JustName (PathName
: string) : string;
21 function CRC16 (s
: string) : system
.word;
30 for i
:=1 to n
do tempstr
:=tempstr
+' ';
39 for i
:=1 to n
do tempstr
:=tempstr
+ch
;
49 if length(str
) > 1 then begin
52 while (j
<= i
) and (str
[j
] = ' ') do inc(j
);
57 while (str
[i
] = ' ') do dec(i
);
58 s
:= copy(str
, j
, i
- j
+ 1);
60 if c
and (length(s
) > 3) then begin
64 s
:= copy(s
, 1, i
- 1) + copy(s
, i
+ 1, length(s
) - i
);
68 if c
then result
:= LoSt(s
)
79 if e
+ f
= 0 then begin
84 if (e
= 0) or (f
= 0) then begin
88 while (p
< e
) and (p
< f
) do begin
90 if a
[p
] <> b
[p
] then begin
95 d
:= 200 * p
div (e
+ f
);
96 if p
* 2 > (e
+ f
) div 2 then begin
102 var tempstr
: string;
105 j
:= n
- length(trim(str
));
106 if j
> 0 then tempstr
:= space(j
- j
div 2) + trim(str
) + space(j
div 2)
107 else tempstr
:= trim(str
);
116 for i
:= 1 to length(s
) do t
[i
] := UpCase(s
[i
]);
125 for i
:= 1 to length(s
) do t
[i
] := LoCase(s
[i
]);
131 lpad
:= replicate(c
, n
- length(s
)) + s
;
136 rpad
:= s
+ replicate(c
, n
- length(s
));
139 function addbackslash
;
141 if length(p
) > 0 then
142 if p
[length(p
)] = '\' then addbackslash
:= p
143 else addbackslash
:= p
+ '\'
144 else addbackslash
:= p
;
147 function match(sm
: string; var st
: string) : boolean;
153 if (length(sm
) > 0) and (length(st
) > 0) then begin
156 while pos(_sm
, _st
) > 0 do begin
159 _st
:= copy(_st
, 1, p
- 1) + copy(_st
, p
+ length(_sm
), 250);
160 st
:= copy( st
, 1, p
- 1) + copy( st
, p
+ length( sm
), 250);
172 n
:= p
* s
* 2 div l
;
173 o
:= replicate('Û', i
);
174 if n
> i
* 2 then o
:= o
+ 'Ý';
175 lines
:= o
+ space(s
- length(o
));
176 end else lines
:= '';
182 if (c
>= 'A') and (c
<= 'Z') then t
:= chr(ord(c
) + 32)
187 function JustPathname(PathName
: string) : string;
188 {-Return just the drive:directory portion of a pathname}
192 I
:= Succ(Word(Length(PathName
)));
195 until (PathName
[I
] in ['\',':',#0]) or (I
= 1);
198 {Had no drive or directory name}
201 {Either the root directory of default drive or invalid pathname}
202 JustPathname
:= PathName
[1]
203 else if (PathName
[I
] = '\') then begin
204 if PathName
[Pred(I
)] = ':' then
205 {Root directory of a drive, leave trailing backslash}
206 JustPathname
:= Copy(PathName
, 1, I
)
208 {Subdirectory, remove the trailing backslash}
209 JustPathname
:= Copy(PathName
, 1, Pred(I
));
211 {Either the default directory of a drive or invalid pathname}
212 JustPathname
:= Copy(PathName
, 1, I
);
215 function JustFilename(PathName
: string) : string;
216 {-Return just the filename of a pathname}
220 I
:= Succ(Word(Length(PathName
)));
223 until (I
= 0) or (PathName
[I
] in ['\', ':', #0]);
224 JustFilename
:= Copy(PathName
, Succ(I
), 64);
227 function JustName(PathName
: string) : string;
228 {-Return just the name (no extension, no path) of a pathname}
232 PathName
:= JustFileName(PathName
);
233 DotPos
:= Pos('.', PathName
);
235 PathName
:= Copy(PathName
, 1, DotPos
-1);
236 JustName
:= PathName
;
240 function CRC16(s
: string) : system
.word; { By Kevin Cooney }
246 for t
:= 1 to length(s
) do
248 crc
:= (crc
xor (ord(s
[t
]) shl 8));
250 if (crc
and $8000)>0 then
251 crc
:= ((crc
shl 1) xor $1021)
255 CRC16
:= (crc
and $FFFF);