home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 3 Comm
/
03-Comm.zip
/
TIKTP12A.LZH
/
UTILITY.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1992-03-16
|
9KB
|
353 lines
(*#module(turbo_comp=>off)*)
IMPLEMENTATION Unit Utility ;
IMPORT
DOS(EXIT_PROCESS),
TURBOSYS(upcase,_STR_INT)
;
FUNCTION UpperCase { (TheString: MAXSTRING): MAXSTRING ; };
Var
Idx : Word ;
Begin
For Idx := 1 to Length(TheString) Do
{ Special Cases are for International Characters }
Case TheString[Idx] of
'å' : TheString[Idx]:= 'Å';
'ä' : TheString[Idx]:= 'Ä';
'ö' : TheString[Idx]:= 'Ö';
'ü' : TheString[Idx]:= 'Ü';
'é' : TheString[Idx]:= 'É';
'ñ' : TheString[Idx]:= 'Ñ';
'æ' : TheString[Idx]:= 'Æ';
{Put all other chars to be converted here }
Else
TheString[Idx] := upcase(TheString[Idx]);
End ;
UpperCase := TheString ;
End;
FUNCTION LowerCase { (TheString: MAXSTRING): MAXSTRING ; };
Var
Idx : Word ;
Ch : Char ;
Begin
For Idx := 1 to Length(TheString) Do
Begin
Ch := TheString[Idx] ;
If Ch In ['A'..'Z'] Then
TheString[Idx] := ((Ord(Ch)+32)::Char)
Else Begin
{ Special Cases for International Characters }
Case TheString[Idx] of
'Å' : TheString[Idx]:= 'å' ;
'Ä' : TheString[Idx]:= 'ä' ;
'Ö' : TheString[Idx]:= 'ö' ;
'Ü' : TheString[Idx]:= 'ü' ;
'É' : TheString[Idx]:= 'é' ;
'Ñ' : TheString[Idx]:= 'ñ' ;
'Æ' : TheString[Idx]:= 'æ' ;
Else End ;
End ;
End ;
LowerCase := TheString ;
End ;
FUNCTION Capitalize { (TheString: MAXSTRING): MAXSTRING ; };
Var
I : Word ;
Ch : Char ;
Fl : Boolean ;
Begin
Fl := True ;
TheString := LowerCase(TheString) ;
For I := 1 to Length(TheString) Do
Begin
Ch := TheString[I] ;
If Ch In ['a'..'z',''''] Then
Begin
If Fl Then TheString[I] := upcase(Ch) ;
Fl := False ;
End Else
Fl := True ;
End ;
Capitalize := TheString ;
End ;
FUNCTION Trim { (TheString: MAXSTRING): MAXSTRING ; };
Var
I : Word ;
Begin
Repeat
Begin
I := POS(' ',TheString) ;
If I <> 0 Then Delete(TheString,I,1) ;
End ;
Until I = 0 ;
If TheString[1] = ' ' Then
Delete(TheString,1,1) ;
If TheString[Length(TheString)] = ' ' Then
Delete(TheString,Length(TheString),1);
Trim := TheString ;
End ;
FUNCTION Strip { (TheString: MAXSTRING; Delim: Char; Mode: Char): MAXSTRING ; };
Var
Idx : Word ;
Begin
Case upcase(Mode) of
'L' : Begin { Strips All LEADING characters }
While (TheString[1] = Delim) and (Length(TheString) > 0) Do
Delete(TheString,1,1);
End ;
'T' : Begin { Strips all TRAILING characters }
While (TheString[Length(TheString)] = Delim) and (Length(TheString) > 0) Do
Delete(TheString,Length(TheString),1);
End ;
'B' : Begin { Strips BOTH leading and trailing characters }
While (TheString[1] = Delim) and (Length(TheString) > 0) Do
Delete(TheString,1,1);
While (TheString[Length(TheString)] = Delim) and (Length(TheString) > 0) Do
Delete(TheString,Length(TheString),1);
End ;
'A' : Begin { Strips ALL occurances of the character }
Repeat
Begin
Idx := POS(Delim,TheString) ;
If Idx <> 0 Then Delete(TheString,Idx,1) ;
End ;
Until Idx = 0 ;
End ;
'R' : Begin { Strips Redundant characters }
Repeat
Begin
Idx := POS(Delim + Delim,TheString) ;
If Idx <> 0 Then Delete(TheString,Idx,1) ;
End ;
Until Idx = 0 ;
If TheString[1] = Delim Then
Delete(TheString,1,1) ;
If TheString[Length(TheString)] = Delim Then
Delete(TheString,Length(TheString),1);
End ;
Else End;
Strip := TheString;
End ;
FUNCTION Word_to_Str { (TheWord: Word): MAXSTRING ; };
Var
Tmp : MAXSTRING ;
OK : boolean;
Begin
IntToStr(TheWord,Tmp,10,OK);
{ _STR_INT(TheWord, 0, Tmp) ;}
Word_to_Str := Tmp ;
End ;
FUNCTION Str_To_Word { (TheString: MAXSTRING): Word ; };
Var
Tmp : Word ;
OK : boolean;
Begin
Tmp := StrToInt(TheString,10,OK);
{ _VAL_INT(TheString,Tmp,Garbage) ; }
If not OK Then
Str_To_Word := 0
Else
Str_To_Word := Tmp ;
End ;
FUNCTION Count { (TheString: MAXSTRING; Delim: MAXSTRING): Word ; };
Var
Idx : Word ;
Cnt : Word ;
Begin
Cnt := 0 ;
For Idx := 1 to Length(TheString) Do
If Copy(TheString,Idx,Length(Delim)) = Delim Then Cnt:=Cnt+1 ;
Count := Cnt ;
End ;
FUNCTION DCount { (TheString: MAXSTRING; Delim: MAXSTRING): Word ; };
Var
Idx : Word ;
Cnt : Word ;
LABEL 1;
Begin
If TheString = '' Then Begin
DCount := 0 ;
GOTO 1 ;
End ;
Cnt := 1 ;
For Idx := 1 to Length(TheString) Do
If Copy(TheString,Idx,Length(Delim)) = Delim Then Cnt:=Cnt+1 ;
DCount := Cnt ;
1:
End ;
FUNCTION Index { (TheString: MAXSTRING; Delim: MAXSTRING; Cnt: Word): Word ; };
Var
X : Word ;
Idx : Word ;
LABEL 1;
Begin
If (Count(TheString,Delim) < Cnt) or (Cnt < 1) Then
Index := 0
Else Begin
X := 0 ;
For Idx := 1 to Length(TheString) Do
Begin
If Copy(TheString,Idx,Length(Delim)) = Delim Then X:=X+1 ;
If X = Cnt Then
Begin
Index := Idx ;
GOTO 1 ;
End ;
End ;
WriteLn('ERROR IN INDEX FUNCTION') ;
dos.exit(EXIT_PROCESS,255);
End ;
1:
End ;
FUNCTION Field { (TheString: MAXSTRING; Delim: MAXSTRING; Cnt: Word): MAXSTRING ; };
Var
Start : Word ;
Last : Word ;
Size : Word ;
LABEL 1;
Begin
Start := Index(TheString,Delim,Cnt-1) ;
If (Start = 0) and (Cnt <> 1) Then
Begin
Field := '' ;
GOTO 1 ;
End ;
Start := Start + 1 ;
Last := Index(TheString,Delim,Cnt) ;
If Last = 0 Then
Last := Length(TheString)
Else
Last := Last - 1 ;
Size := Last - Start + 1 ;
Field := Copy(TheString,Start,Size) ;
1:
End ;
FUNCTION Change { (TheString: MAXSTRING; Old: Char; New: Char): MAXSTRING ; };
Var
Idx : Word ;
Tmp : MAXSTRING ;
Begin
Tmp := TheString ;
For Idx := 1 to Length(TheString) Do
If Tmp[Idx] = Old Then Tmp[Idx] := New ;
Change := Tmp ;
End ;
FUNCTION PadLeft { (TheString: MAXSTRING; Size:Word; Pad: Char): MAXSTRING ; };
Var
Tmp : MAXSTRING ;
Begin
Fillchar(Tmp[1],Size,Pad) ;
Tmp[0] := Chr(Size) ;
If Length(TheString) <= Size Then
Move(TheString[1],Tmp[1],Length(TheString))
Else
Move(TheString[1],Tmp[1],Size) ;
PadLeft := Tmp ;
End ;
FUNCTION PadRight { (TheString: MAXSTRING; Size: Word; Pad: Char): MAXSTRING ; };
Var
Tmp : MAXSTRING ;
L : Word ;
Begin
Fillchar(Tmp[1],Size,Pad) ;
Tmp[0] := Chr(Size) ;
L := Length(TheString) ;
If L <= Size Then
Move(TheString[1],Tmp[Succ(Size - L)],L)
Else
Move(TheString[L - Size + 1],Tmp[1],Size);
PadRight := Tmp;
End;
FUNCTION PadCenter { (TheString: MAXSTRING; Size: Word; Pad: Char): MAXSTRING ; };
Var
Tmp : MAXSTRING ;
L : Word ;
Begin
Fillchar(Tmp[1],Size,Pad) ;
Tmp[0] := Chr(Size) ;
L := Length(TheString) ;
If L <= Size Then
Move(TheString[1],Tmp[((Size - L) div 2) + 1],L)
Else
Move(TheString[((L - Size) div 2) + 1],Tmp[1],Size) ;
PadCenter := Tmp ;
End ;
FUNCTION DATE_DMA { (Number: Word): MAXSTRING ; };
TYPE ZZZXXXZZZ0= Array[1..12] of String[9];
Const Months = ZZZXXXZZZ0 ('January','February','March','April','May','June',
'July','August','September','October','November','December') ;
Begin
DATE_DMA := Months[Number] ;
End ;
FUNCTION DATE_DWA { (Number: Word): MAXSTRING ; };
TYPE ZZZXXXZZZ1= Array[0..6] of String[9];
Const DaysOfWeek = ZZZXXXZZZ1 ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday') ;
Begin
DATE_DWA := DaysOfWeek[Number] ;
End ;
FUNCTION MD { (Number: INTEGER; Decimal: Word): MAXSTRING ; };
Var
Tmp : MAXSTRING ;
Begin
_STR_INT(Number, 0,Tmp) ;
Tmp := PadRight(Tmp,15 + Decimal,'0') ;
Tmp := Copy(Tmp,1,3) + ','
+ Copy(Tmp,4,3) + ','
+ Copy(Tmp,7,3) + ','
+ Copy(Tmp,10,3) + ','
+ Copy(Tmp,13,3) + '.'
+ Copy(Tmp,16,255) ;
While (Tmp[1] = '0') or (Tmp[1] = ',') Do
Delete(Tmp,1,1) ;
If Decimal = 0 Then Delete(Tmp,Length(Tmp),1) ;
If Tmp = '' Then Tmp := '0' ;
MD := Tmp ;
End ;
Begin
End .