[gnu.bash.bug] Problems with TERMCAP in 0.99

john@hopf.math.nwu.edu (John Franks) (06/13/89)

In subst.c the function sv_terminal() calls 
rl_reset_terminal(get_string_value (name)).
If the TERMCAP variable has just been changed then 
name is "TERMCAP" and the name of a termcap file or 
a termcap entry is passed.  rl_reset_terminal()  passes
it on to init_terminal_io( ) (in readline.c ) which
tries to use it as a terminal name which of course it
isn't.  I see no reason for rl_reset_terminal( ) and
init_terminal_io( )to have any argument at all.

Even after this is fixed there seems to be another bug
I can't track down.  It may be a Sun problem (I'm using
a Sun3, SunOs4.0).  Here's what seems to happen: If I
change the value of TERMCAP, rl_reset_terminal() gets
called as it should, but the old value of TERMCAP 
continues to  be used as the termcap file in that invocation
of bash.  If a new bash is invoked the new termcap file 
is used.  I don't see why this happens.  If anybody 
figurest this out please let me know.

Here is a diff with version 0.99.  It includes some previous changes
to fix the way term_backspace is set.  I posted this 
fix earlier.

*** readline.c.orig.).99	Mon Jun 12 15:58:04 1989
--- readline.c	Mon Jun 12 15:58:03 1989
***************
*** 232,235 ****
--- 231,235 ----
  
  #ifdef SIGWINCH
+ static int
  rl_handle_sigwinch (sig, code, scp)
       int sig, code;
***************
*** 236,242 ****
       struct sigcontext *scp;
  {
    if (readline_echoing_p)
      {
!       rl_reset_terminal (get_string_value ("TERM"));
        putc ('\r', out_stream);
        rl_forced_update_display ();
--- 236,243 ----
       struct sigcontext *scp;
  {
+ 	char *get_string_value( );
    if (readline_echoing_p)
      {
!       rl_reset_terminal ();
        putc ('\r', out_stream);
        rl_forced_update_display ();
***************
*** 495,499 ****
  
    /* Initialize the terminal interface. */
!   init_terminal_io ((char *)NULL);
  
    /* Initialize default key bindings. */
--- 496,500 ----
  
    /* Initialize the terminal interface. */
!   init_terminal_io( );
  
    /* Initialize default key bindings. */
***************
*** 714,717 ****
--- 715,721 ----
  static int line_size = 1024;
  
+ static void move_cursor_relative();
+ static void output_some_chars();
+ 
  /* Non-zero means to always use horizontal scrolling in line display. */
  int horizontal_scroll_mode = 0;
***************
*** 722,726 ****
    register int in, out, c, linenum;
    register char *line = invisible_line;
-   static void move_cursor_relative ();
    int c_pos = 0, v_pos = 0;
    int inv_botlin = 0;		/* Number of lines in newly drawn buffer. */
--- 726,729 ----
***************
*** 1213,1226 ****
  /* Re-initialize the terminal considering that the TERM/TERMCAP variable
     has changed. */
! rl_reset_terminal (terminal_name)
!      char *terminal_name;
  {
!   init_terminal_io (terminal_name);
  }
  
! init_terminal_io (terminal_name)
!      char *terminal_name;
  {
!   char *term = (terminal_name? terminal_name : (char *)getenv ("TERM"));
    char *tgetstr (), *buffer = term_string_buffer;
  
--- 1216,1227 ----
  /* Re-initialize the terminal considering that the TERM/TERMCAP variable
     has changed. */
! rl_reset_terminal ( )
  {
!   init_terminal_io ( );
  }
  
! init_terminal_io( )
  {
!   char *term = (char *)getenv ("TERM");
    char *tgetstr (), *buffer = term_string_buffer;
  
***************
*** 1234,1244 ****
      return;
    }
! 
!   buffer = (char *)xmalloc (2048);
!   BC = tgetstr ("pc", &buffer);
!   PC = buffer ? *buffer : 0;
!   BC = tgetstr ("le", &buffer);
! 
!   term_backspace = tgetstr ("bw", &buffer);
  
    term_cr = tgetstr ("cr", &buffer);
--- 1235,1240 ----
      return;
    }
!   PC = (tgetstr( "pc", &buffer) ? *buffer : 0);
!   BC = term_backspace = tgetstr( "le", &buffer);
  
    term_cr = tgetstr ("cr", &buffer);



John Franks 	Dept of Math. Northwestern University
		Internet	john@math.nwu.edu
		Bitnet		j_franks@nuacc

john@hopf. (John Franks) (06/14/89)

In article <767@accuvax.nwu.edu> john@hopf.math.nwu.edu (John Franks) writes:
>Here is a diff with version 0.99.  It includes some previous changes
>to fix the way term_backspace is set.  I posted this 
>fix earlier.

Unfortunately the previous posting got lost. 
Hope that doesn't confuse things too much.  I am
including my most recent diffs deal with the problem that a termcap
file name is sometimes sent to init_terminal_io() instead of a 
file name (see <767@accuvax.nwu.edu>) as well as the backspace 
problem.  Here are quotes from the original posting:

I believe that there is a bug in redline.c where the termcap backspace
string is read.  It seems this string "term_backspace"  is never actually
set to the correct value.  

Also I had to add a couple of declartions to get it to compile with the
Sun C compiler (SunOS 4.0) on Sun 3's and 4's.  Here are the diffs.


*** readline.c.orig.0.99	Mon Jun 12 15:58:04 1989
--- readline.c	Mon Jun 12 15:58:03 1989
***************
*** 233,234 ****
--- 232,234 ----
  #ifdef SIGWINCH
+ static int
  rl_handle_sigwinch (sig, code, scp)
***************
*** 237,238 ****
--- 237,239 ----
  {
+ 	char *get_string_value( );
    if (readline_echoing_p)
***************
*** 239,241 ****
      {
!       rl_reset_terminal (get_string_value ("TERM"));
        putc ('\r', out_stream);
--- 240,242 ----
      {
!       rl_reset_terminal ();
        putc ('\r', out_stream);
***************
*** 496,498 ****
    /* Initialize the terminal interface. */
!   init_terminal_io ((char *)NULL);
  
--- 497,499 ----
    /* Initialize the terminal interface. */
!   init_terminal_io( );
  
***************
*** 715,716 ****
--- 716,720 ----
  
+ static void move_cursor_relative();
+ static void output_some_chars();
+ 
  /* Non-zero means to always use horizontal scrolling in line display. */
***************
*** 723,725 ****
    register char *line = invisible_line;
-   static void move_cursor_relative ();
    int c_pos = 0, v_pos = 0;
--- 727,728 ----
***************
*** 1214,1219 ****
     has changed. */
! rl_reset_terminal (terminal_name)
!      char *terminal_name;
  {
!   init_terminal_io (terminal_name);
  }
--- 1217,1221 ----
     has changed. */
! rl_reset_terminal ( )
  {
!   init_terminal_io ( );
  }
***************
*** 1220,1225 ****
  
! init_terminal_io (terminal_name)
!      char *terminal_name;
  {
!   char *term = (terminal_name? terminal_name : (char *)getenv ("TERM"));
    char *tgetstr (), *buffer = term_string_buffer;
--- 1222,1226 ----
  
! init_terminal_io( )
  {
!   char *term = (char *)getenv ("TERM");
    char *tgetstr (), *buffer = term_string_buffer;
***************
*** 1235,1243 ****
    }
! 
!   buffer = (char *)xmalloc (2048);
!   BC = tgetstr ("pc", &buffer);
!   PC = buffer ? *buffer : 0;
!   BC = tgetstr ("le", &buffer);
! 
!   term_backspace = tgetstr ("bw", &buffer);
  
--- 1236,1239 ----
    }
!   PC = (tgetstr( "pc", &buffer) ? *buffer : 0);
!   BC = term_backspace = tgetstr( "le", &buffer);
  

###################################################################
  
In builtins.c there are some embedded newlines in strings which the
Sun cc doesn't like:

diff builtins.c builtins.c.orig.0.99
363c363,364
< 	command name.\n\n\
---
> 	command name.
> 
367c368,369
< 	respectively.\n\n\
---
> 	respectively.
> 

##################################################################
In shell.c the two functions termination_unwind_protect() and 
throw_to_top_level()  must be declared sighandler for the Sun cc.

diff shell.c shell.c.orig.0.99
768d767
< sighandler
778d776
< sighandler


John Franks 	Dept of Math. Northwestern University
		Internet	john@math.nwu.edu
		Bitnet		j_franks@nuacc

bfox@AUREL.CALTECH.EDU (Brian Fox) (06/14/89)

   Date: 12 Jun 89 21:42:05 GMT
   From: john@hopf.math.nwu.edu  (John Franks)
   Organization: Northwestern Univ. Evanston, Il.
   Sender: bug-bash-request@prep.ai.mit.edu


   Even after this is fixed there seems to be another bug
   I can't track down.  It may be a Sun problem (I'm using
   a Sun3, SunOs4.0).  Here's what seems to happen: If I
   change the value of TERMCAP, rl_reset_terminal() gets
   called as it should, but the old value of TERMCAP 
   continues to  be used as the termcap file in that invocation
   of bash.  If a new bash is invoked the new termcap file 
   is used.  I don't see why this happens.  If anybody 
   figurest this out please let me know.

The problem should happen on any Unix system.

The environment that is given to the shell is the one that the termcap
library will use when looking for the value of TERMCAP.  In fact, any
call to getenv() will produce the value of the environment passed into
the shell instead of the environment that the shell passes out to
programs that it starts.

Perhaps the shell should supply its own getenv () function which would
know how to do the right thing.

Brian Fox