From: dkusu@atc-1s.hac.com (David Kusuda)
Subject: Re: Unix environment variables
Date: 1995/04/03
Date: 1995-04-03T00:00:00+00:00 [thread overview]
Message-ID: <3lp2uv$1e2@hacgate2.hac.com> (raw)
In-Reply-To: 3l9978$5qk@huron.eel.ufl.edu
In article 5qk@huron.eel.ufl.edu, joel.rudy@comm.hq.af.mil (Joel Rudy) writes:
>What is the easiest way to access a Unix environment variable via Ada. We
>are using SunAda 2.1.1 on a Solaris 2.3 operating system.
>
The following program was compiled under both SunAda 1.1j and VADS 6.2 (HP Self-Hosted)
running under SunOS 4.1.3 and HP-UX9.05, respectively.
with A_Strings;
with C_Strings;
with Text_IO;
with U_Env;
procedure ShowEnv is
--
-- Purpose:
-- This program displays the value associated with an environment
-- variable entered on the command line.
--
-- Notes:
-- This program uses a non-standard Ada package, U_Env, to gain
-- access to the command line parameters and the definition of the
-- environment variable.
--
-- RENAMING DECLARATIONS
package ASTR renames A_Strings;
package CSTR renames C_Strings;
package TIO renames Text_IO;
package UENV renames U_Env;
function "=" (L, R : CSTR.C_String) return Boolean renames CSTR."=";
-- LOCAL SUBPROGRAM SPECIFICATIONS
procedure Lookup (Env_Var : ASTR.A_String);
--
-- Purpose:
-- Performs the actual lookup of the environment variable.
--
-- Raises:
-- None.
--
-- Notes:
-- None.
--
-- LOCAL SUBPROGAM BODY
procedure Lookup (Env_Var : ASTR.A_String) is
--
-- Notes:
-- If UENV.Getenv returns a null value, the environment variable
-- is undefined.
--
Lookup_String : CSTR.C_String :=
UENV.Getenv (CSTR.Convert_A_to_C (Env_Var));
begin -- Lookup
if Lookup_String /= null then
TIO.Put_Line (Env_Var.S & " = " & CSTR.To_String (Lookup_String));
else
TIO.Put_Line (Env_Var.S & " is not defined");
end if;
end Lookup;
begin -- ShowEnv
--
-- Make sure that at least one environment variable was entered on the
-- command line.
--
if UENV.Argc < 2 then
TIO.Put_Line ("Usage::" & UENV.Argv (0).S &
" [environment variable...]");
return;
end if;
for I in 1 .. UENV.Argc - 1 loop
Lookup (UENV.Argv (I));
end loop;
end ShowEnv;
prev parent reply other threads:[~1995-04-03 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-03-28 15:15 Unix environment variables Joel Rudy
1995-03-30 0:00 ` Mitch Gart
1995-04-03 0:00 ` David Kusuda [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox