Program Srchname;
uses portfolio;

VAR
   file_in : text;
   infile_name : string;
   linex : array [1..40] of string;
   number_of_lines : char;
   Search_String : string[40];
   dummy : char;
   End_Flag : boolean;
   Sound_Switch : boolean;

Procedure Get_Search_String;
begin
    ClrScr;
    write('Enter search value: ');
    readln(Search_String);
end;

Procedure Open_Files;
begin
   Assign (File_In, infile_name);
   Reset(File_In);
end;

Procedure Pause_Display;
begin
     Write('Press A Key To Continue...');
     If Sound_Switch then
        PortBeep;
     dummy := ReadKey;
     writeln;
end;

Procedure Display_Record(no_lines:integer);
Var
   i, k : integer;

begin
       i := no_lines;
       ClrScr;
       for k := 1 to i do
           begin
           writeln(linex[k]);
           if (k mod 6) = 0 then
              Pause_Display;
           end;
       If (no_lines mod 6) <> 0 then
          begin
          Write('Press A Key To Continue...ESC to End...');
          If Sound_Switch then
             PortBeep;
          Dummy := ReadKey;
          If dummy = chr(27) then
             End_Flag := True;
          end;

end;


Procedure Search_Record(no_lines:integer);
Var
   i, k, x : integer;
   found_flag : boolean;
begin
    i := no_lines;
    found_flag := false;
    for k := 1 to i do
        begin
        x := pos(Search_String,linex[k]);
        if x > 0 then
           found_flag := true;
        end;
    if found_flag then
       Display_Record(i);
end;

Procedure Process_Records;
VAR
   i, j : integer;
begin
   While (not eof (File_In)) and (not End_Flag)do
         begin
              i := 0;
              j := 1;
              while j > 0 do
                    begin
                    i := i + 1;
                    readln(file_in,linex[i]);
                    j := length(linex[i]);
                    end;
              i := i - 1;
         Search_Record(i);
         end;

end;

Procedure Close_Files;
begin
    Close(File_In);
    ClrScr;
end;

Begin
   End_Flag := False;
   If ParamCount > 0 then
      Search_String := ParamStr(1)
      else
      Get_Search_String;
   If ParamCount > 1 then
      Infile_Name := ParamStr(2)
      else
      Infile_Name := 'a:\a.adr';
   Sound_Switch := True;
   Open_Files;
   Process_Records;
   Close_Files;
end.