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;
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;
function PromptString(Name: in String) return String is
L: Integer := 0;
S: String(1 .. 255);
begin
Put(Current_Output,Name);
while L=0 loop
Get_Line(S,L);
end loop;
Put_Line("entered " & S(1 .. L));
return S(1 .. L);
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;
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
use Ada.Command_Line;
L: Integer;
R: Rep;
begin
Txt_Rep_IO.Get(Argument(N),R,L);
return R;
end GetArg;
function GetArg(N: Positive) return Boolean is
use Ada.Command_Line;
begin
if Argument(N)="True" then return True; end if;
if Argument(N)="False" then return False; end if;
Message("Messages.GetArg",Data_Problem);
return False;
end GetArg;
end Messages;