File : ints-io.adb



package body Ints.IO is

  function Width(I: Integer; Base: Positive := 10) return Positive is
    K,D: Integer;
  begin
    K := abs(I);
    if I<0 then D := 2; else D := 1; end if;
    while K >= Base loop
      K := K/Base;
      D := D+1;
    end loop;
    return D;
  end Width;

  function Strng(I: Integer; W: Positive) return String is
    S: String(1 .. W);
  begin
    Int_IO.Put(S,I);
    return S;
  end Strng;

  procedure Get(F: in File_Type; I: out Integer) is
  begin
    Int_IO.Get(F,I);
  end Get;

  procedure Put(F: in File_Type; I: in Integer; NewLine: in Boolean := True) is
  begin
    Int_IO.Put(F,I,Width(I)+1);
    if NewLine then New_Line(F); end if;
  end Put;

  procedure Show1(N: in String; I: in Integer) is
  begin
    Put(N);
    Int_IO.Put(I,Width(I)+1);
    New_Line;
  end Show1;

  procedure Show2(N: in String; I1,I2: in Integer) is
  begin
    Put(N);
    Int_IO.Put(I1,Width(I1)+1);
    Int_IO.Put(I2,Width(I2)+5);
    New_Line;
  end Show2;

end Ints.IO;