home *** CD-ROM | disk | FTP | other *** search
- {$S-,R-,V-}
- Unit Tools;
-
- Interface
-
- Uses
- DOS;
-
- Const
- _EQUAL_ = 0;
-
-
- Type
- Str3 = String[3];
- Str80 = String[80];
- Path = String[70];
-
- Function UpperCase( S : String ) : String;
-
- Function CompMem( Var Block1,Block2; Size : Word ) : Word;
- {
- return 0 if Block1 and Block2 are equal for Size bytes
- if not equal, return the position of first non matching byte
- the first byte is considered to be 1
- }
-
- Function ExpandTabs( Var S : String ) : String;
- { expands each tab into a single space. Used before parsing }
-
- Function Trim( Var S : String ) : String;
- { FAST assembly language Trim routine, trims leading and trailing }
-
- Function SearchBlock( Var FindStr; FindSize : Word; Var Block;
- BlockSize : Word ) : Word;
- { generic Block search routine. Takes untyped VAR parameters }
-
- Procedure ReplaceString( StrToFind,StrToRep : Str80; Var S : String );
- { Finds StrToFind and replaces it with StrToRep in string S. }
- { ignores case when searching for the string to replace. }
-
- Function RightStr( S : String; Number : Word ) : String;
- { returns all characters to the right of character Number }
-
- Function ParseWord( Var S : String; DelimChar : Char ) : String;
- { parses input string S up to the first occurance of DelimChar. }
- { The parsed string is returned, and chopped out of the string S}
- { see WordOnLine implementation for sample use of ParseWord }
-
- Function WordOnLine( Var The_Word,The_Line : String ) : Boolean;
- { returns TRUE if The_Word appears on The_Line }
-
- Function FileExt( PName : Path; Extension : Str3 ) : Path;
- { force a file extension }
-
- Function InKey( Var ScanCode : Byte ) : Char;
- { return character and scancode with a single call }
-
- Implementation
-
- { the external Assembly language routines: }
-
- {$L UCASE.OBJ}
- {$L MEMCOMP.OBJ}
- {$L EXPTABS.OBJ}
- {$L TRIM.OBJ}
- {$L SEARCH.OBJ}
- {$L PARSE.OBJ}
- {$L INKEY.OBJ}
- {$L RIGHTSTR.OBJ}
-
- Function UpperCase( S : String ) : String; External;
-
- Function CompMem( Var Block1,Block2; Size : Word ) : Word; External;
-
- Function ExpandTabs( Var S : String ) : String; External;
-
- Function Trim( Var S : String ) : String; External;
-
- Function SearchBlock( Var FindStr; FindSize : Word; Var Block;
- BlockSize : Word ) : Word; External;
-
- Function ParseWord( Var S : String; DelimChar : Char ) : String; External;
-
- Function InKey( Var ScanCode : Byte ) : Char; External;
-
- Function RightStr( S : String; Number : Word ) : String; External;
-
- Procedure ReplaceString( StrToFind,StrToRep : Str80; Var S : String );
-
- Var
- L,P : Word;
- SS : String; {scratch string }
- STF,STR : Str80;
-
- Begin
- SS := UpperCase( S ); {use the scratch string }
- STF := UpperCase( StrToFind );
- STR := UpperCase( StrToRep );
- L := Length( SS );
- P := SearchBlock( STF[1],Length(STF),SS[1],L );
-
- If P > 0 Then
- Begin
- Delete(S,P,Length(StrToFind));
- If Length( StrToRep ) > 0 Then
- Insert( StrToRep,S,P );
- End;
-
- End;
-
- Function WordOnLine( Var The_Word,The_Line : String ) : Boolean;
- { returns TRUE if The_Word appears on The_Line }
-
- Var
- S : String; {scratch string }
- Wrd : Str80; { the parsed word }
-
- Begin
- S := Trim( The_Line );
- While( Length( S ) > 0 ) Do
- Begin
- Wrd := ParseWord( S,' ' );
- S := Trim( S );
- If CompMem( Wrd,The_Word,
- Succ( Length( Wrd ) ) ) = _EQUAL_ Then
- Begin
- WordOnLine := TRUE;
- Exit;
- End;
- End;
- WordOnLine := FALSE;
- End;
-
- Function FileExt( PName : Path; Extension : Str3 ) : Path;
-
- Var
- Position,L : Word;
-
- PathName : Path;
-
- Const
- Period : String[1] = '.';
-
- Begin
- PathName := PName;
- Position := Pos( Period,PathName );
- If Position > 0 Then
- Begin
- L := Length( PathName );
- PathName[0] := Char( L - Succ( L - Position ) );
- End;
- FileExt := PathName + '.' + Extension;
- End;
-
- End.
-