--
-- PAGER by Richard Conn, TI Ada Technology Branch
-- Version 1.0, 10 Mar 85
-- Version 1.1, 13 Mar 85
-- Version 1.2, 14 Mar 85
-- Version 1.3, 4 Apr 85
-- Version 1.4, 8 Apr 85
-- Version 1.5, 6 May 85
--
with Text_Io, Pager_Support;
procedure Pager is

    Version : constant String := "PAGER, Version 1.5";
    Current_File_Name : String (1 .. Pager_Support.File_Name_Length) :=
       (others => Ascii.Nul);
    Current_File_Name_Length : Natural := 0;

    No_File_Name : exception;

    procedure Comment_Message is
    begin
        Text_Io.Put ("  Comment Prefix is ");

        if Pager_Support.Comment_Prefix then
            Text_Io.Put_Line ("Enabled");
        else
            Text_Io.Put_Line ("Disabled");
        end if;
    end Comment_Message;

    procedure Include_Message is
    begin
        Text_Io.Put ("  Include File Prefix is ");

        if Pager_Support.Include_File_Prefix then
            Text_Io.Put_Line ("Enabled");
        else
            Text_Io.Put_Line ("Disabled");
        end if;
    end Include_Message;

    procedure Verbose_Message is
    begin
        Text_Io.Put ("  Verbose Mode is ");

        if Pager_Support.Verbose then
            Text_Io.Put_Line ("Enabled");
        else
            Text_Io.Put_Line ("Disabled");
        end if;
    end Verbose_Message;

begin
    Text_Io.Put_Line (Version);
    Text_Io.Put_Line ("Type HELP for Help");

    loop
        begin
            Text_Io.Put ("PAGER> ");

            case Pager_Support.Command is
                when '-' =>
                    null;
                when 'C' =>
                    if Pager_Support.Input_File_Name_Length > 0 then
                        Current_File_Name := Pager_Support.Input_File_Name;
                        Current_File_Name_Length :=
                           Pager_Support.Input_File_Name_Length;
                    else
                        raise No_File_Name;
                    end if;

                    Pager_Support.Ada_Check
                       (Current_File_Name (1 .. Current_File_Name_Length));
                when 'H' =>
                    Text_Io.Put_Line ("PAGER Commands:");
                    Text_Io.Put_Line (" CHECK filename  --  Ada Check on File");
                    Text_Io.Put_Line (" PAGE filename   --  Create Paged File");
                    Text_Io.Put_Line
                       (" SCAN filename   --  List Files in Paged File");
                    Text_Io.Put_Line
                       (" TOGGLE          --  Indicate Flag Settings");
                    Text_Io.Put_Line
                       (" TOGGLE flag     --  Toggle Indicated Flag:");
                    Text_Io.Put_Line
                       ("                     Comment, Include File, or");
                    Text_Io.Put_Line ("                     Verbose");
                    Text_Io.Put_Line
                       (" UNPAGE filename --  Extract from Paged File");
                    Text_Io.Put_Line (" X (Exit)        --  Exit PAGER");
                when 'P' =>
                    if Pager_Support.Input_File_Name_Length > 0 then
                        Current_File_Name := Pager_Support.Input_File_Name;
                        Current_File_Name_Length :=
                           Pager_Support.Input_File_Name_Length;
                    else
                        raise No_File_Name;
                    end if;

                    Pager_Support.Page (Current_File_Name
                                           (1 .. Current_File_Name_Length));
                when 'S' =>
                    if Pager_Support.Input_File_Name_Length > 0 then
                        Current_File_Name := Pager_Support.Input_File_Name;
                        Current_File_Name_Length :=
                           Pager_Support.Input_File_Name_Length;
                    else
                        raise No_File_Name;
                    end if;

                    Pager_Support.Scanpage (Current_File_Name
                                               (1 .. Current_File_Name_Length));
                when 'T' =>
                    if Pager_Support.Input_File_Name_Length > 0 then
                        case Pager_Support.Input_File_Name (1) is
                            when 'c' | 'C' =>
                                Pager_Support.Comment_Prefix :=
                                   not Pager_Support.Comment_Prefix;
                                Comment_Message;
                            when 'i' | 'I' =>
                                Pager_Support.Include_File_Prefix :=
                                   not Pager_Support.Include_File_Prefix;
                                Include_Message;
                            when 'v' | 'V' =>
                                Pager_Support.Verbose :=
                                   not Pager_Support.Verbose;
                                Verbose_Message;
                            when others =>
                                Text_Io.Put_Line ("    Invalid Toggle Option");
                        end case;
                    else
                        Comment_Message;
                        Include_Message;
                        Verbose_Message;
                    end if;
                when 'U' =>
                    if Pager_Support.Input_File_Name_Length > 0 then
                        Current_File_Name := Pager_Support.Input_File_Name;
                        Current_File_Name_Length :=
                           Pager_Support.Input_File_Name_Length;
                    else
                        raise No_File_Name;
                    end if;

                    Pager_Support.Unpage (Current_File_Name
                                             (1 .. Current_File_Name_Length));
                when 'X' =>
                    exit;
                when others =>
                    Text_Io.Put_Line ("    Invalid Command - Use HELP Command");
            end case;
        exception
            when No_File_Name =>
                Text_Io.Put_Line ("    File Name Missing from Command");
            when others =>
                null;
        end;
    end loop;
end Pager;
