File : messages.adb


with Ada.Text_IO, Ada.Command_Line, Ada.Strings.Fixed, Ints.IO, Reps.IO;
use Ada.Text_IO, Ada.Command_Line, Ada.Strings.Fixed;

package body Messages is

  use Ints.IO.Int_IO, Reps.IO.Rep_IO;

  procedure Check(B: in Boolean) is
  begin
    if B then
      Put_Line("Check passed");
    else
      Put_Line("Check failed");
      raise Constraint_Error;
    end if;
    New_Line;
  end Check;

  procedure Show(S: in String; Skip: in Natural := 0; NewLine: in Boolean := True) is
  begin
    if Skip <= Verbosity then
      Put(S);
      if NewLine then New_Line; end if;
    end if;
  end Show;

  procedure Show(S: in String; R: in Rep; Skip: in Natural := 0) is
  begin
    if Skip <= Verbosity then
      Put(S);
      Put(R,3,DefaultAft,DefaultExp);
      New_Line;
    end if;
  end Show;

  procedure Show(S: in String; R1,R2: in Rep; Skip: in Natural := 0) is
  begin
    if Skip <= Verbosity then
      Put(S);
      Put(R1,3,DefaultAft,DefaultExp);
      Put(R2,3,DefaultAft,DefaultExp);
      New_Line;
    end if;
  end Show;

  procedure Show(S: in String; R1,R2,R3: in Rep; Skip: in Natural := 0) is
  begin
    if Skip <= Verbosity then
      Put(S);
      Put(R1,3,DefaultAft,DefaultExp);
      Put(R2,3,DefaultAft,DefaultExp);
      Put(R3,3,DefaultAft,DefaultExp);
      New_Line;
    end if;
  end Show;

  procedure Error(S: in String; Skip: in Natural := 0) is
  begin
    Show(S,Skip);
    if Skip=0 then raise Constraint_Error; end if;
  end Error;

  procedure Error(S: in String; R: in Rep; Skip: in Natural := 0) is
  begin
    Show(S,R,Skip);
    if Skip=0 then raise Constraint_Error; end if;
  end Error;

  procedure Error(S: in String; R1,R2: in Rep; Skip: in Natural := 0) is
  begin
    Show(S,R1,R2,Skip);
    if Skip=0 then raise Constraint_Error; end if;
  end Error;

  procedure Error(S: in String; R1,R2,R3: in Rep; Skip: in Natural := 0) is
  begin
    Show(S,R1,R2,R3,Skip);
    if Skip=0 then raise Constraint_Error; end if;
  end Error;

  procedure TraceEnter(Where: in String) is
  begin
    if Verbosity>1 then
      Put_Line(Head(Dots,2*Indent) & "[ " & Where);
      Indent := Indent+1;
    end if;
  end TraceEnter;

  procedure TraceLeave is
  begin
    if Verbosity>1 then
      Indent := Indent-1;
      Put_Line(Head(Dots,2*Indent) & "]");
    end if;
  end TraceLeave;

  function GetArg return Boolean is
    S: constant String := GetArg;
  begin
    if not (S="True") or (S="False") then
      Error("Messages.GetArg: non-Boolean value");
    end if;
    return S="True";
  end GetArg;

  function GetArg return Integer is
    M,L: Integer;
  begin
    Get(Argument(ArgIndex),M,L);
    ArgIndex := ArgIndex+1;
    return M;
  end GetArg;

  function GetArg return String is
    S: constant String := Argument(ArgIndex);
  begin
    ArgIndex := ArgIndex+1;
    return S;
  end GetArg;

  function GetArg return Rep is
-- careful, input may get rounded
    L: Integer;
    R: Rep;
  begin
    Get(Argument(ArgIndex),R,L);
    ArgIndex := ArgIndex+1;
    return R;
  end GetArg;

end Messages;