Program FindItem(Input,Output);
{ ***************************************************************

       Program to search through a ASCII text file.
       Can be used to search thru PC-BLUE.CAT.
       to find volumn number to any key word or string.
       Will search for upper or lower case.
       Written using Turbo Pascal (c) V 3.0

       Pressing < ESC > will terminate search.

                  Written by Robert V. DiPippo
                        80 Pepin Street
                        West Warwick, RI 02893
                        401-821-6124


              Copyright 1987  DiPippo's Electronics, Inc.
                        80 Pepin Street
                        West Warwick, RI 02893
                        401-821-6124


  Released to the Public Domain for non-commerical use.

****************************************************************** }
Const
     CopyTitle1='File Search Program';
     CopyTitle2='Copyright 1987   DiPippo''s Electronics, Inc.';
     CopyTitle3='Written by Robert V. DiPippo';
Type
   A_Name=string[255];

Var
   Stop,Print,Ok:Boolean;

   A_File:text;
   Tab,x,y,Pg:integer;
   SaveLine,Line,NameOfFile,EnterLine:A_Name;
   Answer:char;

Procedure PrintTitle(TitleName:A_Name;PageNumber:integer);
begin
     Write(lst,'** FINDITEM **        ');
     Write(lst,CopyTitle2);
     Writeln(lst,'     Page# ',PageNumber);
     Writeln(lst);
     Write(lst,'Filename: [ ',NameOfFile,' ]');
     Tab:=(35+length(NameOfFile))-(length(TitleName));
     Writeln(lst,'Search String':Tab,' [ ',Titlename,' ]');
     Writeln(lst);
End;
Procedure Capitols(Var A_File_Name:A_Name);
Begin
     for x:=1 to length(A_File_Name) do
     Begin
         A_File_Name[x]:=UpCase(A_File_Name[x]);
         If Ord(A_File_Name[x])<32 Then
            A_File_Name[x]:=Chr(0);
     End;
End;
Procedure PrintName(A_File_Name:A_Name);
Begin
     For x:=1 to length(A_File_Name) do
         Write(chr(8));
     Writeln(A_File_Name);
End;

Procedure PressedKey(Var Stop:Boolean);
Var
      Choice:Char;
Begin
      If KeyPressed Then
       Begin
        Repeat
          Read(Kbd,Choice);
        Until Not KeyPressed;
        If choice=Chr(27) Then
        Begin
        Write('Terminate (Y/N)? ');
        Read(Kbd,Choice);
        If UpCase(Choice)='Y' Then
         Begin
          WriteLn(Upcase(Choice));
          Stop:=True;
         End
         Else
             Writeln;
        End;
       End;
End; { KeyPressed }
Begin

     For Y:=1 to 24 do
         Writeln;
     Print:=false;
     Tab:=Round(40+(length(CopyTitle1)/2));
     Writeln(CopyTitle1:tab);
     writeln;
     Tab:=Round(40+(length(CopyTitle2)/2));
     Writeln(CopyTitle2:tab);
     Tab:=Round(40+(length(CopyTitle3)/2));
     Writeln(CopyTitle3:Tab);
     For y:=1 to 10 do
         Writeln;
     Delay(3000);
     repeat
     for y:=1 to 25 do
         writeln;
     Writeln('Enter name of text file to search ');
     Write('--> ');
     Read(NameOfFile);
     Capitols(NameOfFile);
     PrintName(NameOfFile);
     Assign(A_File,NameOfFile);
     {$I-} Reset(A_File) {$I+};
     Ok:=(IOresult=0);
     If Ok then
     Begin
     Write('Output to printer < Y/N > ');
     Read(Kbd,Answer);
     Writeln(Upcase(Answer));
     If upcase(Answer)='Y' then
     Begin
          Print:=true;
          y:=0;
     End
      Else
          Print:=false;
     Writeln;

     Writeln('Enter a string of 20 or less characters to search for ');
     Write('---> ');
     Read(EnterLine);
     Capitols(EnterLine);
     PrintName(EnterLine);
     Writeln;
     Writeln('Press < ESC > to terminate ');
     Pg:=1;
     If Print then
        PrintTitle(enterline,pg);
        Stop:=False;
     While (not Eof(A_File)) and (not stop) Do
     Begin
          Readln(A_File,Line);
          SaveLine:=Line;
          PressedKey(Stop);
          Capitols(Line);
          If Pos(EnterLine,Line)>0 then
             If Print then
             Begin
                y:=y+1;
                If y>55 then
                Begin
                     Writeln(lst,chr(12));
                     Pg:=Pg+1;
                     PrintTitle(Enterline,pg);
                     y:=0;
                End;
                Writeln(lst,SaveLine);
             End
                Else
                   Writeln(SaveLine);
      End;
          If Print then writeln(lst,chr(12));

      End
         Else
             Writeln(chr(7),'File <  ',NameOfFile,'  > Not Found');
      Close(A_File);
      write('Continue  < Y/N > ');
      Read(kbd,answer);
      Writeln(Upcase(answer));
      Until(Upcase(answer)='N');
End.

