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.4 required=5.0 tests=BAYES_00,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f9642664cfbe6417 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!news2.euro.net!feeds.phibee-telecom.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: ACCESS TO SYSTEM VARIABLES Date: Mon, 07 Mar 2011 14:51:03 -0800 Organization: None to speak of Message-ID: References: <31c9ef20-db49-4d3e-bafb-0d2a5dca7866@e9g2000vbk.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx01.eternal-september.org; posting-host="mytEQcPL+ceHcrnNa7VoaQ"; logging-data="22639"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188AiNj55AsxMwv4c2/TYjQ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:vha1mUuAfKrwVPq+n3LOygYXSJ0= sha1:QFcCQXieNjPNC8nlJbjyT5Lm2TE= Xref: g2news2.google.com comp.lang.ada:18931 Date: 2011-03-07T14:51:03-08:00 List-Id: Emile8 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 Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"