DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦f8e76f3ad⟧ Ada Source

    Length: 14336 (0x3800)
    Types: Ada Source
    Notes: 03_class, FILE, R1k_Segment, e3_tag, package body Line_Buffer_Bounded_Width, seg_0046dc

Derivation

└─⟦8527c1e9b⟧ Bits:30000544 8mm tape, Rational 1000, Arrival backup of disks in PAM's R1000
    └─ ⟦cfc2e13cd⟧ »Space Info Vol 2« 
        └─⟦this⟧ 

E3 Source Code



with Unbounded_String;
with String_Utilities;
with Table_Sort_Generic;
package body Line_Buffer_Bounded_Width is

    package Unbounded is new Unbounded_String (256);

    procedure Reset (The_Buffer : in out Buffer) is
    begin
        The_Buffer.Current := 1;
        The_Buffer.Size    := 0;
    end Reset;

    procedure Append (The_Buffer :        Buffer;  
                      To         : in out Buffer) is
    begin
        if The_Buffer.Size + To.Size > To.Length then
            raise Overflow;
        else
            To.Buf (To.Current .. To.Current + The_Buffer.Size - 1) :=
               The_Buffer.Buf (1 .. The_Buffer.Size);  
            To.Current := To.Current + The_Buffer.Size;
            To.Size := To.Size + The_Buffer.Size;
        end if;
    end Append;

    procedure Append_Line (The_Line : Line; To : in out Buffer) is
    begin
        if To.Current > To.Length or The_Line'Length > Width then
            raise Overflow;
        else
            Bounded_String.Copy (To.Buf (To.Current), The_Line);
            To.Current := To.Current + 1;
            To.Size    := To.Size + 1;
        end if;
    end Append_Line;

    procedure Prepend_Line (The_Line : Line; To : in out Buffer) is
    begin
        if To.Current > To.Length or The_Line'Length > Width then
            raise Overflow;
        else
            To.Buf (2 .. To.Size + 1) := To.Buf (1 .. To.Size);
            Bounded_String.Copy (To.Buf (1), The_Line);
            To.Current := To.Current + 1;
            To.Size    := To.Size + 1;
        end if;
    end Prepend_Line;

    procedure Overwrite (The_Line    :        Line;
                         At_Location :        Positive;
                         To          : in out Buffer) is
    begin
        if The_Line'Length > Width then
            raise Overflow;
        end if;
        if At_Location <= To.Length and At_Location <= To.Size then
            Bounded_String.Copy (To.Buf (At_Location), The_Line);
        else
            raise Overflow;
        end if;
    end Overwrite;

    procedure Remove (Line_At_Location :        Positive;  
                      In_Buffer        : in out Buffer) is
    begin
        if Line_At_Location <= In_Buffer.Size then
            In_Buffer.Buf (Line_At_Location .. In_Buffer.Size - 1) :=
               In_Buffer.Buf (Line_At_Location + 1 .. In_Buffer.Size);
            In_Buffer.Size := In_Buffer.Size - 1;
            In_Buffer.Current := In_Buffer.Current - 1;
        else
            raise Overflow;
        end if;
    end Remove;

    function Buffer_Length (Of_Buffer : Buffer) return Natural is
    begin
        return Natural (Of_Buffer.Size);
    end Buffer_Length;

    function String_Image (Of_Buffer : Buffer; Add_Line_Feeds : Boolean := True)
                          return String is
        Image : Unbounded.Variable_String;
    begin
        for I in 1 .. Of_Buffer.Size loop
            Unbounded.Append (Image, Bounded_String.Image (Of_Buffer.Buf (I)));
            if Add_Line_Feeds then
                Unbounded.Append (Image, Ascii.Lf);
            end if;
        end loop;
        return Unbounded.Image (Image);
    end String_Image;

    procedure Prepend (Text : String; To_All_Lines_In_Buffer : in out Buffer) is
    begin
        for I in 1 .. To_All_Lines_In_Buffer.Size loop
            Bounded_String.Insert (To_All_Lines_In_Buffer.Buf (I), 1, Text);
        end loop;
    exception
        when Constraint_Error =>
            raise Overflow;
    end Prepend;

    procedure Append (Text : String; To_All_Lines_In_Buffer : in out Buffer) is
    begin
        for I in 1 .. To_All_Lines_In_Buffer.Size loop
            Bounded_String.Append (To_All_Lines_In_Buffer.Buf (I), Text);
        end loop;
    exception
        when Constraint_Error =>
            raise Overflow;
    end Append;

    procedure Modify (The_Buffer : in out Buffer) is
    begin
        for I in 1 .. The_Buffer.Size loop
            Bounded_String.Copy (The_Buffer.Buf (I),
                                 Process (Bounded_String.Image
                                             (The_Buffer.Buf (I))));
        end loop;

    exception
        when Constraint_Error =>
            raise Overflow;
    end Modify;

    procedure Strip (The_Buffer : in out Buffer; Char : Character := ' ') is

        function Process (The_Line : Line) return Line is
        begin
            return String_Utilities.Strip (The_Line, Char);
        end Process;

        procedure Str is new Modify (Process);
    begin
        Str (The_Buffer);
    end Strip;

    procedure Strip_Leading (The_Buffer : in out Buffer;
                             Char       :        Character := ' ') is
        function Process (The_Line : Line) return Line is
        begin
            return String_Utilities.Strip_Leading (The_Line, Char);
        end Process;

        procedure Str is new Modify (Process);
    begin
        Str (The_Buffer);
    end Strip_Leading;

    procedure Strip_Trailing (The_Buffer : in out Buffer;
                              Char       :        Character := ' ') is

        function Process (The_Line : Line) return Line is
        begin
            return String_Utilities.Strip_Trailing (The_Line, Char);
        end Process;

        procedure Str is new Modify (Process);
    begin
        Str (The_Buffer);
    end Strip_Trailing;

    procedure Filter (The_Buffer : in out Buffer) is
        Filtered_Buffer : Buffer (The_Buffer.Length);
    begin
        for I in 1 .. The_Buffer.Size loop
            declare
                Line : constant String :=
                   Bounded_String.Image (The_Buffer.Buf (I));
            begin
                if not Discard (Line) then
                    Append_Line (Line, To => Filtered_Buffer);
                end if;
            end;
        end loop;
        The_Buffer := Filtered_Buffer;
    end Filter;

    procedure Sort (The_Buffer : in out Buffer) is

        The_Buf : Buffer_Lines (1 .. The_Buffer.Size) :=
           The_Buffer.Buf (1 .. The_Buffer.Size);

        function "<" (Left, Right : Var_String) return Boolean is
        begin
            return Bounded_String.Image (Left) < Bounded_String.Image (Right);
        end "<";

        procedure Buffer_Sort is
           new Table_Sort_Generic (Var_String, Positive, Buffer_Lines, "<");
    begin
        Buffer_Sort (The_Buf);
        The_Buffer.Buf (1 .. The_Buffer.Size) := The_Buf;
    end Sort;

    function Max (Left, Right : Natural) return Positive is
    begin
        if Left > Right then
            return Left;
        else
            return Right;
        end if;
    end Max;

    procedure Left_Right_Justify (The_Buffer : in out Buffer) is
        Max_Break : Natural := 0;  
    begin
        for I in 1 .. The_Buffer.Size loop

            declare
                Line          : constant String :=
                   Bounded_String.Image (The_Buffer.Buf (I));
                Current_Break : Natural         := Break_Point (Line);
            begin
                if Current_Break > Line'Last or else
                   Current_Break < Line'First then
                    null;
                else
                    Max_Break := Max (Max_Break, Current_Break);
                end if;
            end;
        end loop;

        for I in 1 .. The_Buffer.Size loop
            declare
                Line : constant String :=
                   Bounded_String.Image (The_Buffer.Buf (I));
                Current_Break : constant Positive := Break_Point (Line);
                Pad : constant String (1 .. Max_Break - Current_Break + 1) :=
                   (others => ' ');
            begin
                if Current_Break > Line'Last or else
                   Current_Break < Line'First then

                    Bounded_String.Copy (The_Buffer.Buf (I), Line);
                else
                    Bounded_String.Copy
                       (The_Buffer.Buf (I),
                        Line (Line'First .. Current_Break - 1) &
                           Pad & Line (Current_Break .. Line'Last));
                end if;
            end;
        end loop;

    end Left_Right_Justify;

    procedure Display (The_Buffer : Buffer) is
    begin
        for I in 1 .. The_Buffer.Size loop
            Put_Line (Bounded_String.Image (The_Buffer.Buf (I)));
        end loop;
    end Display;

    procedure Init (Iter : in out Iterator; From_Buffer : Buffer) is
    begin
        Iter         := new Buffer'(From_Buffer);
        Iter.Current := 1;
    end Init;

    function Done (Iter : Iterator) return Boolean is
    begin
        return Iter.Current > Iter.Size;
    end Done;

    function Value (Iter : Iterator) return Line is
    begin
        return Bounded_String.Image (Iter.Buf (Iter.Current));
    end Value;

    procedure Next (Iter : in out Iterator) is
    begin
        Iter.Current := Iter.Current + 1;
    end Next;
end Line_Buffer_Bounded_Width;

E3 Meta Data

    nblk1=d
    nid=0
    hdr6=1a
        [0x00] rec0=1f rec1=00 rec2=01 rec3=032
        [0x01] rec0=00 rec1=00 rec2=0d rec3=004
        [0x02] rec0=1c rec1=00 rec2=02 rec3=01c
        [0x03] rec0=00 rec1=00 rec2=0c rec3=00c
        [0x04] rec0=1c rec1=00 rec2=03 rec3=026
        [0x05] rec0=1d rec1=00 rec2=04 rec3=00a
        [0x06] rec0=1d rec1=00 rec2=05 rec3=040
        [0x07] rec0=1e rec1=00 rec2=06 rec3=05c
        [0x08] rec0=21 rec1=00 rec2=07 rec3=080
        [0x09] rec0=1b rec1=00 rec2=08 rec3=00a
        [0x0a] rec0=00 rec1=00 rec2=0b rec3=022
        [0x0b] rec0=1e rec1=00 rec2=09 rec3=050
        [0x0c] rec0=0d rec1=00 rec2=0a rec3=000
    tail 0x217002a3c815c6735d629 0x42a00088462061e03