From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ed86965848f8610b X-Google-Attributes: gid103376,public From: gisle@krake.ii.uib.no (Gisle S{lensminde) Subject: Re: Reading environment variables in ADA? Date: 1998/09/17 Message-ID: #1/1 X-Deja-AN: 392158579 Content-Transfer-Encoding: 8bit References: <6tdl75$qs6$2@nyheter.chalmers.se> Content-Type: text/plain; charset=iso-8859-1 Organization: University of Bergen, Norway Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-09-17T00:00:00+00:00 List-Id: In article <6tdl75$qs6$2@nyheter.chalmers.se>, Stefan Lingdell wrote: >How do you read environment variables in ADA? I'm >programming under UNIX (SunOS) if that makes any >difference. > >Thanks, >Stefan > There is packages to access environment variables and other OS things. Since this is a posix feature, you can use the florist package, If have thought to use a lot of OS features, that is a good idea. If not, you can use the C interface. The program under reads the HOME environment variable, and demonstrates how the C interface can be used for this. I have tested it for solaris/gnat, but should work on all Unix systems. If you use other compilers than GNAT, you maybe must link with the C library. The example: with Interfaces.C.Strings; use type Interfaces.C.Strings.Chars_Ptr; with Ada.Text_IO; use Ada.Text_IO; procedure env is package Cstr renames Interfaces.C.strings; function Getenv(Name : Cstr.Chars_Ptr) return Cstr.Chars_Ptr; pragma Import(C, Getenv); Var_Name, Result : Cstr.Chars_Ptr; begin Var_Name := Cstr.New_String("HOME"); Result := Getenv(Var_Name); Cstr.Free(Var_Name); if Result /= Cstr.Null_Ptr then Put_Line(Cstr.Value(Result)); end if; end; -- ------------------------------------------------------------------------ Gisle S�lensminde Tlf: 55 34 07 63 Eliasmarken 16 5031 Laksev�g epost: gisle@ii.uib.no UNIX is user friendly. It's just selective about who its friends are. ------------------------------------------------------------------------