Subject: Re: readline-5.1 && CGDB
From: Bob Rossi <[email-masked]>
To: [email-masked]
Cc: Chet Ramey <[email-masked]>
Date: Mon, 30 Jan 2006 10:50:13 -0500

On Mon, Jan 30, 2006 at 07:11:45AM -0700, Eric Blake wrote:
> According to Bob Rossi on 1/28/2006 9:19 PM:
> > On Linux, something totally different happens. When I initialize
> > readline, it eventually calls tgetent, which happens to set LINES and
> > COLS to the correct size of the terminal. On cygwin this doesn't happen.
> > The call readline makes to tgetent leaves LINES and COLS alone. Then,
> > in Cygwin when I get to initscr, LINES and COLS is set to 25x80, unless
> > I set the LINES and COLUMNS environment variables before the call to
> > initscr.
> 
> http://www.die.net/doc/linux/man/man3/tgetent.3.html does not document
> that tgetent() messes with the environment, but if that is the case, you
> may be onto something.  Perhaps it really is something cygwin1.dll needs
> to patch to be more similar to linux.

I've finally produced a small test case like you asked me too. It did
take some time, but it should certainly help discover the problem. I've
attached the program.

Basically, you can run the program like './main' and that will have
readline operate on stdout, or you can run it like './main use_pty' and
that will have readline operate on a PTY that I have created. Besides
the code that opens the PTY, there is only the main function, and a
function that modifies the readline library.

If you run with the use_pty option, then ncurses thinks the terminal
size is 25x80 after the call to rl_reset_terminal. Here's the output:

    [bar@bar-nt ~/cvs/cgdb/builddir/tmp] $ ./main.exe use_pty
    before rline_initialize LINES=0 COLS=0

	    before rl_callback LINES=0 COLS=0
	    after rl_callback LINES=75 COLS=85

	    before rl_reset_terminal LINES=75 COLS=85
	    after rl_reset_terminal LINES=25 COLS=80

    after rline_initialize LINES=25 COLS=80

    before initscr LINES=25 COLS=80
    after initscr LINES=25 COLS=80

However, if you run without that option, then ncurses thinks the terminal 
size is the correct terminal size. Here's the output:

    [bar@bar-nt ~/cvs/cgdb/builddir/tmp] $ ./main
    before rline_initialize LINES=0 COLS=0

	    before rl_callback LINES=0 COLS=0
    (tgdb)  after rl_callback LINES=75 COLS=85

	    before rl_reset_terminal LINES=75 COLS=85
	    after rl_reset_terminal LINES=75 COLS=85

    after rline_initialize LINES=75 COLS=85

    before initscr LINES=75 COLS=85
    after initscr LINES=75 COLS=85

I've tracked down the code in readline to the line that manipulates the
LINES/COLS curses variables when initialize readline with a PTY. (This
same code does not modify the LINES/COLS variable when readline is
initialized with stdout).

The code is in terminal.c:_rl_init_terminal_io line 420 for me. It looks
like 
         tgetent_ret = tgetent (term_buffer, term);

where term is the string "dumb".

What I can't understand is, why would tgetent act differently when I
initialize readline with a created PTY, instead of stdout?

Thanks,
Bob Rossi

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/