program tstssearch;

%include ex:[22,320]general3.typ;
%include ex:[22,320]string.pkg;

var
  string,typ1string,piece : packed array [1..15] of char;
  typ0string:packed array [0..15] of char;
  end_check:packed array [1..3] of char;
  i,len:integer;

begin
  writeln;
  writeln;
  writeln('Begin test of type1 string test. type "end" to quit.');
  writeln;
  repeat
    write('enter string to be searched: ');
    Sclear(typ1string);
    SRead(INPUT,typ1string);
    for i:= 1 to 3 do
      end_check[i] := typ1string[i];
    if (end_check <> 'end') and (end_check <> 'END')
     then 
       begin
       if Ssearch(typ1string,'te',1) > 0   
       then begin
          write('the substring "te" occurs in "',typ1string);
          write('" at position ',ssearch(typ1string,'te',1));
          writeln;
          end
       else begin
          write('the substring "te" does not occur in "');
          write(typ1string,'"');
          writeln;
          end;
       writeln;
       end
      else begin
           writeln;
           writeln('end of type1 string test.');
           end
  until (end_check = 'end') or (end_check = 'END');
  writeln;
  writeln('Begin test of type0 string test. type "end" to quit.');
  repeat
    write('enter string to be searched :');
    Sclear(typ0string);
    Sclear(string);
    SRead(INPUT,typ0string);
    len := slen(typ0string);
    for i:= 1 to len do
      string[i] := typ0string[i];
    for i:=1 to 3 do
      end_check[i]:=string[i];
    if (end_check <> 'end') and (end_check <> 'END') 
      then 
        begin
        if Ssearch(typ0string,'te',0) > 0 
         then begin
              write('the substring "te" occurs in "',string);
              write('" at position ',ssearch(typ0string,'te',0));
              writeln;
              end  
        else  begin
              write('the substring "te" does not occur in "');
              write(string,'"');
              writeln;
              end;
        writeln;
        end
      else begin
           writeln;
           writeln('end of type0 string test.');
           end;
  until (end_check = 'end') or (end_check = 'END');
  writeln;
  writeln;
  writeln;
  writeln('Begin test of type1 string test. type "end" to quit.');
  writeln;
  repeat
    write('enter string to be searched: ');
    Sclear(typ1string);
    SRead(INPUT,typ1string);
    for i:= 1 to 3 do
      end_check[i] := typ1string[i];
    if (end_check <> 'end') and (end_check <> 'END')
     then 
       begin
  writeln('enter piece');
  Sclear(piece);
  Sread(INPUT,piece);
       if Ssearch(typ1string,piece,1) > 0   
       then begin
          write('the substring "',piece,'" occurs in "',typ1string);
          write('" at position ',ssearch(typ1string,piece,1));
          writeln;
          end
       else begin
          write('the substring "',piece,'" does not occur in "');
          write(typ1string,'"');
          writeln;
          end;
       writeln;
       end
      else begin
           writeln;
           writeln('end of type1 string test.');
           end
  until (end_check = 'end') or (end_check = 'END');
  writeln;
  writeln('Begin test of type0 string test. type "end" to quit.');
  repeat
    write('enter string to be searched :');
    Sclear(typ0string);
    Sclear(string);
    SRead(INPUT,typ0string);
    len := slen(typ0string);
    for i:= 1 to len do
      string[i] := typ0string[i];
    for i:=1 to 3 do
      end_check[i]:=string[i];
    if (end_check <> 'end') and (end_check <> 'END') 
      then 
        begin
        writeln('enter piece');
        Sclear(piece);
        Sread(INPUT,piece);
        if Ssearch(typ0string,piece,0) > 0 
         then begin
              write('the substring "',piece,'" occurs in "',string);
              write('" at position ',ssearch(typ0string,piece,0));
              writeln;
              end  
        else  begin
              write('the substring "',piece,'" does not occur in "');
              write(string,'"');
              writeln;
              end;
        writeln;
        end
      else begin
           writeln;
           writeln('end of type0 string test.');
           end;
  until (end_check = 'end') or (end_check = 'END');
  writeln;
  writeln('end of Ssearch test.');
end.
