|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 Tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: B T
Length: 19194 (0x4afa)
Types: TextFile
Names: »B«
└─⟦180fe333a⟧ Bits:30000405 8mm tape, Rational 1000, SW CATALOG, 10_20_0
└─⟦180fe333a⟧ Bits:30000537 8mm tape, Rational 1000, SW Catalog 10_20_0
└─⟦5cb1d1d7f⟧ »DATA«
└─⟦3b1ee7bd8⟧
└─⟦this⟧
with Machine_Dependencies, Equality_Operator, Terminal_Interface,
Text_Io, Singly_Linked_List, Token_Definition;
package body Utilities is
--****************************************************************
--****************************************************************
-------------------------------------------------------------------------
-- Abstract : This operation will obtain a file name from the user.
--
--------------------------------------------------------------------------
-- Parameters : DICTIONARY_NAME : out STRING; is the name of the
-- dictionary
-- : file.
-- :
-- : NAME_LENGTH : out NATURAL; is the number of characters
-- in
-- : the DICTIONARY_NAME.
--------------------------------------------------------------------------
-- Algorithm :
--
--------------------------------------------------------------------------
procedure Get_Dictionary_Name
(Dictionary_Name : out String; Name_Length : out Natural) is
Input_String : String (1 .. Machine_Dependencies.File_Line_Length);
Length : Natural := 0;
Index : Natural := 1;
Blank : constant Character := ' ';
begin
Dictionary_Name := (Dictionary_Name'Range => ' ');
----------------------------------------------------------------
-- if the user enters a space (blank value) then the
-- DICTIONARY_NAME
-- will be assigned the default value TERMINAL_DEVICE. If
-- the KEY_BOARD_RESPONSE is a '?' then help is being requested.
-----------------------------------------------------------------
Terminal_Interface.Get_Line (Input_String, Length);
if Length = Input_String'First - 1 then
raise Abandon;
else
for I in Input_String'First .. Length loop
if Input_String (I) = Wants_Help then
raise Needs_Help;
end if;
end loop;
loop
if Input_String (Index) = Blank then
null;
else
Name_Length := Length - Index + 1;
Dictionary_Name (Dictionary_Name'First ..
Length - Index + 1) :=
Input_String (Index .. Length);
exit;
end if;
Index := Index + 1;
if Index > Length then
Name_Length := Terminal_Device'Length;
Dictionary_Name (Terminal_Device'Range) := Terminal_Device;
exit;
end if;
end loop;
end if;
end Get_Dictionary_Name;
--****************************************************************
--****************************************************************
-------------------------------------------------------------------------
-- Abstract : This operation will list out a user dicitonary to a
-- file.
--
--------------------------------------------------------------------------
-- Parameters : INPUT_FILE,OUTPUT_FILE : STRING;
-- Both parameters are string names of user files.
--------------------------------------------------------------------------
-- Algorithm :
--
--------------------------------------------------------------------------
procedure List (Input_File, Output_File : String) is
Number_Of_Characters : Natural;
-- number of spaces
Tab_Width : constant String := " "; -- between columns
-- on output.
Margin : constant Natural := Tab_Width'Length;
Token : Token_Definition.Token_Type;
Input : Text_Io.File_Type;
Output : Text_Io.File_Type;
------------------------------
-- Local helper procedure
-- to list multiple words per
-- output line.
------------------------------
--------------------------------------------------------------------------
-- Abstract : This operation will output to a file using a column and
-- : and page format. The formats are calculated based on
-- : constants declared in the machine dependencies package.
--------------------------------------------------------------------------
-- Parameters : INPUT and OUTPUT are opened files.
--
--------------------------------------------------------------------------
-- Algorithm :
--
--------------------------------------------------------------------------
procedure Output_Multiple_Columns
(Input, Output : in out Text_Io.File_Type) is
begin
if Text_Io.End_Of_File (Input) then
null;
else
Token.Word := (Token.Word'Range => ' ');
Text_Io.Get_Line (Input, Token.Word, Token.Length);
Text_Io.Put (Output, Token.Word (Token.Word'Range));
loop
exit when Text_Io.End_Of_File (Input);
Token.Word := (Token.Word'Range => ' ');
Text_Io.Get_Line (Input, Token.Word, Token.Length);
if Natural (Text_Io.Col (Output)) +
Token_Definition.Token_Length + Margin >
Machine_Dependencies.Output_Page_Width then
Text_Io.New_Line (Output);
if Natural (Text_Io.Line (Output)) >
Machine_Dependencies.Output_Page_Length then
Text_Io.New_Page (Output);
end if;
Text_Io.Put (Output, Token.Word (Token.Word'Range));
else
Text_Io.Put (Output, Tab_Width);
Text_Io.Put (Output, Token.Word (Token.Word'Range));
end if;
end loop;
end if;
end Output_Multiple_Columns;
--------------------------------------------
-- start of LIST
--------------------------------------------
begin
if Token_Definition.Token_Length >
Machine_Dependencies.Output_Page_Width then
Terminal_Interface.Put_Line
(" The output page width is too narrow." &
" This operation is terminated.");
else
--------------------------------------------
-- open the input file
--------------------------------------------
begin
Text_Io.Open (File => Input,
Mode => Text_Io.In_File,
Name => Input_File (Input_File'Range),
Form => "");
exception
when Text_Io.Name_Error |
Text_Io.Status_Error | Constraint_Error =>
raise Invalid_Input_File;
when others =>
Terminal_Interface.Put_Line
(" UNKNOWN ERROR in UTILITIES.LIST" & " on INPUT ");
end;
--------------------------------------------
-- Create the output file
--------------------------------------------
begin
Text_Io.Create (File => Output,
Mode => Text_Io.Out_File,
Name => Output_File (Output_File'Range),
Form => "");
exception
when Text_Io.Status_Error | Text_Io.Name_Error |
Text_Io.Device_Error | Constraint_Error =>
raise Invalid_Output_File;
when others =>
Terminal_Interface.Put_Line
(" UNKNOWN ERROR in UTILITIES.LIST" & " on OUTPUT ");
end;
if Token_Definition.Token_Length =
Machine_Dependencies.Output_Page_Width then
loop
exit when Text_Io.End_Of_File (Input);
Text_Io.Get_Line (Input, Token.Word, Token.Length);
Text_Io.Put_Line
(Output, Token.Word (Token.Word'First .. Token.Length));
end loop;
else
Output_Multiple_Columns (Input, Output);
end if;
Text_Io.Close (Input);
Text_Io.Close (Output);
end if;
end List;
--****************************************************************
--****************************************************************
--------------------------------------------------------------------------
-- Abstract : This operation will merge two user dictionaries into
-- : one user dictionary.
--------------------------------------------------------------------------
-- Parameters : DICTIONARY_A : in out TEXT_IO.FILE_TYPE;
-- : DICTIONARY_B : in out TEXT_IO.FILE_TYPE;
-- : DICTIONARY_C : in out TEXT_IO.FILE_TYPE;
-- : These are the opened files.
--------------------------------------------------------------------------
-- Algorithm : This process will merge DICTIONARY_A and DICTIONARY_B
-- into
-- : DICTIONARY_C.
--------------------------------------------------------------------------
procedure Merge (Dictionary_A, Dictionary_B, Dictionary_C : in out
Text_Io.File_Type) is
Token : Token_Definition.Token_Type;
type Token_Counter is
record
Token : Token_Definition.Token_Type;
Counter : Natural := 0;
end record;
package Singly_Linked_Word_List is
new Singly_Linked_List (Token_Counter);
use Singly_Linked_Word_List;
Token_Counter_List : Singly_Linked_Word_List.List_Type;
function Equals
(Left, Right : Token_Definition.Token_Type) return Boolean;
package Token_Equality is new Equality_Operator
(Token_Definition.Token_Type, Equals);
function "=" (Left, Right : Token_Definition.Token_Type) return Boolean
renames Token_Equality.Equals."=";
function Equals (Left, Right : Token_Definition.Token_Type)
return Boolean is
--------------------------------------------------------------------------
-- Abstract : This function defines equality for tokens.
--------------------------------------------------------------------------
-- Parameters : Left & Right -- are tokens to be compared for equality.
--------------------------------------------------------------------------
begin
return Left.Word (Left.Word'First .. Left.Length) =
Right.Word (Right.Word'First .. Right.Length);
end Equals;
--**************************************************************************
--**************************************************************************
function ">" (Left, Right : Token_Definition.Token_Type)
return Boolean is
--------------------------------------------------------------------------
-- Abstract : This function defines the "greater than" relation for
-- tokens.
--------------------------------------------------------------------------
-- Parameters : Left & Right -- are tokens to be compared
--------------------------------------------------------------------------
begin
return Left.Word (Left.Word'First .. Left.Length) >
Right.Word (Right.Word'First .. Right.Length);
end ">";
--*************************************************************************
--*************************************************************************
procedure Initialize is
--------------------------------------------------------------------------
-- Abstract : This procedure empties the misspelled word list.
--------------------------------------------------------------------------
-- Algorithm : Go to the head of the list and delete the head element
-- until the list is empty.
--------------------------------------------------------------------------
begin
First (Token_Counter_List);
while not Empty (Token_Counter_List) loop
Delete_Element (Token_Counter_List);
end loop;
end Initialize;
procedure Insert_Word (Token : Token_Definition.Token_Type) is
--------------------------------------------------------------------------
-- Abstract : This procedure inserts a token and the corrected token
-- into the linked list in ascending order if the token is
-- not
-- already in the list.
--------------------------------------------------------------------------
-- Parameters : Token - is the original word from the document.
--------------------------------------------------------------------------
-- Algorithm : (a) Go to the head of the list.
-- (b) Traverse the list until the end of the list is
-- encountered or a token is found in the list that has
-- a value greater than or equal to the input
-- parameter.
-- (c) select
-- end-of-list =>
-- insert input parameter at end of list
-- token in list is greater than input parameter =>
-- insert the input parameter in front of the
-- element
--------------------------------------------------------------------------
begin
First (Token_Counter_List);
while (not Null_Node (Token_Counter_List)) and then
(Token > Current_Element (Token_Counter_List).Token) loop
Next (Token_Counter_List);
end loop;
if Null_Node (Token_Counter_List) then
Insert_After (List => Token_Counter_List,
Element => Token_Counter'(Token, 0));
elsif Token =
Current_Element (Token_Counter_List).Token then
null;
else
Insert_Before (List => Token_Counter_List,
Element => Token_Counter'(Token, 0));
end if;
end Insert_Word;
--**********************************************************************
--**********************************************************************
begin
Initialize;
loop
begin
Text_Io.Get_Line (Dictionary_A, Token.Word, Token.Length);
if Token.Length > 0 then
Insert_Word (Token);
end if;
exception
when Text_Io.End_Error =>
exit;
end;
end loop;
loop
begin
Text_Io.Get_Line (Dictionary_B, Token.Word, Token.Length);
if Token.Length > 0 then
Insert_Word (Token);
end if;
exception
when Text_Io.End_Error =>
exit;
end;
end loop;
if Text_Io.Is_Open (Dictionary_C) then
Text_Io.Reset (Dictionary_C, Text_Io.Out_File);
end if;
First (Token_Counter_List);
while not Null_Node (Token_Counter_List) loop
Text_Io.Put_Line
(Dictionary_C, Current_Element (Token_Counter_List).Token.Word
(Current_Element (Token_Counter_List).
Token.Word'First ..
Current_Element (Token_Counter_List).
Token.Length));
Next (Token_Counter_List);
end loop;
Text_Io.Close (Dictionary_C);
if Text_Io.Is_Open (Dictionary_A) then
Text_Io.Close (Dictionary_A);
end if;
if Text_Io.Is_Open (Dictionary_B) then
Text_Io.Close (Dictionary_B);
end if;
end Merge;
--****************************************************************
--****************************************************************
--------------------------------------------------------------------------
-- Abstract : This operation will open a file. This operation calls
-- : TEXT_IO.OPEN.
--------------------------------------------------------------------------
-- Parameters : FILE_NAME : STRING; is the name of the file to open.
-- : OPENED_FILE is the name of the file to be used for
-- : writing to reading from.
--------------------------------------------------------------------------
-- Algorithm :
--
--------------------------------------------------------------------------
procedure Open (File_Name : String;
Opened_File : in out Text_Io.File_Type) is
begin
Text_Io.Open (File => Opened_File,
Mode => Text_Io.In_File,
Name => File_Name (File_Name'Range),
Form => "");
end Open;
--------------------------------------------------------------------------
-- Abstract : This operation will create a file. This operaiton calls
-- : TEXT_IO.CREATE.
--------------------------------------------------------------------------
-- Parameters : FILE_NAME : STRING; is the name of the file to be
-- created.
-- : OPENED_FILE is the name of the file to be used for
-- : writing to reading from.
--------------------------------------------------------------------------
-- Algorithm :
--
--------------------------------------------------------------------------
procedure Create (File_Name : String;
Created_File : in out Text_Io.File_Type) is
begin
Text_Io.Create (File => Created_File,
Mode => Text_Io.Out_File,
Name => File_Name (File_Name'Range),
Form => "");
end Create;
--****************************************************************
--****************************************************************
end Utilities;