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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1d0c2b030ed43de7 X-Google-Attributes: gid103376,public From: dkusu@atc-1s.hac.com (David Kusuda) Subject: Re: Unix environment variables Date: 1995/04/03 Message-ID: <3lp2uv$1e2@hacgate2.hac.com>#1/1 X-Deja-AN: 100815553 distribution: world references: <3l9978$5qk@huron.eel.ufl.edu> organization: Hughes Aircraft Company reply-to: dkusu@atc-1s.hac.com newsgroups: comp.lang.ada Date: 1995-04-03T00:00:00+00:00 List-Id: 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;