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

⟦a73f8c939⟧ TextFile

    Length: 13974 (0x3696)
    Types: TextFile
    Names: »B«

Derivation

└─⟦a7d1ea751⟧ Bits:30000550 8mm tape, Rational 1000, !users!projects 94_04_11
    └─ ⟦129cab021⟧ »DATA« 
        └─⟦this⟧ 

TextFile

with Arguments;
with Bounded_String;
with Easy_X;
with Message;
with Msg_Report;
with Object;
with Scanner;
with String_Class;
with String_Utilities;

package body Pen_Class is

    function Is_Equal_String
                (Str1 : String; Str2 : String; Ignore_Case : Boolean := True)
                return Boolean renames String_Utilities.Equal;

    function Bs_Image (Source : Scanner.B_String) return String
        renames Bounded_String.Image;

    procedure Bs_Copy (Target : in out Scanner.B_String; Source : String)
        renames Bounded_String.Copy;


    Max_Pen : constant Integer := 100;

    Pen_Table : array (1 .. Max_Pen) of Pen_Ref;


    -- initialisation de la table d'instance des stylos
    -- ================================================

    procedure Init_Instance_Table is
    begin  
        for Ref in Pen_Table'Range loop
            if Pen_Table (Ref).Indicator = Used then
                Pen_Table (Ref).Font := Small_Font;
                Pen_Table (Ref).X := 0;
                Pen_Table (Ref).Y := 0;
            end if;
        end loop;

    end Init_Instance_Table;


    -- creation d'un objet stylo
    -- =========================

    function Create return Object.Reference is

        use Object;

        Found : Boolean := False;
        Value : Integer;

    begin  
        for Ref in Pen_Table'Range loop
            if Pen_Table (Ref).Indicator = Unused then
                Found := True;
                Pen_Table (Ref).Indicator := Used;
                Value := Ref;
                exit;
            end if;
        end loop;  
        if Found then
            return Object.Create (C_Pen, Value);
        else
            Msg_Report.Interpret_Error
               ("Pen instance table full, creation of a new object impossible");
            raise Instance_Table_Full;
        end if;

    end Create;


    function Unary_Msg_X (The_Object : Object.Reference)
                         return Object.Reference is
        use Object;
        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        return Object.Create (C_Integer, Integer (Pen_Table (Ref).X));

    end Unary_Msg_X;


    function Unary_Msg_Y (The_Object : Object.Reference)
                         return Object.Reference is
        use Object;
        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        return Object.Create (C_Integer, Integer (Pen_Table (Ref).Y));

    end Unary_Msg_Y;


    function Unary_Msg_Font (The_Object : Object.Reference)
                            return Object.Reference is
        Ref : Integer;
        Font_Value : Scanner.B_String;

    begin
        Ref := Object.Identificator (The_Object);

        case Pen_Table (Ref).Font is
            when Small_Font =>
                Bs_Copy (Font_Value, "PetitePlume");
            when Medium_Font =>
                Bs_Copy (Font_Value, "MoyennePlume");
            when Large_Font =>
                Bs_Copy (Font_Value, "LargePlume");
        end case;
        return String_Class.Create (Bs_Image (Font_Value));

    end Unary_Msg_Font;


    function Unary_Msg_Small_Font
                (The_Object : Object.Reference) return Object.Reference is

        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        Pen_Table (Ref).Font := Small_Font;
        Easy_X.Set_Font (Pen_Table (Ref).Font);
        return Object.Void_Reference;

    end Unary_Msg_Small_Font;


    function Unary_Msg_Medium_Font
                (The_Object : Object.Reference) return Object.Reference is

        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        Pen_Table (Ref).Font := Medium_Font;
        Easy_X.Set_Font (Pen_Table (Ref).Font);
        return Object.Void_Reference;

    end Unary_Msg_Medium_Font;


    function Unary_Msg_Large_Font
                (The_Object : Object.Reference) return Object.Reference is

        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        Pen_Table (Ref).Font := Large_Font;
        Easy_X.Set_Font (Pen_Table (Ref).Font);
        return Object.Void_Reference;

    end Unary_Msg_Large_Font;


    function Unary_Msg_Go_Home
                (The_Object : Object.Reference) return Object.Reference is

        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        Pen_Table (Ref).X := 0;
        Pen_Table (Ref).Y := 0;
        Easy_X.Move_To (0, 0);
        return Object.Void_Reference;

    end Unary_Msg_Go_Home;


    function Unary_Msg_Copy (The_Object : Object.Reference)
                            return Object.Reference is

        Ref, New_Ref : Integer;
        New_Object : Object.Reference;

    begin
        Ref := Object.Identificator (The_Object);
        New_Object := Create;
        New_Ref := Object.Identificator (New_Object);
        Pen_Table (New_Ref) := Pen_Table (Ref);
        return New_Object;

    end Unary_Msg_Copy;


    function Keyword_Msg_X (The_Object : Object.Reference; Arg_Value : Integer)
                           return Object.Reference is
        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        Pen_Table (Ref).X := Easy_X.Coordinate (Arg_Value);
        Easy_X.Move_To (Pen_Table (Ref).X, Pen_Table (Ref).Y);
        return Object.Void_Reference;

    end Keyword_Msg_X;


    function Keyword_Msg_Y (The_Object : Object.Reference; Arg_Value : Integer)
                           return Object.Reference is
        Ref : Integer;

    begin
        Ref := Object.Identificator (The_Object);
        Pen_Table (Ref).Y := Easy_X.Coordinate (Arg_Value);
        Easy_X.Move_To (Pen_Table (Ref).X, Pen_Table (Ref).Y);
        return Object.Void_Reference;

    end Keyword_Msg_Y;


    function Keyword_Msg_Write
                (Arg_Object : Object.Reference) return Object.Reference is

        Write_Str : Scanner.B_String;

    begin
        Bs_Copy (Write_Str, String_Class.In_Text (Arg_Object));
        Easy_X.Draw_String (Bs_Image (Write_Str));
        return Object.Void_Reference;

    end Keyword_Msg_Write;


    function Keyword_Msg_Goto_X_Y (The_Object : Object.Reference;
                                   First_Arg_Value, Second_Arg_Value : Integer)
                                  return Object.Reference is
        Ref : Integer;
        New_X, New_Y : Easy_X.Coordinate;

    begin
        Ref := Object.Identificator (The_Object);
        New_X := Easy_X.Coordinate (First_Arg_Value);
        New_Y := Easy_X.Coordinate (Second_Arg_Value);

        Pen_Table (Ref).X := New_X;
        Pen_Table (Ref).Y := New_Y;

        Easy_X.Move_To (Pen_Table (Ref).X, Pen_Table (Ref).Y);
        return Object.Void_Reference;

    end Keyword_Msg_Goto_X_Y;


    -- envoi d'un message a un objet stylo
    -- ===================================

    function Send (To_Object : Object.Reference;
                   The_Message : Message.Selector;
                   With_Arguments : Arguments.List := Arguments.Void_Arguments)
                  return Object.Reference is

        Nb_Argument : Natural;

        Msg_List, Msg : Message.Selector := Message.Void_Selector;

        Arg_Object, Result : Object.Reference;
        Arg_Value, Second_Arg_Value : Integer;
        Arg_List : Arguments.List;

    begin
        Nb_Argument := Arguments.How_Many (With_Arguments);

        if Nb_Argument = 0 then

            -- reception d'un message unaire

            if Is_Equal_String (Message.Image (The_Message), "TonX") then

                Msg_Report.Information ("Pen object: unary message -> TonX");
                Result := Unary_Msg_X (To_Object);

            elsif Is_Equal_String (Message.Image (The_Message), "TonY") then

                Msg_Report.Information ("Pen object: unary message -> TonY");
                Result := Unary_Msg_Y (To_Object);

            elsif Is_Equal_String (Message.Image (The_Message), "TaPlume") then

                Msg_Report.Information ("Pen object: unary message -> TaPlume");
                Result := Unary_Msg_Font (To_Object);

            elsif Is_Equal_String
                     (Message.Image (The_Message), "PetitePlume") then

                Msg_Report.Information
                   ("Pen object: unary message -> PetitePlume");
                Result := Unary_Msg_Small_Font (To_Object);

            elsif Is_Equal_String
                     (Message.Image (The_Message), "MoyennePlume") then

                Msg_Report.Information
                   ("Pen object: unary message -> MoyennePlume");
                Result := Unary_Msg_Medium_Font (To_Object);

            elsif Is_Equal_String
                     (Message.Image (The_Message), "LargePlume") then

                Msg_Report.Information
                   ("Pen object: unary message -> LargePlume");
                Result := Unary_Msg_Large_Font (To_Object);

            elsif Is_Equal_String
                     (Message.Image (The_Message), "RentreChezToi") then

                Msg_Report.Information
                   ("Pen object: unary message -> RentreChezToi");
                Result := Unary_Msg_Go_Home (To_Object);

            elsif Is_Equal_String (Message.Image (The_Message), "CopieToi") then

                Msg_Report.Information
                   ("Pen object: unary message -> CopieToi");
                Result := Unary_Msg_Copy (To_Object);

            else

                Msg_Report.Interpret_Error
                   ("Incorrect unary method " &
                    Message.Image (The_Message) & " for Pen object");

                raise Incorrect_Method;
            end if;

        elsif Message.Is_Keyword (The_Message) then

            -- reception d'un message a mots cles

            Message.Cat (Msg_List, The_Message);

            Arg_List := With_Arguments;
            Arguments.First (Arg_List);

            while (Nb_Argument /= 0) loop

                Arguments.Read (Arg_List, Arg_Object);
                Arg_Value := Object.Identificator (Arg_Object);
                Nb_Argument := Nb_Argument - 1;

                Message.Extract_Keyword (Msg_List, Msg);

                if Is_Equal_String (Message.Image (Msg), "TonX") then

                    Msg_Report.Information
                       ("Pen object: keyword message -> TonX:");
                    Result := Keyword_Msg_X (To_Object, Arg_Value);

                elsif Is_Equal_String (Message.Image (Msg), "TonY") then

                    Msg_Report.Information
                       ("Pen object: keyword message -> TonY:");
                    Result := Keyword_Msg_Y (To_Object, Arg_Value);

                elsif Is_Equal_String (Message.Image (Msg), "Ecrire") then

                    Msg_Report.Information
                       ("Pen object: keyword message -> Ecrire:");
                    Result := Keyword_Msg_Write (Arg_Object);

                elsif Is_Equal_String (Message.Image (Msg), "VaEnX") then

                    Msg_Report.Information
                       ("Pen object: keyword message -> VaEnX:");

                    -- recherche de la 2eme partie du message
                    if (Nb_Argument /= 0) then

                        Message.Extract_Keyword (Msg_List, Msg);

                        if (Message.Image (Msg) = "y" or
                            Message.Image (Msg) = "Y") then

                            Arguments.Read (Arg_List, Arg_Object);
                            Second_Arg_Value :=
                               Object.Identificator (Arg_Object);
                            Nb_Argument := Nb_Argument - 1;

                            Msg_Report.Information
                               ("Pen object: keyword message -> Y:");
                            Result := Keyword_Msg_Goto_X_Y
                                         (To_Object, Arg_Value,
                                          Second_Arg_Value);
                        else
                            -- 2eme partie du message incorrecte
                            Msg_Report.Interpret_Error
                               ("Incorrect keyword method VaEnX " &
                                Message.Image (Msg) & " for Pen object");

                            raise Incorrect_Method;
                        end if;

                    else
                        -- 2eme partie du message manquante
                        Msg_Report.Interpret_Error
                           ("Incorrect keyword method VaEnX" &
                            " for Pen object");

                        raise Incorrect_Method;

                    end if;

                else
                    -- message inexistant
                    Msg_Report.Interpret_Error
                       ("Incorrect keyword method " &
                        Message.Image (Msg) & " for Pen object");

                    raise Incorrect_Method;
                end if;

            end loop;

        else

            -- erreur sur reception d'un message binaire

            Msg_Report.Interpret_Error
               ("No binary method allowed " &
                Message.Image (The_Message) & " for Pen object");

            raise Incorrect_Method;
        end if;

        return Result;

    end Send;


    -- affichage du contenu de la table d'instance des stylos
    -- ======================================================

    procedure Image_Table is

        Pen : Pen_Ref;

    begin  
        Msg_Report.Information ("Pen Table contents");
        for Ref in Pen_Table'Range loop  
            Pen := Pen_Table (Ref);
            Msg_Report.Continue (Enum_Indicator'Image (Pen.Indicator) &
                                 ", Font: " & Easy_X.Fonts'Image (Pen.Font) &
                                 ", X: " & Easy_X.Coordinate'Image (Pen.X) &
                                 ", Y: " & Easy_X.Coordinate'Image (Pen.Y));
        end loop;

    end Image_Table;

end Pen_Class;