comp.lang.ada
 help / color / mirror / Atom feed
* Unix environment variables
@ 1995-03-28 15:15 Joel Rudy
  1995-03-30  0:00 ` Mitch Gart
  1995-04-03  0:00 ` David Kusuda
  0 siblings, 2 replies; 3+ messages in thread
From: Joel Rudy @ 1995-03-28 15:15 UTC (permalink / raw)


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.

Thanks for your help. 

Joel

2Lt Joel E. Rudy, USAF        | No sig -- The surgeon general has determined
PPBS Software Engineer        | that second hand humor is bad for your health.
joel.rudy@comm.hq.af.mil      | (703)697-5403 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unix environment variables
  1995-03-28 15:15 Unix environment variables Joel Rudy
@ 1995-03-30  0:00 ` Mitch Gart
  1995-04-03  0:00 ` David Kusuda
  1 sibling, 0 replies; 3+ messages in thread
From: Mitch Gart @ 1995-03-30  0:00 UTC (permalink / raw)


Joel Rudy (joel.rudy@comm.hq.af.mil) wrote:
: 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.

Each compiler on Unix has its own way, see the manual.

Or now-a-days most Ada compilers on Unix support the POSIX/Ada
packages.  POSIX_Process_Environment contains a way to get 
environment variables.  If you use this package your program is 
even likely to be portable.

	Mitch Gart




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unix environment variables
  1995-03-28 15:15 Unix environment variables Joel Rudy
  1995-03-30  0:00 ` Mitch Gart
@ 1995-04-03  0:00 ` David Kusuda
  1 sibling, 0 replies; 3+ messages in thread
From: David Kusuda @ 1995-04-03  0:00 UTC (permalink / raw)



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;
  





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1995-04-03  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox