TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

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

Print Reply
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
"W. Wesley Groleau x4923" <[log in to unmask]>
Tue, 20 Apr 1999 09:39:26 -0500
"W. Wesley Groleau x4923" <[log in to unmask]>
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

  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;