comp.lang.ada
 help / color / mirror / Atom feed
* Re: Dos Environment varables
  1999-05-21  0:00 Dos Environment varables Al Lively
  1999-05-21  0:00 ` Keith Thompson
@ 1999-05-21  0:00 ` Gautier
  1999-05-21  0:00   ` Al Lively
  1999-05-22  0:00 ` David Botton
  2 siblings, 1 reply; 9+ messages in thread
From: Gautier @ 1999-05-21  0:00 UTC (permalink / raw)
  To: Al Lively

> Can anyone advise how I can access (through Ada code) the contents of local
> environmental variables?

Which compiler, platform ?

With GNAT, you obtain them by the GNAT.OS_lib getenv function.
E.g.

with GNAT.OS_lib;

...

  function Get_env_string(name:String) return String is
    begin
      return GNAT.OS_lib.getenv(name).all;
    end;

-- 
Gautier

--------
http://members.xoom.com/gdemont/




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

* Re: Dos Environment varables
  1999-05-21  0:00   ` Al Lively
@ 1999-05-21  0:00     ` Gautier
  1999-05-24  0:00     ` Jeffrey D. Cherry
  1 sibling, 0 replies; 9+ messages in thread
From: Gautier @ 1999-05-21  0:00 UTC (permalink / raw)
  To: Al Lively

> I am using ObjectAda 7.1 on a windows 95 platform....

Aaaah. Maybe it's a function called "Get_env_string"
- that's the name in use in Alsys Ada, the ancestor of OA.
Possibily in a package called "DOS" or "OS" - see manual!

My example was precisely for "glueing" it from GNAT!

-- 
Gautier

--------
http://members.xoom.com/gdemont/




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

* Dos Environment varables
@ 1999-05-21  0:00 Al Lively
  1999-05-21  0:00 ` Keith Thompson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Al Lively @ 1999-05-21  0:00 UTC (permalink / raw)


Can anyone advise how I can access (through Ada code) the contents of local
environmental variables?

Thanks,








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

* Re: Dos Environment varables
  1999-05-21  0:00 ` Gautier
@ 1999-05-21  0:00   ` Al Lively
  1999-05-21  0:00     ` Gautier
  1999-05-24  0:00     ` Jeffrey D. Cherry
  0 siblings, 2 replies; 9+ messages in thread
From: Al Lively @ 1999-05-21  0:00 UTC (permalink / raw)


I am using ObjectAda 7.1 on a windows 95 platform....

Gautier wrote in message <37458BC1.CC63E63E@Maths.UniNe.CH>...
>> Can anyone advise how I can access (through Ada code) the contents of
local
>> environmental variables?
>
>Which compiler, platform ?
>
>With GNAT, you obtain them by the GNAT.OS_lib getenv function.
>E.g.
>
>with GNAT.OS_lib;
>
>...
>
>  function Get_env_string(name:String) return String is
>    begin
>      return GNAT.OS_lib.getenv(name).all;
>    end;
>
>--
>Gautier
>
>--------
>http://members.xoom.com/gdemont/






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

* Re: Dos Environment varables
  1999-05-21  0:00 Dos Environment varables Al Lively
@ 1999-05-21  0:00 ` Keith Thompson
  1999-05-21  0:00 ` Gautier
  1999-05-22  0:00 ` David Botton
  2 siblings, 0 replies; 9+ messages in thread
From: Keith Thompson @ 1999-05-21  0:00 UTC (permalink / raw)


"Al Lively" <al.lively@business.gatech.edu> writes:
> Can anyone advise how I can access (through Ada code) the contents of local
> environmental variables?

As others have pointed out, some Ada compilers provide routines for
this.

If yours doesn't, or if you want your code to be portable across
compilers, you can probably call the standard C getenv() function.
The C declaration is

     char *getenv(const char *name);

See Interfaces.C (section B.3 in the RM) for information on how to
call C functions from Ada.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center  <http://www.sdsc.edu>                 <*>
Techno-geek.  Mouse bigger than phone.  Bites heads off virtual chickens.




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

* Re: Dos Environment varables
  1999-05-21  0:00 Dos Environment varables Al Lively
  1999-05-21  0:00 ` Keith Thompson
  1999-05-21  0:00 ` Gautier
@ 1999-05-22  0:00 ` David Botton
  2 siblings, 0 replies; 9+ messages in thread
From: David Botton @ 1999-05-22  0:00 UTC (permalink / raw)


If you are using GNAT see gnat.os_lib

also see:

Ada 95 Binding to CGI (Wheeler)
ftp://ftp.cdrom.com/pub/ada/swcomps/cgi/cgi.html

in the getenv code.

David Botton


Al Lively wrote:
> 
> Can anyone advise how I can access (through Ada code) the contents of local
> environmental variables?
> 
> Thanks,




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

* Re: Dos Environment varables
  1999-05-21  0:00   ` Al Lively
  1999-05-21  0:00     ` Gautier
@ 1999-05-24  0:00     ` Jeffrey D. Cherry
  1999-05-25  0:00       ` Pascal Obry
  1 sibling, 1 reply; 9+ messages in thread
From: Jeffrey D. Cherry @ 1999-05-24  0:00 UTC (permalink / raw)
  To: Al Lively

Al,

The GNAT OS_Lib route is a great way to get environment variables when
you want to port your application accross different platforms.  If you
are going to stay with Windows, then using the Win32 API is a good
"portability" alternative, again the condition being that you stay
within the Windows family (95/98/NT).  Here is a function that I've used
with the OA compiler.  I've used it on Windows 95, 98, and NT without
any problems.  Hope it helps.

Regard,
Jeffrey D. Cherry
Logicon Geodynamics

-----
with Ada.Strings.Unbounded;

function Get_Environment_Variable(Name : in string)
      return Ada.Strings.Unbounded.Unbounded_String;
-----
with Win32;
with Win32.Winbase;

with Ada.Characters.Latin_1;

function Get_Environment_Variable(Name : in string) 
      return Ada.Strings.Unbounded.Unbounded_String is
   
   N : string(1 .. Name'length+1) := Name & Ada.Characters.Latin_1.Nul;
   B : string(1 .. 2048);
   S : Win32.DWORD;
         
begin -- Get_Environment_Variable
   S := Win32.Winbase.GetEnvironmentVariable(Win32.Addr(N),
Win32.Addr(B),
         Win32.DWORD(B'length));
   if (integer(S) <= 0) then
      return Ada.Strings.Unbounded.Null_Unbounded_String;
   else
      return
Ada.Strings.Unbounded.To_Unbounded_String(B(1..positive(S)));
   end if;            
end Get_Environment_Variable;
-----




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

* Re: Dos Environment varables
  1999-05-24  0:00     ` Jeffrey D. Cherry
@ 1999-05-25  0:00       ` Pascal Obry
  1999-05-25  0:00         ` Jeffrey D. Cherry
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal Obry @ 1999-05-25  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1559 bytes --]


Jeffrey D. Cherry <jdcherry@utech.net> a �crit dans le message :
37497064.C4457F71@utech.net...
> Al,
>
> The GNAT OS_Lib route is a great way to get environment variables when
> you want to port your application accross different platforms.  If you
> are going to stay with Windows, then using the Win32 API is a good
> "portability" alternative, again the condition being that you stay
> within the Windows family (95/98/NT).  Here is a function that I've used
> with the OA compiler.  I've used it on Windows 95, 98, and NT without
> any problems.  Hope it helps.

Yes and the best solution could be POSIX. It is compiler and platforms
independant.

Look at Florist for a UNIX implementation and under my homepage for
a partial (yet very usefull) POSIX for Win32.

Pascal.

--

--|------------------------------------------------------------
--| Pascal Obry                               Team-Ada Member |
--|                                                           |
--| EDF-DER-IPN-SID- T T I                                    |
--|                       Intranet: http://cln46gb            |
--| Bureau N-023            e-mail: pascal.obry@edf.fr        |
--| 1 Av G�n�ral de Gaulle  voice : +33-1-47.65.50.91         |
--| 92141 Clamart CEDEX     fax   : +33-1-47.65.50.07         |
--| FRANCE                                                    |
--|------------------------------------------------------------
--|
--|   http://ourworld.compuserve.com/homepages/pascal_obry
--|
--|   "The best way to travel is by means of imagination"







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

* Re: Dos Environment varables
  1999-05-25  0:00       ` Pascal Obry
@ 1999-05-25  0:00         ` Jeffrey D. Cherry
  0 siblings, 0 replies; 9+ messages in thread
From: Jeffrey D. Cherry @ 1999-05-25  0:00 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]

For both Al and Pascal ...

Pascal Obry wrote:
> 
> Yes and the best solution could be POSIX. It is compiler and platforms
> independant.
> 
> Look at Florist for a UNIX implementation and under my homepage for
> a partial (yet very usefull) POSIX for Win32.
> 
> Pascal.
> 

Pascal is quite right.  I've used his Win32POSIX packages successfully
on Windows systems (i.e., 95/98/NT).  I've also used them with ObjectAda
7.1.2a at work and with GNAT 3.11p at home, and have never experienced a
problem.  The POSIX package bodies show how the Win32 API can be used to
implement the POSIX functionality and thus are quite instructive for
those learning the Win32 API.  A great example is demo6 in the
aforementioned Win32POSIX binding.  Is uses the package
POSIX.POSIX_Process_Environment and demonstrates its many services for
dealing with environment variables and strings.

So Al, although the Win32 API is popular, I would suggest that you tuck
my previous example code into a nice bit bucket somewhere and follow the
example shown in the demo6 program.  Pascal rightly points out that
POSIX is a much more portable means of dealing with environment
variables, and other operating system services as well.

Regards,
Jeffrey D. Cherry
Logicon Geodynamics

[-- Attachment #2: Card for Jeffrey D. Cherry --]
[-- Type: text/x-vcard, Size: 375 bytes --]

begin:vcard 
n:Cherry;Jeffrey D.
tel;fax:(805)734-4779
tel;work:(805)606-8838
x-mozilla-html:FALSE
org:Logicon Geodynamics
adr:;;P.O. Box 5548;Vandenberg AFB;CA;93437;USA
version:2.1
email;internet:jdcherry@utech.net
title:Senior Software Engineer/Analyst
note;quoted-printable:BSEE, MSCSc=0D=0AComputer Science Instructor
x-mozilla-cpt:;-6096
fn:Jeffrey D. Cherry
end:vcard

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

end of thread, other threads:[~1999-05-25  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-21  0:00 Dos Environment varables Al Lively
1999-05-21  0:00 ` Keith Thompson
1999-05-21  0:00 ` Gautier
1999-05-21  0:00   ` Al Lively
1999-05-21  0:00     ` Gautier
1999-05-24  0:00     ` Jeffrey D. Cherry
1999-05-25  0:00       ` Pascal Obry
1999-05-25  0:00         ` Jeffrey D. Cherry
1999-05-22  0:00 ` David Botton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox