Re: bidiv and the default $COLUMNS value

2007-05-06 Thread Oron Peled
On Sunday, 6 בMay 2007 22:06, Maxim Veksler wrote:
> What is tput then? I know it speaks with the terminfo db and that it's
> a "rather portable" to method to encode color strings (try tput setaf
> 1; whoami; tput setaf 7).

That's true, but...

> I assume this adds a fourth mechanisms?

No. Let's see:
$ strace tputs cols
..
ioctl(1, TIOCGWINSZ, {ws_row=55, ws_col=132, ws_xpixel=0, ws_ypixel=0}) = 0
..

So this utility looks at the terminfo database, for terminal
features, but also (in "modern" versions) use the ioctl() mentioned
by Nadav to query the tty driver.

> ncurses being 5th?

No. Ncurses is just a hi-level library (for some definition of hi-level ;-)
working above terminfo (used to work above termcap in Berkely Unix) and
provide more abstractions (e.g: [text] windows, scrolling management,
cursor motion, etc.)

Just to complement what Nadav already describe, if you happen to work
in an old shell that does not contain signal handling for SIGWINCH and
change your xterm size, the standard workaround is to run:
eval `resize`
Which issues the ioctl and output the commands to set COLUMNS and LINES
environment variables.

You may notice that the output of resize depends on the $SHELL environment
variable, so it may be used both by sh/ksh/bash and csh/tcsh.

-- 
Oron Peled Voice/Fax: +972-4-8228492
[EMAIL PROTECTED]  http://www.actcom.co.il/~oron
ICQ UIN: 16527398

She sells cshs by the cshore.   - Rob Malda

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-06 Thread Maxim Veksler

On 5/6/07, Nadav Har'El <[EMAIL PROTECTED]> wrote:

On Sat, May 05, 2007, Avraham Rosenberg wrote about "bidiv and the default $COLUMNS 
value":
> After rereading the man page for bidiv, I cheched: echo $COLUMNS.
> As suspected, I got an odd number: 99.
>
> Question: Where is this value defined ?

I completely missed this question (which has nothing to do with bidiv).

So here is a brief history of COLUMNS...

COLUMNS is a variable set by your shell (zsh, bash, tcsh, or whatever you're
using). The idea is that your shell knows what is the width of your terminal
and passes this knowledge to the programs it runs; A few of the familiar
Unix programs use this knowledge - for example "ls" by default shows the file
listing in multile columns, up to the terminal's width. As you saw, bidiv
also uses this variable.

In the "old days", terminals used to have fixed widths; If you had a vt100
terminal (TERM=vt100), then the width was always 80. If you had a AT&T 5620
terminal, the width was 88, and so on, and the "termcap" or "terminfo"
libraries was used to get this information based on the terminal name.
However, when resisable windows appeared in Unix (on the aforementioned 5620,
and in X-Windows), this fixed width was no longer enough, and the terminal's
(or actually, terminal emulator window's) width could be changed at any
moment.

This is when three new facilities were added to Unix. First, a window
width/hight setting was added to the tty (the "tty" is the Unix mechanism for
a terminal emulator to connect to a process, usually a shell, running in it).
See "stty -a" (and the TIOCSWINSZ ioctl). This was almost enough - your shell
and the processes it runs can now figure out at any moment what's the window's
current size. But should the shell (which needs to know the terminal's width,
e.g., for command line editing) try this ioctl on every command? Instead of
forcing it to check every time, a new signal was invented - SIGWINCH, "window
change". When the terminal emulator is resized, it sends its child process
(namely, your shell) a SIGWINCH signal. The shell then uses the ioctl to get
its current window size, and remembers it. The third mechanism is a shell
variable, COLUMNS, which gets updated when the shell learns of a new window
width. This feature is useful because ioctl's are "nonstandard" or "complex"
and using variables is easier; it also allows the user to easily override
the width; And it also works with pipes and redirections.



Learning something new everyday.

What is tput then? I know it speaks with the terminfo db and that it's
a "rather portable" to method to encode color strings (try tput setaf
1; whoami; tput setaf 7). I assume this adds a fourth mechanisms?
ncurses being 5th?

[EMAIL PROTECTED]:~$ echo $COLUMNS
88
[EMAIL PROTECTED]:~$ tput cols
88
#resizing window...
[EMAIL PROTECTED]:~$ echo $COLUMNS
112
[EMAIL PROTECTED]:~$ tput cols
112



--
Nadav Har'El|   Sunday, May  6 2007, 18 Iyyar 5767
[EMAIL PROTECTED] |-
Phone +972-523-790466, ICQ 13349191 |I have a great signature, but it won't
http://nadav.harel.org.il   |fit at the end of this message -- Fermat




--
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-06 Thread Avraham Rosenberg
On Sun, May 06, 2007 at 11:53:14AM +0300, Nadav Har'El wrote:
> On Sat, May 05, 2007, Avraham Rosenberg wrote about "bidiv and the default 
> $COLUMNS value":
> > After rereading the man page for bidiv, I cheched: echo $COLUMNS.
> > As suspected, I got an odd number: 99.
> > 
> > Question: Where is this value defined ?
> 
> I completely missed this question (which has nothing to do with bidiv).
>^^
> So here is a brief history of COLUMNS...
..
Hi,
Thanks for the last answer. The only connection is that, when one
does not specify the width, bidiv uses the $COLUMNS value (see
bidiv man page).
It so happens that 1-My old version of bidiv does not like odd
values for the width, 2-The number of columns of the xterm, as
stated in .Xresources was an odd number. Hence the harmless, but
intriguing error messages.
The apt-get upgrade bidiv asked me to replace a lot of additional
packages. As, as a rule, I prefer to upgrade by several small
steps (only apparently I negected this for a long time), and I have
no real problems with bidiv, I prefered to answer: don't!
Cheers, Avraham
-- 
Please avoid sending to this address attachments in excess of 2MByte, 
or any Excell or Powerpoint attachments.

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-06 Thread Ilya Konstantinov

On 5/6/07, Nadav Har'El <[EMAIL PROTECTED]> wrote:


When the terminal emulator is resized, it sends its child process
(namely, your shell) a SIGWINCH signal.



Does it strike you too odd that back then, signals could be introduced for
such immediate (and passing) needs? Or is it just because signals haven't
caught on as an IPC mechanism?


Re: bidiv and the default $COLUMNS value

2007-05-06 Thread Nadav Har'El
On Sat, May 05, 2007, Avraham Rosenberg wrote about "bidiv and the default 
$COLUMNS value":
> After rereading the man page for bidiv, I cheched: echo $COLUMNS.
> As suspected, I got an odd number: 99.
> 
> Question: Where is this value defined ?

I completely missed this question (which has nothing to do with bidiv).

So here is a brief history of COLUMNS...

COLUMNS is a variable set by your shell (zsh, bash, tcsh, or whatever you're
using). The idea is that your shell knows what is the width of your terminal
and passes this knowledge to the programs it runs; A few of the familiar
Unix programs use this knowledge - for example "ls" by default shows the file
listing in multile columns, up to the terminal's width. As you saw, bidiv
also uses this variable.

In the "old days", terminals used to have fixed widths; If you had a vt100
terminal (TERM=vt100), then the width was always 80. If you had a AT&T 5620
terminal, the width was 88, and so on, and the "termcap" or "terminfo"
libraries was used to get this information based on the terminal name.
However, when resisable windows appeared in Unix (on the aforementioned 5620,
and in X-Windows), this fixed width was no longer enough, and the terminal's
(or actually, terminal emulator window's) width could be changed at any
moment.

This is when three new facilities were added to Unix. First, a window
width/hight setting was added to the tty (the "tty" is the Unix mechanism for
a terminal emulator to connect to a process, usually a shell, running in it).
See "stty -a" (and the TIOCSWINSZ ioctl). This was almost enough - your shell
and the processes it runs can now figure out at any moment what's the window's
current size. But should the shell (which needs to know the terminal's width,
e.g., for command line editing) try this ioctl on every command? Instead of
forcing it to check every time, a new signal was invented - SIGWINCH, "window
change". When the terminal emulator is resized, it sends its child process
(namely, your shell) a SIGWINCH signal. The shell then uses the ioctl to get
its current window size, and remembers it. The third mechanism is a shell
variable, COLUMNS, which gets updated when the shell learns of a new window
width. This feature is useful because ioctl's are "nonstandard" or "complex"
and using variables is easier; it also allows the user to easily override
the width; And it also works with pipes and redirections.

-- 
Nadav Har'El|   Sunday, May  6 2007, 18 Iyyar 5767
[EMAIL PROTECTED] |-
Phone +972-523-790466, ICQ 13349191 |I have a great signature, but it won't
http://nadav.harel.org.il   |fit at the end of this message -- Fermat

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-06 Thread Nadav Har'El
On Sun, May 06, 2007, Avraham Rosenberg wrote about "Re: bidiv and the default 
$COLUMNS value":
> Good Morning
> Thanks for the prompt reaction.
> As it did not answer my question, I downloaded the tarbals for
> bidiv, versions 1.5 and 1.4, grepped -i for COLUMNS (found them
> only in the remarks) and compared (diff) the bidiv and Makefile
> files between the two distributions (none found).
> I guess that, at this stage, I shall call it a day.

I'm afraid I didn't understand what you just said. Did you try to compile
version 1.5 (using the link I gave), and the bug is still there?

The change between 1.4 and 1.5 had to do with a buffer that was allocated
using the given width (either COLUMNS or a -w parameter), but was allocated
a bit too short, which is why I thought this was the same bug you're seeing.
The fact that the diff did not mention the word "COLUMNS" is completely
irrelevant to that bug...

Nadav.

-- 
Nadav Har'El|   Sunday, May  6 2007, 18 Iyyar 5767
[EMAIL PROTECTED] |-
Phone +972-523-790466, ICQ 13349191 |The path of least resistance is what
http://nadav.harel.org.il   |makes rivers and politicians crooked.

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-05 Thread Avraham Rosenberg
Good Morning
Thanks for the prompt reaction.
As it did not answer my question, I downloaded the tarbals for
bidiv, versions 1.5 and 1.4, grepped -i for COLUMNS (found them
only in the remarks) and compared (diff) the bidiv and Makefile
files between the two distributions (none found).
I guess that, at this stage, I shall call it a day.

Thanks to you and Dan for the program. I use it a lot.
Cheers, Avraham

-- 
Please avoid sending to this address attachments in excess of 2MByte, 
or any Excell or Powerpoint attachments.

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-05 Thread Lior Kaplan
Nadav Har'El wrote:
> On Sat, May 05, 2007, Avraham Rosenberg wrote about "bidiv and the default 
> $COLUMNS value":
>> Hi,
>> This is not a problen. I am just curious.
>> In my system, whenever I use bidiv without giving a value to the
>> parameter w, or when giving it an odd value, I get the error
>> message:
>> *** glibc detected *** free(): invalid next size (fast): 0x0804b650 ***
> 
> It sounds like this might be an old bug from Bidiv 1.4, which Dan Kenigsberg
> and Shachar Raindel discovered almost two years ago, and was fixed in Bidiv
> 1.5. Could it be that you're running Bidiv 1.4? I can't seem to replicate
> the problem on my own computer, running Bidiv 1.5.
> 
> You can try the latest (1.5) source release from:
> 
>   http://ftp.ivrix.org.il/pub/ivrix/src/cmdline/bidiv-1.5.tgz
> 
> Unfortunately, my bidiv distribution is extremely messy; I don't have a web
> site for it, and have no idea which versions the various distributions
> picked up (except in Fedora Core, when I know Dan Kenigsberg added version
> 1.5). 

FYI: debian has 1.5

-- 

Lior Kaplan
[EMAIL PROTECTED]
http://www.Guides.co.il

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: bidiv and the default $COLUMNS value

2007-05-05 Thread Nadav Har'El
On Sat, May 05, 2007, Avraham Rosenberg wrote about "bidiv and the default 
$COLUMNS value":
> Hi,
> This is not a problen. I am just curious.
> In my system, whenever I use bidiv without giving a value to the
> parameter w, or when giving it an odd value, I get the error
> message:
> *** glibc detected *** free(): invalid next size (fast): 0x0804b650 ***

It sounds like this might be an old bug from Bidiv 1.4, which Dan Kenigsberg
and Shachar Raindel discovered almost two years ago, and was fixed in Bidiv
1.5. Could it be that you're running Bidiv 1.4? I can't seem to replicate
the problem on my own computer, running Bidiv 1.5.

You can try the latest (1.5) source release from:

http://ftp.ivrix.org.il/pub/ivrix/src/cmdline/bidiv-1.5.tgz

Unfortunately, my bidiv distribution is extremely messy; I don't have a web
site for it, and have no idea which versions the various distributions
picked up (except in Fedora Core, when I know Dan Kenigsberg added version
1.5). Which Linux distribution are you using that you got your bidiv from,
and do you know what version it uses?

Thanks,
Nadav.


-- 
Nadav Har'El| Saturday, May  5 2007, 18 Iyyar 5767
[EMAIL PROTECTED] |-
Phone +972-523-790466, ICQ 13349191 |How's he gonna read that magazine rolled
http://nadav.harel.org.il   |up like that? What the ... - a fly.

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



bidiv and the default $COLUMNS value

2007-05-05 Thread Avraham Rosenberg
Hi,
This is not a problen. I am just curious.
In my system, whenever I use bidiv without giving a value to the
parameter w, or when giving it an odd value, I get the error
message:
*** glibc detected *** free(): invalid next size (fast): 0x0804b650 ***
   ^
No problems when using bidiv -w x, where x is an even number.
After rereading the man page for bidiv, I cheched: echo $COLUMNS.
As suspected, I got an odd number: 99.

Question: Where is this value defined ?
Thanks, Avraham

PS The command: export COLUMNS=98, did not influence bidiv's
behaviour, altough echo $COLUMNS gave 98.

-- 
Please avoid sending to this address attachments in excess of 2MByte, 
or any Excell or Powerpoint attachments.

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]