with Type_Definitions, Simple_Paginated_Output, String_Pkg, Calendar;

----------------------
package Report_Library is
    --| Ada Test and Evaluation Tools Report Library
    ----------------------

    --| Overview
    --| NOSC_Report_Library is a library of procedures common to all of the
    --| NOSC Ada Test and Evaluation Tool Set (ATETS) report generators.

    --| N/A: Raises, Requires, Modifies, Errors

    use Type_Definitions;        --| Global type declarations for all ATETS tools

    use Simple_Paginated_Output; --| Output writer uses Text_IO;


    Minimum_Cpl : constant Integer := 40;
    Maximum_Cpl : constant Integer := 132;
    Minimum_Lpp : constant Integer := 24;
    Maximum_Lpp : constant Integer := 66;

    subtype Characters_Per_Line is Integer range Minimum_Cpl .. Maximum_Cpl;
    subtype Lines_Per_Page is Integer range Minimum_Lpp .. Maximum_Lpp;

    type Options is
    --| Report formatting options
        record
            Cpl : Characters_Per_Line;
            Page_Size : Lines_Per_Page;
            Tool_Name : Tool_Names;
            Tool_Version : String (1 .. 20);
        end record;

    subtype Header_Text is String_Pkg.String_Type;


    --------------------------
    procedure Open_Report_File
                 (--| Open the report file and set up formatting

                  Report : in out Paginated_File_Handle;
                  --| A "handle" for the report file

                  Report_File_Name : in
                     Filename;    --| The name of the report file

                  Format_Options : in Options   --| Report formatting options

                  );

    --| Effects
    --| This procedure opens the report file for output and sets up the
    --| report formatting options. If the report file already exists then
    --| it is overwritten. A "handle" for the report file is returned to
    --| the calling program. All output to the report file is performed via
    --| the package Pagenated_Output. Report formatting  options for the
    --| output writer are set up according to the parameters specified in
    --| Format_Options. Although no exceptions are raised by this procedure,
    --| any Text_IO or Pagenated_Output exceptions that may be raised are
    --| allowed to pass, unhandled, back to the calling program.

    --| N/A:  Raises, Requires, Modifies, Errors


    -----------------------------------------
    procedure Print_Test_Configuration_Report
                 (
                  --| Print log file test configuration data to report file

                  Report : in out
                  Paginated_File_Handle;   --| Output report file handle

                  Program_Name : in
                     Ada_Name;          --| Name of program under test

                  Log_File_Name : in Filename;          --| Name of the log file

                  Test_Date : in
                     Calendar.Time;     --| Date the log file was created

                  Test_Ident : in
                     Test_Identifier --| Test id specified by the user

                  );

    --| Effects
    --| This procedure prints configuration information obtained from
    --| the command line parameters and the Execution Log File  on the
    --| first page of the report file. All output to the report file
    --| is performed via the package Pagenated_Output. No logfile is specified
    --| as access to the logfile is not visible to the calling program.
    --| The following information is printed on the configuration page
    --| of the report file:
    --|
    --|     Program Name:  name of program under test
    --|     Test Date:     date of log file generation
    --|     Test Time:     time of log file generation
    --|     Report Date:   date of report generation
    --|     Report Time:   time of report generation
    --|     Logfile:       log file name

    --| N/A:  Raises, Requires, Modifies, Errors


    -------------------------------------
    procedure Put_Test_Configuration_Data
                 (
                  --| Put log file test configuration data to current output

                  Program_Name : in
                  Ada_Name;           --| The name of the program under test
                  Test_Date : in
                     Calendar.Time;      --| Date the log file was created
                  Test_Ident : in
                     Test_Identifier  --| Test id specified by the user

                  );

    --| Effects
    --| This procedure puts test configuration information obtained from
    --| the Execution Log File  to current output. The following information
    --| is output:
    --|
    --|     Program Under Test:  name of program under test
    --|     Test Date:           date of log file generation
    --|     Test Time:           time of log file generation
    --|     Test ID:             the test ID obtained from the log file
    --|

    --| N/A:  Raises, Requires, Modifies, Errors


    --------------
    function Query
                (--| Put a Yes or No question and get a response

                 Question : in String  --| A query to be answered Y or N

                 ) return Boolean;   --| True if answered Y, False if answered N

    --| Effects
    --| The user is then prompted with Question. The user's response is then
    --| tested for Y or N. Only the first character input is tested and
    --| case is not significant. If Y is input then Response is returned
    --| true. In N is input then Response is  returned false. If Neither
    --| Y nor N then the user is prompted again with Query.

    --| N/A:  Raises, Requires, Modifies, Errors


    ------------------
    function String_Of (--| Convert an integer to a string of length 1..Width

                        Int : in Integer;         --| The Integer to be converted

                        Width : in Natural :=
                           0  --| The width of the string to be returned

                        ) return String;

    --| Effects
    --| Converts the integer Int to a string of length Width. If Width = 0
    --| then the length of the string is equal to the number of digits in
    --| INT. If Width is greater than the number of digits in Int then the
    --| integer is right justified in the string and padded with blanks.


    ----------------
    function Replace (--| Replace characters in S1 at position Pos with S2

                      S1 : in String_Pkg.String_Type;
                      --| String_Type with characters to be replaced

                      S2 : in String_Pkg.String_Type;
                      --| String_Type to be inserted into copy of S2

                      Pos : in Natural
                      --| Position in S1 at which S2 is to be inserted

                      ) return String_Pkg.String_Type;

    --| Effects
    --| Returns  Substr( S1, 1, Pos-1 ) & S2 &
    --|              Substr( S1, Pos+Length(S2), Length(S1)-Pos-Len(S2) )

    --| N/A:  Raises, Requires, Modifies, Errors


    ----------------
    function Replace (--| Replace characters in S1 at position Pos with S2

                      S1 : in String_Pkg.String_Type;
                      --| String_Type with characters to be replaced

                      S2 : in String;
                      --| String to be inserted into copy of S2

                      Pos : in Natural
                      --| Position in S1 at which S2 is to be inserted

                      ) return String_Pkg.String_Type;

    --| Effects
    --| Returns  Substr( S1, 1, Pos-1 ) & S2 &
    --|              Substr( S1, Pos+Length(S2), Length(S1)-Pos-Len(S2) )

    --| N/A:  Raises, Requires, Modifies, Errors


    ---------------
    function Center
                ( --| Center text on header line

                 Text : in String;                 --| The text to be centered

                 Cpl : in
                    Characters_Per_Line  --| Length of header text, in characters,
                 --| to be created

                 )
                return Header_Text;

    --| Effects
    --| Returns a Header_Text line of length CPL with the input Text string
    --| centered on the line.

    --| N/A:  Raises, Requires, Modifies, Errors


end Report_Library;
