--::::::::::
--env.pro
--::::::::::
-------- SIMTEL20 Ada Software Repository Prologue ------------
-- Unit name    : ENV
-- Version      : 02/25/88
-- Author       : Richard Conn
-- DDN Address  : rconn @ simtel20.army.mil
-- Copyright    :  
-- Date created : 02/25/88
-- Release date : 09/24/88 
-- Last update  : 09/24/88 
-- Machine/System Compiled/Run on : SUN 3/260 with Alsys Ada 3.2 and
--  : Verdix VADS 5.41
---------------------------------------------------------------
-- Keywords     : Environment Interface, ENV, Environment Variable
-- Abstract     :  
--    ENV is a package which implements an Environment Interface.
-- It mirrors the UNIX/C environment interface, providing a count
-- of the environment variables and the environment variables
-- themselves.
------------------ Revision history ---------------------------
-- DATE         VERSION	AUTHOR                  HISTORY
-- 09/24/88    02/25/88 Richard Conn            Initial Release
------------------ Distribution and Copyright -----------------
-- This prologue must be included in all copies of this software.
--
-- This software is released to the Ada community.
-- This software is released to the Public Domain (note:
--   software released to the Public Domain is not subject
--   to copyright protection).
-- Restrictions on use or distribution:  NONE
------------------ Disclaimer ---------------------------------
-- This software and its documentation are provided "AS IS" and
-- without any expressed or implied warranties whatsoever.
-- No warranties as to performance, merchantability, or fitness
-- for a particular purpose exist.
--
-- Because of the diversity of conditions and hardware under
-- which this software may be used, no warranty of fitness for
-- a particular purpose is offered.  The user is advised to
-- test the software thoroughly before relying on it.  The user
-- must assume the entire risk and liability of using this
-- software.
--
-- In no event shall any person or organization of people be
-- held responsible for any direct, indirect, consequential
-- or inconsequential damages or lost profits.
-------------------END-PROLOGUE--------------------------------
--::::::::::
--env.src
--::::::::::
--::::::::::
--env.inc
--::::::::::
-- Environment Interface package

-- Include file for this package
env.inc

-- ASR Prologue file
env.pro

-- Package specification
env.ada

-- Package bodies for ALSYS 3.2, Verdix VADS 5.41, and general-purpose
env_body_alsys.ada
env_body_verdix.ada
env_body_general.ada

-- Command file to compile test programs and test programs
envtest.sub
envtest1.ada
envtest2.ada
--::::::::::
--env.pro
--::::::::::
-------- SIMTEL20 Ada Software Repository Prologue ------------
-- Unit name    : ENV
-- Version      : 02/25/88
-- Author       : Richard Conn
-- DDN Address  : rconn @ simtel20.army.mil
-- Copyright    :  
-- Date created : 02/25/88
-- Release date : 09/24/88 
-- Last update  : 09/24/88 
-- Machine/System Compiled/Run on : SUN 3/260 with Alsys Ada 3.2 and
--  : Verdix VADS 5.41
---------------------------------------------------------------
-- Keywords     : Environment Interface, ENV, Environment Variable
-- Abstract     :  
--    ENV is a package which implements an Environment Interface.
-- It mirrors the UNIX/C environment interface, providing a count
-- of the environment variables and the environment variables
-- themselves.
------------------ Revision history ---------------------------
-- DATE         VERSION	AUTHOR                  HISTORY
-- 09/24/88    02/25/88 Richard Conn            Initial Release
------------------ Distribution and Copyright -----------------
-- This prologue must be included in all copies of this software.
--
-- This software is released to the Ada community.
-- This software is released to the Public Domain (note:
--   software released to the Public Domain is not subject
--   to copyright protection).
-- Restrictions on use or distribution:  NONE
------------------ Disclaimer ---------------------------------
-- This software and its documentation are provided "AS IS" and
-- without any expressed or implied warranties whatsoever.
-- No warranties as to performance, merchantability, or fitness
-- for a particular purpose exist.
--
-- Because of the diversity of conditions and hardware under
-- which this software may be used, no warranty of fitness for
-- a particular purpose is offered.  The user is advised to
-- test the software thoroughly before relying on it.  The user
-- must assume the entire risk and liability of using this
-- software.
--
-- In no event shall any person or organization of people be
-- held responsible for any direct, indirect, consequential
-- or inconsequential damages or lost profits.
-------------------END-PROLOGUE--------------------------------
--::::::::::
--env.ada
--::::::::::
package ENV is
   
   --------------------------------------------------------------------------
   --| BEGIN PROLOGUE
   --| DESCRIPTION            : ENV is a package which implements an Environ-
   --|                        : ment Interface.  It mirrors the UNIX/C
   --|                        : environment interface, providing a count of
   --|                        : the environment variables and the environment
   --|                        : variables themselves.
   --|                        : 
   --| REQUIREMENTS SUPPORTED : Environment Interface
   --|                        : 
   --| LIMITATIONS            : Compiler limit on string length and dynamic
   --|                        :    memory.
   --|                        : INITIALIZE must be called once, and only once,
   --|                        :    during the execution of the main Ada proc.
   --|                        : 
   --| AUTHOR(S)              : Richard Conn (RLC)
   --| CHANGE LOG             : 02/25/88  RLC  Initial Version
   --| END PROLOGUE
   --------------------------------------------------------------------------
   
   type FUNCTIONS is (ENVC_VALUE, ENVP_NAME);
   -- Which functions are implemented?
   --   ENVC_VALUE = ENVC, ENVP, ENVP_NAME(NATURAL), ENVP_VALUE(NATURAL)
   --   ENVP_NAME  = ENVP_VALUE(STRING), IS_VALID_ENVP_NAME(STRING)
   type STATUS is (IMPLEMENTED, NOT_IMPLEMENTED);
   type PACKAGE_STATUS is array (FUNCTIONS) of STATUS;
   ENV_STATUS : PACKAGE_STATUS;
   -- Which of the functions below are implemented?
   
   ENVC       : NATURAL;
   -- Number (0 to ENVC-1) of environment variables
   
   procedure INITIALIZE (PROGRAM_NAME        : in STRING;
                         COMMAND_LINE_PROMPT : in STRING);
   -- Initialize this package (this routine must be called before any other
   -- routines or objects are called or referenced)
   
   function ENVP (INDEX : in NATURAL) return STRING;
   -- Return the Nth environment variable
   
   function ENVP_NAME (INDEX : in NATURAL) return STRING;
   -- Return the name of the Nth environment variable
   
   function ENVP_VALUE (INDEX : in NATURAL) return STRING;
   -- Return the value of the Nth environment variable
   
   function ENVP_VALUE (NAME : in STRING) return STRING;
   -- Return the value of the named environment variable
   
   function IS_VALID_ENVP_NAME (NAME : in STRING) return BOOLEAN;
   -- Determine if NAME is a valid name for an environment variable
   
   ENVIRONMENT_VARIABLE_NAME_ERROR   : exception;
   ENVIRONMENT_VARIABLE_SYNTAX_ERROR : exception;
   INVALID_INDEX                     : exception;
   UNEXPECTED_ERROR                  : exception;
   
end ENV;
--::::::::::
--env_body_alsys.ada
--::::::::::
-- This implementation of Package Body ENV is Alsys-specific (SUN).
-- It requires the Alsys package SYSTEM_ENVIRONMENT.
with TEXT_IO;
with SYSTEM_ENVIRONMENT;
package body ENV is
   
   LOCAL_STRING_LENGTH : constant := 400;
   type LOCAL_STRING is 
      record
         CONTENT : STRING (1 .. LOCAL_STRING_LENGTH);
         LAST    : NATURAL;
      end record;
   
   function CONVERT (ITEM : in STRING) return LOCAL_STRING is
      LS : LOCAL_STRING;
   begin
      LS.CONTENT (1 .. ITEM'LENGTH) := ITEM;
      LS.LAST := ITEM'LENGTH;
      return LS;
   end CONVERT;
   
   procedure INITIALIZE (PROGRAM_NAME        : in STRING;
                         COMMAND_LINE_PROMPT : in STRING) is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    INITIALIZE performs necessary initializations.
      --|DESIGN DESCRIPTION:
      --|    No initialization needed
      --=========================================================
      
   begin
      null;
   end INITIALIZE;
   
   function ENVP (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP returns the indicated environment variable string.
      --|    This string is in the UNIX-standard "NAME=value" form.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return " "
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return " ";
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP;
   
   function ENVP_NAME (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_NAME returns the indicated environment variable name.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return " "
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return " ";
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_NAME;
   
   function ENVP_VALUE (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_VALUE returns the indicated environment variable value.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return " "
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return " ";
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_VALUE;
   
   function ENVP_VALUE (NAME : in STRING) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_VALUE returns the indicated environment variable value.
      --|DESIGN DESCRIPTION:
      --|    If NAME does not match existing environment variable,
      --|      raise ENVIRONMENT_VARIABLE_NAME_ERROR
      --|    Return SYSTEM_ENVIRONMENT.ENV_VALUE (NAME)
      --=========================================================
      
   begin
      return SYSTEM_ENVIRONMENT.ENV_VALUE (NAME);
   exception
      when SYSTEM_ENVIRONMENT.UNKNOWN_ENV_NAME     =>
         raise ENVIRONMENT_VARIABLE_NAME_ERROR;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_VALUE;
   
   function IS_VALID_ENVP_NAME (NAME : in STRING) return BOOLEAN is
      CURRENT_NAME : LOCAL_STRING;
   begin
      CURRENT_NAME := CONVERT (ENVP_VALUE (NAME));
      return TRUE;
   exception
      when ENVIRONMENT_VARIABLE_NAME_ERROR    =>
         return FALSE;
      when others    =>
         raise UNEXPECTED_ERROR;
   end IS_VALID_ENVP_NAME;
   
begin
   ENVC                    := 0;
   ENV_STATUS (ENVC_VALUE) := NOT_IMPLEMENTED;
   ENV_STATUS (ENVP_NAME)  := IMPLEMENTED;
end ENV;
--::::::::::
--env_body_verdix.ada
--::::::::::
-- This implementation of Package Body ENV is Verdix-specific (SUN).
-- The following Verdix Ada packages must be compiled into
-- the Ada library before this package body is compiled:
--      standard/a_strings.a
--      standard/a_strings_b.a
--      standard/c_strings.a
--      standard/c_strings_b.a
--      verdixlib/cmd_line_s.a
--      verdixlib/cmd_line_b.a
with COMMAND_LINE;
with A_STRINGS;
package body ENV is
   
   LOCAL_STRING_LENGTH : constant := 400;
   type LOCAL_STRING is 
      record
         CONTENT : STRING (1 .. LOCAL_STRING_LENGTH);
         LAST    : NATURAL;
      end record;
   
   function CONVERT (ITEM : in STRING) return LOCAL_STRING is
      LS : LOCAL_STRING;
   begin
      LS.CONTENT (1 .. ITEM'LENGTH) := ITEM;
      LS.LAST := ITEM'LENGTH;
      return LS;
   end CONVERT;
   
   procedure INITIALIZE (PROGRAM_NAME        : in STRING;
                         COMMAND_LINE_PROMPT : in STRING) is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    INITIALIZE prompts the user for the command line
      --|    arguments and loads the linked list with them.
      --|DESIGN DESCRIPTION:
      --|    Do nothing (no initialization required)
      --=========================================================
      
   begin
      null;
   end INITIALIZE;
   
   function ENVP (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP returns the indicated environment variable string.
      --|    This string is in the UNIX-standard "NAME=value" form.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S;
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP;
   
   function ENVP_NAME (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_NAME returns the indicated environment variable name.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Locate the '=' in the desired environment variable
      --|    If no '=' was found, raise ENVIRONMENT_VARIABLE_SYNTAX_ERROR
      --|    Return the slice up to the '='
      --=========================================================
      
      EQUALS : NATURAL := 0;
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      for I in COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S'RANGE loop
         if COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S (I) = '=' then
            EQUALS := I;
            exit ;
         end if;
      end loop;
      if EQUALS = 0 then
         raise ENVIRONMENT_VARIABLE_SYNTAX_ERROR;
      end if;
      return 
         COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S (
            COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S'FIRST .. EQUALS - 1);
   exception
      when INVALID_INDEX  | ENVIRONMENT_VARIABLE_SYNTAX_ERROR     =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_NAME;
   
   function ENVP_VALUE (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_VALUE returns the indicated environment variable value.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Locate the '=' in the desired environment variable
      --|    If no '=' was found, raise ENVIRONMENT_VARIABLE_SYNTAX_ERROR
      --|    Return the slice from after the '=' to the end
      --=========================================================
      
      EQUALS : NATURAL := 0;
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      for I in COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S'RANGE loop
         if COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S (I) = '=' then
            EQUALS := I;
            exit ;
         end if;
      end loop;
      if EQUALS = 0 then
         raise ENVIRONMENT_VARIABLE_SYNTAX_ERROR;
      end if;
      return 
         COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S (
            EQUALS + 1 .. COMMAND_LINE.ENVP.all (INTEGER (INDEX)).all.S'LAST);
   exception
      when INVALID_INDEX  | ENVIRONMENT_VARIABLE_SYNTAX_ERROR     =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_VALUE;
   
   function ENVP_VALUE (NAME : in STRING) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_VALUE returns the indicated environment variable value.
      --|DESIGN DESCRIPTION:
      --|    Set FOUND index to ENVC+1
      --|    Loop through the existing names
      --|        If match, set FOUND index to variable index
      --|    End Loop
      --|    If FOUND > ENVC, raise ENVIRONMENT_VARIABLE_NAME_ERROR
      --|    Else return ENVP_VALUE(FOUND)
      --=========================================================
      
      CURRENT_NAME : LOCAL_STRING;
      FOUND        : NATURAL := ENVC + 1;
   begin
      for I in 0 .. ENVC - 1 loop
         CURRENT_NAME := CONVERT (ENVP_NAME (I));
         if CURRENT_NAME.LAST = NAME'LENGTH and then 
            CURRENT_NAME.CONTENT (1 .. CURRENT_NAME.LAST) = NAME then
            FOUND := I;
            exit ;
         end if;
      end loop;
      if FOUND > ENVC then
         raise ENVIRONMENT_VARIABLE_NAME_ERROR;
      else
         return ENVP_VALUE (FOUND);
      end if;
   exception
      when ENVIRONMENT_VARIABLE_NAME_ERROR    =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_VALUE;
   
   function IS_VALID_ENVP_NAME (NAME : in STRING) return BOOLEAN is
      CURRENT_NAME : LOCAL_STRING;
   begin
      CURRENT_NAME := CONVERT (ENVP_VALUE (NAME));
      return TRUE;
   exception
      when ENVIRONMENT_VARIABLE_NAME_ERROR    =>
         return FALSE;
      when others    =>
         raise UNEXPECTED_ERROR;
   end IS_VALID_ENVP_NAME;
   
begin
   ENVC := NATURAL (COMMAND_LINE.ENVC);
   ENV_STATUS := (others => IMPLEMENTED);
end ENV;
--::::::::::
--env_body_general.ada
--::::::::::
-- This implementation of Package Body ENV is general-purpose.
with TEXT_IO;
package body ENV is
   
   procedure INITIALIZE (PROGRAM_NAME        : in STRING;
                         COMMAND_LINE_PROMPT : in STRING) is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    INITIALIZE is a dummy for ENV.
      --|DESIGN DESCRIPTION:
      --|    Do nothing
      --=========================================================
      
   begin
      null;
   end INITIALIZE;
   
   function ENVP (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP returns the indicated environment variable string.
      --|    This string is in the UNIX-standard "NAME=value" form.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return " "
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return " ";
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP;
   
   function ENVP_NAME (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_NAME returns the indicated environment variable name.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return " "
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return " ";
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_NAME;
   
   function ENVP_VALUE (INDEX : in NATURAL) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_VALUE returns the indicated environment variable value.
      --|DESIGN DESCRIPTION:
      --|    If INDEX is out of range, raise INVALID_INDEX
      --|    Return " "
      --=========================================================
      
   begin
      if INDEX < 0 or INDEX >= ENVC then
         raise INVALID_INDEX;
      end if;
      return " ";
   exception
      when INVALID_INDEX  =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_VALUE;
   
   function ENVP_VALUE (NAME : in STRING) return STRING is
      
      --========================= PDL ===========================
      --|ABSTRACT:
      --|    ENVP_VALUE returns the indicated environment variable value.
      --|DESIGN DESCRIPTION:
      --|    If NAME does not match existing environment variable,
      --|      raise ENVIRONMENT_VARIABLE_NAME_ERROR
      --|    Return " "
      --=========================================================
      
   begin
      return " ";
   exception
      when ENVIRONMENT_VARIABLE_NAME_ERROR    =>
         raise ;
      when others    =>
         raise UNEXPECTED_ERROR;
   end ENVP_VALUE;
   
   function IS_VALID_ENVP_NAME (NAME : in STRING) return BOOLEAN is
   begin
      return FALSE;
   end IS_VALID_ENVP_NAME;
   
begin
   ENVC                    := 0;
   ENV_STATUS (ENVC_VALUE) := NOT_IMPLEMENTED;
   ENV_STATUS (ENVP_NAME)  := NOT_IMPLEMENTED;
end ENV;
--::::::::::
--envtest.sub
--::::::::::
a envtest1
ax envtest1
a envtest2
ax envtest2
--::::::::::
--envtest1.ada
--::::::::::
with ENV;
with TEXT_IO;
procedure ENVTEST1 is
   
   --------------------------------------------------------------------------
   --| BEGIN PROLOGUE
   --| DESCRIPTION            : ENVTEST1 tests the ENV (Environment
   --|                        : Interface) package.  ENVTEST1 displays
   --|                        : a count of the environment variables and
   --|                        : the names and values of the environment
   --|                        : variables themselves.
   --|                        : 
   --| REQUIREMENTS SUPPORTED : Environment Interface
   --|                        : 
   --| AUTHOR(S)              : Richard Conn (RLC)
   --| CHANGE LOG             : 02/25/88  RLC  Initial Version
   --| END PROLOGUE
   --------------------------------------------------------------------------
   
   function "=" (LEFT, RIGHT : in ENV.STATUS) return BOOLEAN renames ENV."=";
   
begin
   
   ENV.INITIALIZE ("ENVTEST1", "Enter Arguments: ");
   
   if ENV.ENV_STATUS (ENV.ENVC_VALUE) = ENV.NOT_IMPLEMENTED then
      TEXT_IO.PUT_LINE
          ("Cannot run first part of ENVTEST1 since ENVC not implemented");
   else
      
      TEXT_IO.PUT_LINE ("Number of Environment Variables is " & 
                        NATURAL'IMAGE (ENV.ENVC));
      TEXT_IO.NEW_LINE;
      TEXT_IO.PUT_LINE ("Environment Variables are:");
      for I in 0 .. ENV.ENVC - 1 loop
         TEXT_IO.PUT_LINE (NATURAL'IMAGE (I) & " " & ENV.ENVP_NAME (I));
         TEXT_IO.PUT_LINE ("   " & ENV.ENVP_VALUE (I));
      end loop;
      
   end if;
   
   if ENV.ENV_STATUS (ENV.ENVP_NAME) = ENV.IMPLEMENTED then
      
      begin
         TEXT_IO.PUT ("PATH Variable Value is ");
         if ENV.IS_VALID_ENVP_NAME ("PATH") then
            TEXT_IO.PUT_LINE ("Defined:");
            TEXT_IO.PUT_LINE ("  " & ENV.ENVP_VALUE ("PATH"));
         else
            TEXT_IO.PUT_LINE ("not Defined");
         end if;
      exception
         when ENV.ENVIRONMENT_VARIABLE_NAME_ERROR  =>
            TEXT_IO.PUT_LINE ("  Not Defined");
         when others =>
            TEXT_IO.PUT_LINE ("  Error");
      end;
      
      begin
         TEXT_IO.PUT ("XXXX Variable Value is ");
         if ENV.IS_VALID_ENVP_NAME ("XXXX") then
            TEXT_IO.PUT_LINE ("Defined:");
         else
            TEXT_IO.PUT_LINE ("not Defined");
         end if;
         TEXT_IO.PUT_LINE ("  " & ENV.ENVP_VALUE ("XXXX"));
      exception
         when ENV.ENVIRONMENT_VARIABLE_NAME_ERROR  =>
            TEXT_IO.PUT_LINE ("  Not Defined (OK)");
         when others =>
            TEXT_IO.PUT_LINE ("  Error");
      end;
      
   end if;
   
end ENVTEST1;
--::::::::::
--envtest2.ada
--::::::::::
with ENV;
with TEXT_IO;
procedure ENVTEST2 is
   
   --------------------------------------------------------------------------
   --| BEGIN PROLOGUE
   --| DESCRIPTION            : ENVTEST2 tests the index-out-of-range
   --|                        : error condition for the package ENV
   --|                        : (Environment Interface).
   --|                        : 
   --| REQUIREMENTS SUPPORTED : Environment Interface
   --|                        : 
   --| AUTHOR(S)              : Richard Conn (RLC)
   --| CHANGE LOG             : 02/25/88  RLC  Initial Version
   --| END PROLOGUE
   --------------------------------------------------------------------------
   
   type ERROR_CODE is (NOT_OK, OK);
   FLAG : ERROR_CODE;
   
   function "=" (LEFT, RIGHT : in ENV.STATUS) return BOOLEAN renames ENV."=";
   
   procedure TEST_MESSAGE (TEXT : in STRING) is
      FLAG_COLUMN : constant := 40;
   begin
      TEXT_IO.PUT (TEXT);
      TEXT_IO.SET_COL (FLAG_COLUMN);
      TEXT_IO.PUT_LINE (ERROR_CODE'IMAGE (FLAG));
   end TEST_MESSAGE;
   
begin
   
   ENV.INITIALIZE ("ENVTEST2", "Enter Arguments: ");
   
   if ENV.ENV_STATUS (ENV.ENVC_VALUE) = ENV.IMPLEMENTED then
      begin
         TEXT_IO.PUT_LINE ("Error: " & ENV.ENVP (ENV.ENVC));
      exception
         when ENV.INVALID_INDEX     =>
            FLAG := OK;
         when others =>
            FLAG := NOT_OK;
      end;
      TEST_MESSAGE ("Index out of range on environment var");
   end if;
   
end ENVTEST2;