|
|
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: 7332 (0x1ca4)
Types: TextFile
Names: »B«
└─⟦85b835f43⟧ Bits:30000549 8mm tape, Rational 1000, Xlib rev 6.00
└─⟦0c20f784e⟧ »DATA«
└─⟦1abbe589f⟧
└─⟦ada0be243⟧
└─⟦this⟧
with Directory_Tools;
with Io;
with Library;
with System_Utilities;
package body Common_Env is
------------------------------------------------------------------------------
-- X Library Environment Variables - Common functions
--
-- Common_Env - Common functions used by all environment variable functions.
------------------------------------------------------------------------------
-- Copyright 1990 - 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 names 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.
------------------------------------------------------------------------------
Home : constant String := System_Utilities.Home_Library;
Session : constant String := System_Utilities.Session_Name;
Environment : constant String := Home & "." & Session & "_Environment";
-- \f
function Env_Directory return String is
------------------------------------------------------------------------------
-- Called to obtain the name of the directory that contains R1000 "environment"
-- variables. One variable per file. Name of the file is the name of the
-- variable. Case-insensitive.
------------------------------------------------------------------------------
begin
return Environment;
end Env_Directory;
-- \f
function Env_File (Var : String) return String is
------------------------------------------------------------------------------
-- Var - Specifies the name of the environment variable.
--
-- Called to obtain the name of the file that contains a particular R1000
-- "environment" variable. Name of the file is the name of the variable.
-- Case-insensitive.
------------------------------------------------------------------------------
begin
return Environment & "." & Var;
end Env_File;
-- \f
function Is_Set (Var : String) return Boolean is
------------------------------------------------------------------------------
-- Var - Specifies the name of the R1000 "environment" variable to fetch
--
-- Called to see if an R1000 "environment" variable has been set.
------------------------------------------------------------------------------
Env : Io.File_Type;
Env_Name : constant String := Env_Directory & "." & Var;
begin
----If the file exists then the variable is set.
Io.Open (Env, Io.In_File, Env_Name);
Io.Close (Env);
return True;
exception
when others =>
return False;
end Is_Set;
-- \f
procedure Unset_Env (Var : String) is
------------------------------------------------------------------------------
-- Var - Specifies the name of the R1000 "environment" variable to unset
--
-- Called to unset (delete) the definition of an R1000 "environment" variable.
------------------------------------------------------------------------------
Env : Io.File_Type;
Env_Name : constant String := Env_Directory & "." & Var;
begin
----Open the Environment Variable file then delete it.
begin
Io.Open (Env, Io.In_File, Env_Name);
exception
when others =>
return;
end;
Io.Delete (Env);
end Unset_Env;
-- \f
procedure Set_Env (Var : String;
Value : String) is
------------------------------------------------------------------------------
-- Var - Specifies the name of the R1000 "environment" variable to set
-- Value - Specifies the value for the variable
--
-- Called to set the definition of an R1000 "environment" variable.
------------------------------------------------------------------------------
Obj : Directory_Tools.Object.Handle;
Env : Io.File_Type;
Env_Name : constant String := Env_Directory & "." & Var;
begin
----See if the Env_Directory exists or not.
Obj := Directory_Tools.Naming.Resolution (Env_Directory);
if Directory_Tools.Object.Is_Bad (Obj) then
Library.Create_Directory (Name => Env_Directory,
Kind => Library.Directory,
Vol => Library.Nil,
Model => "",
Response => "<ERROR> RAISE_ERROR");
end if;
----Open the Environment Variable file. Write the first line. Close the file.
-- The line is the value.
begin
Io.Create (Env, Io.Out_File, Env_Name);
exception
when others =>
Io.Open (Env, Io.Out_File, Env_Name);
end;
Io.Put_Line (Env, Value);
Io.Close (Env);
end Set_Env;
-- \f
function Get_Env (Var : String) return String is
------------------------------------------------------------------------------
-- Var - Specifies the name of the R1000 "environment" variable to fetch
--
-- Called to obtain the definition of an R1000 "environment" variable.
-- Returns "" if the variable is not defined.
------------------------------------------------------------------------------
Env : Io.File_Type;
Env_Name : constant String := Env_Directory & "." & Var;
function Read_Env return String is
----Read one line from Env; regardless of the length of the
-- line.
Line : String (1 .. 1024);
Length : Natural;
begin
Io.Get_Line (Env, Line, Length);
if Length = Line'Length and then
Io.">" (Io.Col (Env), 1) then
return Line & Read_Env;
else
return Line (1 .. Length);
end if;
end Read_Env;
begin
----Open the Environment Variable file. Read the first line. Close the file.
-- Return that line as the value.
Io.Open (Env, Io.In_File, Env_Name);
declare
Env_Ptr : constant String := Read_Env;
begin
Io.Close (Env);
return Env_Ptr;
end;
exception
when others =>
begin -- Just in case.
Io.Close (Env);
exception
when others =>
null;
end;
return "";
end Get_Env;
-- \f
end Common_Env;