home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TOOLS4.ZIP / TOOLS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-08-30  |  4.7 KB  |  175 lines

  1. {***************************************************************
  2.  
  3.   Unit Tools - A set of Turbo Pascal programming tools
  4.   version 1.0 8/30/88
  5.   by Richard S. Sadowsky [74017,1670]
  6.  
  7.   released to the public domain by author
  8.  
  9.   This unit was originally written for use with my TC2TP system.
  10.   The source to TC2TP is undergoing some changes, so I thought
  11.   I'd upload these routines.  These routines were written with
  12.   speed in mind.  Most are coded in assembly.  I have included
  13.   the object code for those without an assembler.  I used MASM
  14.   5.1 to develop the ASM code.
  15.  
  16.   These routines are provided as is.  I welcome comments,
  17.   questions,  and suggestions.  Note: some of these routines
  18.   may appear in other public domain files that I have uploaded.
  19.   Some are completely unique to this unit.
  20.  
  21. ***************************************************************}
  22. {$S-,R-,V-}
  23. Unit Tools;
  24.  
  25. interface
  26.  
  27. uses DOS;
  28.  
  29. const
  30.   _EQUAL_          = 0;
  31.  
  32.  
  33. type
  34.   Str3             = String[3];
  35.   Str80            = String[80];
  36.   Path             = String[70];
  37.  
  38. function UpperCase(S : String) : String;
  39.  
  40. function CompMem(var Block1,Block2; Size : Word) : Word;
  41. {
  42.  return 0 if Block1 and Block2 are equal for Size bytes
  43.  if not equal, return the position of first non matching byte
  44.  the first byte is considered to be 1
  45. }
  46.  
  47. function ExpandTabs(var S : String) : String;
  48. { expands each tab into a single space. Used before parsing }
  49.  
  50. function Trim(var S : String) : String;
  51. { FAST assembly language Trim routine, trims leading and trailing }
  52.  
  53. function SearchBlock(var FindStr; FindSize : Word; var Block;
  54.             BlockSize : Word) : Word;
  55. { generic Block search routine.  Takes untyped VAR parameters }
  56.  
  57. procedure ReplaceString(StrToFind,StrToRep : Str80; var S : String);
  58. { Finds StrToFind and replaces it with StrToRep in string S. }
  59. { ignores case when searching for the string to replace.     }
  60.  
  61. function RightStr(S : String; Number : Word) : String;
  62. { returns all characters to the right of character Number }
  63.  
  64. function ParseWord(var S : String; DelimChar : Char) : String;
  65. { parses input string S up to the first occurance of DelimChar. }
  66. { The parsed string is returned, and chopped out of the string S}
  67. { see WordOnLine implementation for sample use of ParseWord     }
  68.  
  69. function WordOnLine(var The_Word,The_Line : String) : Boolean;
  70. { returns TRUE if The_Word appears on The_Line }
  71.  
  72. function FileExt(PName : Path; Extension : Str3) : Path;
  73. { force a file extension }
  74.  
  75. function InKey(var ScanCode : Byte) : Char;
  76. { return character and scancode with a single call }
  77.  
  78. implementation
  79.  
  80. { the external Assembly language routines: }
  81.  
  82. {   MACROS.asm}
  83.  
  84. {$L UCASE.OBJ}
  85. {$L MEMCOMP.OBJ}
  86. {$L EXPTABS.OBJ}
  87. {$L TRIM.OBJ}
  88. {$L SEARCH.OBJ}
  89. {$L PARSE.OBJ}
  90. {$L INKEY.OBJ}
  91. {$L RIGHTSTR.OBJ}
  92.  
  93. function UpperCase(S : String) : String; External;
  94.  
  95. function CompMem(var Block1,Block2; Size : Word) : Word; External;
  96.  
  97. function ExpandTabs(var S : String) : String; External;
  98.  
  99. function Trim(var S : String) : String; External;
  100.  
  101. function SearchBlock(var FindStr; FindSize : Word; var Block;
  102.             BlockSize : Word) : Word; External;
  103.  
  104. function ParseWord(var S : String; DelimChar : Char) : String; External;
  105.  
  106. function InKey(var ScanCode : Byte) : Char; External;
  107.  
  108. function RightStr(S : String; Number : Word) : String; External;
  109.  
  110. procedure ReplaceString(StrToFind,StrToRep : Str80; var S : String);
  111.  
  112. var
  113.   L,P              : Word;
  114.   SS               : String; {scratch string }
  115.   STF,STR          : Str80;
  116.  
  117. begin
  118.   SS := UpperCase(S); {use the scratch string }
  119.   STF := UpperCase(StrToFind);
  120.   STR  := UpperCase(StrToRep);
  121.   L := Length(SS);
  122.   P := SearchBlock(STF[1],Length(STF),SS[1],L);
  123.  
  124.   if P > 0 then begin
  125.     Delete(S,P,Length(StrToFind));
  126.     if Length(StrToRep) > 0 then
  127.       Insert(StrToRep,S,P);
  128.   end;
  129.  
  130. end;
  131.  
  132. function WordOnLine(var The_Word,The_Line : String) : Boolean;
  133. { returns TRUE if The_Word appears on The_Line }
  134.  
  135. var
  136.   S                : String; {scratch string }
  137.   Wrd              : Str80;  { the parsed word }
  138.  
  139. begin
  140.   S := Trim(The_Line);
  141.   while Length(S) > 0 do begin
  142.     Wrd := ParseWord(S,' ');
  143.     S := Trim(S);
  144.     if CompMem(Wrd,The_Word,
  145.                Succ(Length(Wrd))) = _EQUAL_ then begin
  146.       WordOnLine := TRUE;
  147.       Exit;
  148.     end;
  149.   end;
  150.   WordOnLine := FALSE;
  151. end;
  152.  
  153. function FileExt(PName : Path; Extension : Str3) : Path;
  154.  
  155. var
  156.   Position,L       : Word;
  157.  
  158.   PathName         : Path;
  159.  
  160. const
  161.   Period           : String[1] = '.';
  162.  
  163. begin
  164.   PathName := PName;
  165.   Position := Pos(Period,PathName);
  166.   if Position > 0 then begin
  167.     L := Length(PathName);
  168.     PathName[0] := Char(L - Succ(L - Position));
  169.   end;
  170.   FileExt := PathName + '.' + Extension;
  171. end;
  172.  
  173. end.
  174.  
  175.