File : messages.adb


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

pragma Elaborate_All (Ada.Text_IO, 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);
    Txt_Rep_IO.Put(File=>Current_Output, Item=>R2, Aft=>A, Exp=>E);
    Put_Line(" )");
  end Show;

  procedure PromptString(Name: in String; S: out String; Length: out Integer) is
  begin
    Put(Current_Output,Name);
    Length := 0;
    while Length=0 loop
      Get_Line(S,Length);
    end loop;
  end PromptString;

  function PromptInteger(Name: String) return Integer is
    I: Integer;
  begin
    Put(Current_Output,Name);
    Txt_Int_IO.Get(Current_Input,I);
    Put_Line("entered " & I'Img);
    return I;
  end PromptInteger;

  function PromptRep(Name: String) return Rep is
    R: Rep;
  begin
    Put(Current_Output,Name);
    Txt_Rep_IO.Get(Current_Input,R);
    Put_Line("entered " & R'Img);
    return R;
  end PromptRep;

end Messages;