TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
"W. Wesley Groleau x4923" <[log in to unmask]>
Tue, 20 Apr 1999 09:39:26 -0500
text/plain (31 lines)
> On second thought, this version is better.  The previous version doesn't
> give you any way of differentiating between an undefined env var, and a
> defined env var that happens to have a zero-length string as its value.
>
> function getenv (Name : String)
>    return Interfaces.C.Strings.Chars_Ptr is   ...

> Matthew Heaney's solution works if the environment variable exists,
> but raises an exception if it does not.  I offer this refinement of
> Matthew's solution, where the exception is raised, but with
> information supplied which quickly pinpoints the cause of the
> exception.

I disagree with both of you.  I think the best solution is to start with
the GNAT package Ada.Command_Line.Environment, and if necessary, modify it
to do what you want.  It is covered by the "special exception" to the
GPL.  Why start over on a problem that has been solved?

The following program has output identical to ksh printenv :

with Ada.Command_Line.Environment;
with Ada.Text_IO;

procedure CL_Test is

begin
  for I in 1 .. Ada.Command_Line.Environment.Environment_Count loop
    Ada.Text_IO.Put_Line (Ada.Command_Line.Environment.Environment_Value (I));
  end loop;
end CL_Test;

ATOM RSS1 RSS2