comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: ACCESS TO SYSTEM VARIABLES
Date: Mon, 07 Mar 2011 14:51:03 -0800
Date: 2011-03-07T14:51:03-08:00	[thread overview]
Message-ID: <lnsjuytui0.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 31c9ef20-db49-4d3e-bafb-0d2a5dca7866@e9g2000vbk.googlegroups.com

Emile8 <pocchiola.yves@gmail.com> writes:
> On Linux I want to know the number of lines and columns of my working
> terminal. When on the command line I call by hand the system variables
> $LINES and $COLUMNS, I get the right answers.
>
> When I try to do the same from a program written in Gnat Ada 2005
> (Year 2010) using the specialized package Ada.Environment_Variables,
> as in the following code called from the same terminal, I get no
> answer for COLUMNS and LINES as if the corresponding system variables
> do not exist (I get a correct answer for PATH).
>
>
> with Ada.Environment_Variables; use Ada.Environment_Variables;
> with Ada.Text_Io; use Ada.Text_Io;
>
> procedure Print_Env is
> begin
> Put_Line("Columns : " & Value("COLUMNS"));
> Put_Line("Lines : " & Value("LINES"));
> Put_Line("Path : " & Value("PATH"));
> end Print_Env;
>
>
> I would like to understand the reasons of this behavior. Are there
> different kinds of system variables in Linux ? Those as HOME, PATH
> whose values depend only on the user session and those as LINES,
> COLUMNS defined for each used terminal. Is there a way in Ada to
> overcome this limitation ?

$LINES and $COLUMNS are bash shell variables, not environment
variables.  They're not visible from your Ada program any more than
variables declared within your Ada program would be visible from
a shell (even if the shell was launched by your Ada program).

bash probably obtains the values by invoking the ioctl() system
call with TIOCGWINSZ as the second argument.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



      parent reply	other threads:[~2011-03-07 22:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-07  9:34 ACCESS TO SYSTEM VARIABLES Emile8
2011-03-07 11:47 ` Georg Bauhaus
2011-03-07 15:32   ` Adam Beneschan
2011-03-07 20:14   ` Emile8
2011-03-07 21:32     ` Peter C. Chapin
2011-03-08 17:13       ` Emile8
2011-03-09 18:59         ` Emile8
2011-03-07 22:51 ` Keith Thompson [this message]
replies disabled

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