DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

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 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ B T

⟦267835ce0⟧ TextFile

    Length: 13781 (0x35d5)
    Types: TextFile
    Names: »B«

Derivation

└─⟦85b835f43⟧ Bits:30000549 8mm tape, Rational 1000, Xlib rev 6.00
    └─ ⟦0c20f784e⟧ »DATA« 
        └─⟦1abbe589f⟧ 
            └─⟦591c5b094⟧ 
                └─⟦this⟧ 

TextFile

with Text_Io;
use Text_Io;
with Vstring_Heap;
use Vstring_Heap;
with Vstring_Type;
use Vstring_Type;

package body Vstring_Io is
------------------------------------------------------------------------------
-- Vstring I/O
------------------------------------------------------------------------------
-- Copyright 1988 - 1991 by Rational, Santa Clara, California.
--
--                  All Rights Reserved.
--
-- Permission to use, copy, modify, and distribute this software and its
-- documentation for any purpose and without fee is hereby granted,
-- provided that the above copyright notice(s) appear in all copies and that
-- both that copyright notice(s) and this permission notice appear in
-- supporting documentation, and that the name of Rational not be used in
-- advertising or publicity pertaining to distribution of the software
-- without specific, written prior permission.
--
-- Rational disclaims all warranties with regard to this software, including
-- all implied warranties of merchantability and fitness, in no event shall
-- Rational be liable for any special, indirect or consequential damages or
-- any damages whatsoever resulting from loss of use, data or profits, whether
-- in an action of contract, negligence or other tortious action, arising out
-- of or in connection with the use or performance of this software.
------------------------------------------------------------------------------

----Some Text_Io's have problems with strings(1..Natural'Last) so we'll do
--  approximately (1..Natural'Last/2) at most in one I/O.

    Natural_Last : constant S_Natural := (S_Natural (Natural'Last) + 1) / 2;

--\f

    procedure Get (File        :        Text_Io.File_Type;  
                   Line        : in out Vstring_Data;
                   End_Of_Line : in out Boolean;
                   End_Of_Page : in out Boolean;
                   End_Of_File : in out Boolean) is
----Just line Get.  Get all or part of a line.
--  End_Of_Line iff Item contains the end of line (possibly null)
--  End_Of_Page iff End_Of_Line and this is the last line of the page
--  End_Of_File iff End_Of_Page and this is the last page of the file
--
--  The intent if for each call to return as many characters from the
--  line as fit, but Line.Length /= Line.Maximum_Length doesn't imply
--  End_Of_Line.
        Lno    : Positive_Count := Text_Io.Line (File);
        Pno    : Positive_Count := Text_Io.Page (File);
        Length : Natural;
        Buffer : String (1 .. Natural (Min (512, Line.Maximum_Length)));
    begin

        if Text_Io.End_Of_File (File) then
            Line.Length := 0;
            End_Of_File := True;
            End_Of_Page := True;
            End_Of_Line := True;
            return;
        end if;
        Get_Line (File, Buffer, Length);
        Line.Length                   := S_Natural (Length);
        Line.Chars (1 .. Line.Length) := E_String (Buffer (1 .. Length));
        while Line.Length < Line.Maximum_Length and then  
                 not Text_Io.End_Of_Line (File) loop
            if S_Natural (Buffer'Length) >
               Line.Maximum_Length - Line.Length then
                Get_Line
                   (File,  
                    Buffer (1 .. Natural (Line.Maximum_Length - Line.Length)),  
                    Length);
            else
                Get_Line (File, Buffer, Length);
            end if;
            Line.Chars (Line.Length + 1 .. Line.Length + S_Natural (Length)) :=
               E_String (Buffer (1 .. Length));
            Line.Length := Line.Length + S_Natural (Length);
        end loop;
        End_Of_File := Text_Io.End_Of_File (File);
        End_Of_Page := End_Of_File or else  
                          Pno /= Text_Io.Page (File);
        End_Of_Line := End_Of_Page or else  
                          Lno /= Text_Io.Line (File);

    end Get;

--\f

    procedure Get (File        :        Text_Io.File_Type;  
                   Line        :        Vstring;
                   End_Of_Line : in out Boolean;
                   End_Of_Page : in out Boolean;
                   End_Of_File : in out Boolean) is
----Just line Get.  Get all or part of a line.
--  End_Of_Line iff Item contains the end of line (possibly null)
--  End_Of_Page iff End_Of_Line and this is the last line of the page
--  End_Of_File iff End_Of_Page and this is the last page of the file
--
--  The intent if for each call to return as many characters from the
--  line as fit, but Line.Length /= Line.Maximum_Length doesn't imply
--  End_Of_Line.
        Lno    : Positive_Count := Text_Io.Line (File);
        Pno    : Positive_Count := Text_Io.Page (File);
        Length : Natural;
        Buffer : String (1 .. Natural (Min (512, Line.Maximum_Length)));
    begin

        if Text_Io.End_Of_File (File) then
            Line.Length := 0;
            End_Of_File := True;
            End_Of_Page := True;
            End_Of_Line := True;
            return;
        end if;
        Get_Line (File, Buffer, Length);
        Line.Length                   := S_Natural (Length);
        Line.Chars (1 .. Line.Length) := E_String (Buffer (1 .. Length));
        while Line.Length < Line.Maximum_Length and then  
                 not Text_Io.End_Of_Line (File) loop
            if S_Natural (Buffer'Length) >
               Line.Maximum_Length - Line.Length then
                Get_Line
                   (File,  
                    Buffer (1 .. Natural (Line.Maximum_Length - Line.Length)),  
                    Length);
            else
                Get_Line (File, Buffer, Length);
            end if;
            Line.Chars (Line.Length + 1 .. Line.Length + S_Natural (Length)) :=
               E_String (Buffer (1 .. Length));
            Line.Length := Line.Length + S_Natural (Length);
        end loop;
        End_Of_File := Text_Io.End_Of_File (File);
        End_Of_Page := End_Of_File or else  
                          Pno /= Text_Io.Page (File);
        End_Of_Line := End_Of_Page or else  
                          Lno /= Text_Io.Line (File);

    end Get;

--\f

    procedure Get_Resize (File          :        Text_Io.File_Type;  
                          Line          : in out Vstring;
                          Resize_Amount :        S_Positive;  
                          End_Of_Line   : in out Boolean;
                          End_Of_Page   : in out Boolean;
                          End_Of_File   : in out Boolean) is
----Just like Get above except that Line will be continually resized
--  by Resize_Amount's until we can fit in an entire line (or until we
--  hit End_Of_Page/File).
        Lno    : Positive_Count := Text_Io.Line (File);
        Pno    : Positive_Count := Text_Io.Page (File);
        Length : Natural;
        Buffer : String (1 .. 512);
    begin

----Try to fit a line into the space available.

        if Text_Io.End_Of_File (File) then
            Line.Length := 0;
            End_Of_File := True;
            End_Of_Page := True;
            End_Of_Line := True;
            return;
        end if;
        Get_Line
           (File,  
            Buffer
               (1 .. Natural
                        (Min (S_Natural (Buffer'Last), Line.Maximum_Length))),  
            Length);
        Line.Length                   := S_Natural (Length);
        Line.Chars (1 .. Line.Length) := E_String (Buffer (1 .. Length));
        End_Of_File                   := Text_Io.End_Of_File (File);
        End_Of_Page                   := End_Of_File or else  
                                            Pno /= Text_Io.Page (File);
        End_Of_Line                   := End_Of_Page or else  
                                            Lno /= Text_Io.Line (File);

----If we succeeded then return our result.

        if End_Of_Line then
            return;
        end if;

----Loop until we hit End_Of something.

        declare
            Start  : S_Natural := Line.Length + 1;
            Finish : S_Natural;
        begin
            loop

----Grab up to the next 512 characters of line.

                Get_Line (File, Buffer, Length);

----Resize the buffer up one notch and then read into the new space.

                Finish := Line.Length + S_Natural (Length);
                if Finish > Line.Maximum_Length then
                    Resize_Vstring (Line, (Finish + Resize_Amount - 1)  
                                              / Resize_Amount * Resize_Amount);
                end if;

                Line.Chars (Start .. Finish) := E_String (Buffer (1 .. Length));
                Line.Length                  := Finish;

                End_Of_File := Text_Io.End_Of_File (File);
                End_Of_Page := End_Of_File or else  
                                  Pno /= Text_Io.Page (File);
                End_Of_Line := End_Of_Page or else  
                                  Lno /= Text_Io.Line (File);

----If we've reached End_Of something then set our length and return.

                Line.Length := Finish;
                if End_Of_Line then
                    return;
                end if;

----No luck, record the high-water mark and continue.

                Start := Finish + 1;
            end loop;
        end;

    end Get_Resize;

--\f

    procedure Put (Vstr : Vstring_Data) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 0 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
        end if;
    end Put;

--\f

    procedure Put (File : Text_Io.File_Type; Vstr : Vstring_Data) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 0 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (File, String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
        end if;
    end Put;

--\f

    procedure Put_Line (Vstr : Vstring_Data) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 1 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
            Put_Line (String (Vstr.Chars (Start .. Vstr.Length)));
        else
            New_Line;
        end if;
    end Put_Line;

--\f

    procedure Put_Line (File : Text_Io.File_Type; Vstr : Vstring_Data) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 1 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (File, String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
            Put_Line (File, String (Vstr.Chars (Start .. Vstr.Length)));
        else
            New_Line (File);
        end if;
    end Put_Line;

--\f

    procedure Put (Vstr : Vstring) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 0 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
        end if;
    end Put;

--\f

    procedure Put (File : Text_Io.File_Type; Vstr : Vstring) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 0 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (File, String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
        end if;
    end Put;

--\f

    procedure Put_Line (Vstr : Vstring) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 1 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
            Put_Line (String (Vstr.Chars (Start .. Vstr.Length)));
        else
            New_Line;
        end if;
    end Put_Line;

--\f

    procedure Put_Line (File : Text_Io.File_Type; Vstr : Vstring) is
----Do output of the contents of a Vstring.
        Start  : S_Natural := 1;
        Finish : S_Natural;
    begin
        if Vstr.Length > 0 then
            for I in S_Natural range 1 .. (Vstr.Length - 1) / Natural_Last loop
                Finish := Min (Vstr.Length, Start + Natural_Last - 1);
                Put (File, String (Vstr.Chars (Start .. Finish)));
                Start := Finish + 1;
            end loop;
            Put_Line (File, String (Vstr.Chars (Start .. Vstr.Length)));
        else
            New_Line (File);
        end if;
    end Put_Line;

--\f

end Vstring_Io;