with Instrument;
use Instrument;
-- BENCHMARK   CHARACTER STRING SEARCH.
procedure Chssa1 is
    -- PRAGMA SUPPRESS (ACCESS_CHECK);
    -- PRAGMA SUPPRESS (DISCRIMINANT_CHECK);
    -- PRAGMA SUPPRESS (INDEX_CHECK);
    -- PRAGMA SUPPRESS (LENGTH_CHECK);
    -- PRAGMA SUPPRESS (RANGE_CHECK);
    -- PRAGMA SUPPRESS (DIVISION_CHECK);
    -- PRAGMA SUPPRESS (OVERFLOW_CHECK);
    -- PRAGMA SUPPRESS (STORAGE_CHECK);

    subtype Short_Integer is Integer;
    type String is array (1 .. 120) of Character;
    Numiterations : constant Integer := 10000;
    -- TO MAKE IT MILLISECONDS/SEC
    Position_To_Pass : Short_Integer;

    function Strsch (S, K : in String; Ns, Nk : in Short_Integer)
                    return Short_Integer is

        I, J : Short_Integer;
        Base, Ksave, Cont : Short_Integer;
        Kend, Ssave : Short_Integer;
        R : Short_Integer;
    begin
        Base := 1;
        Ksave := 1;
        Cont := Ns - Nk + Base;
        Kend := Ksave + Nk - 1;
        I := 1;

        J := 1;
        <<Top>>
            while S (I) /= K (J) loop
                if I >= Cont then
                    R := -1;
                    goto Finish;
                end if;
                I := I + 1;
            end loop;
        Ssave := I;
        J := J + 1;
        while J <= Kend loop
            I := I + 1;
            if S (I) /= K (J) then
                I := Ssave + 1;
                J := Ksave;
                goto Top;
            end if;
            J := J + 1;
        end loop;
        R := Ssave - Base + 1;
        <<Finish>> return (R);
    end Strsch;


    procedure Benche is
        S, K : String;
        Position : Short_Integer := 0;
        Ns, Nk : Short_Integer;
    begin
        S :=
           "000000000000000000000000000000000000000000000000000000000000HERE" &
              "000000" & "00000000000000000000HERE IS A MATCH000000000000000";
        K :=
           "HERE IS A MATCH                                                 " &
              "      " & "                                                  ";
        Ns := 120;
        Nk := 15;
        --    POSITION := STRSCH (S, K, NS, NK);
        Position_To_Pass := Position;
    end Benche;

begin
    Start ("CHSSA1", "Char. String Search (control)");
    for I in 1 .. Numiterations loop
        Benche;
    end loop;
    Stop;
end Chssa1;