File : messages.adb


with Ada.Text_IO, Ada.Command_Line, Ada.Strings.Fixed;
use Ada.Text_IO;

pragma Elaborate_All (Ada.Text_IO, Ada.Command_Line, Ada.Strings.Fixed);

package body Messages is

  Dots: constant String := ". . . . . . . . . . . . . . . . . . . . ";

  procedure Message(Where: in String; What: in Problem) is
  begin
    Put_Line(Where & ": " & What'Img);
    raise Constraint_Error;  -- comment this out if you want to continue anyway
  end Message;

  procedure TraceEnter(Where: in String) is
    use Ada.Strings.Fixed;
  begin
    if Tracing then
      Put_Line(Head(Dots,2*TraceLevel) & "[ " & Where);
      TraceLevel := TraceLevel+1;
    end if;
  end TraceEnter;

  procedure TraceLeave is
    use Ada.Strings.Fixed;
  begin
    if Tracing then
      TraceLevel := TraceLevel-1;
      Put_Line(Head(Dots,2*TraceLevel) & "]");
    end if;
  end TraceLeave;

  procedure Trace is
  begin
    Tracing := True;
  end Trace;

  package Txt_Int_IO is new Ada.Text_IO.Integer_IO(Integer);
  package Txt_Rep_IO is new Ada.Text_IO.Float_IO(Rep);

  procedure Show(S: in String; NewLine: in Boolean := True) is
  begin
    Put(Current_Output,S);
    if NewLine then New_Line; end if;
  end Show;

  procedure Show(S: in String; I: in Integer; NewLine: in Boolean := True) is
  begin
    Put(S);
    Txt_Int_IO.Put(Current_Output,I);
    if NewLine then New_Line; end if;
  end Show;

  procedure Show(S: in String; R: in Rep; A: in Natural := 5; E: in Natural := 3) is
  begin
    Put(S);
    Txt_Rep_IO.Put(File=>Current_Output, Item=>R, Aft=>A, Exp=>E);
    New_Line;
  end Show;

  procedure Show(S: in String; R1,R2: in Rep; A: in Natural := 5; E: in Natural := 3) is
  begin
    Put(S & "( ");
    Txt_Rep_IO.Put(File=>Current_Output, Item=>R1, Aft=>A, Exp=>E);
    Put(" , ");
    Txt_Rep_IO.Put(File=>Current_Output, Item=>R2, Aft=>A, Exp=>E);
    Put_Line(" )");
  end Show;

  function GetArg(N: Positive) return String is
    use Ada.Command_Line;
  begin
    return Argument(N);
  end GetArg;

  function GetArg(N: Positive) return Integer is
    use Ada.Command_Line;
    M,L: Integer;
  begin
    Txt_Int_IO.Get(Argument(N),M,L);
    return M;
  end GetArg;

  function GetArg(N: Positive) return Rep is
-- careful, input may get rounded
    use Ada.Command_Line;
    L: Integer;
    R: Rep;
  begin
    Txt_Rep_IO.Get(Argument(N),R,L);
    return R;
  end GetArg;

end Messages;