cks@white.toronto.edu (Chris Siebenmann) (08/11/89)
As it stands, readline.c tries to re-read your termcap entry every time TERM or TERMCAP changes, when it only really needs to do this right before it starts line editing. Since my .profile plus .bashrc change them a total of seven times I decided to fix this. The following context diffs are relative to bash 1.01. They don't QUITE preserve all the facets of readline.c behavior; in particular, rl_reset_terminal()'s argument is now ignored (since I didn't feel like doing yet more malloc()'s to store it away). This doesn't cause problems in bash, but may in some environments readline is used in. For free, you also get a patch to avoid a problem with Ultrix 2.2's termcap routines (they ignore the tty window size fields). If you don't want this, delete the last context diff before patching. *** /tmp/,RCSt1017603 Thu Aug 10 17:37:22 1989 --- readline.c Wed Jul 5 17:49:25 1989 *************** *** 469,472 **** --- 469,475 ---- } + /* This flags whether we need to reinitialize terminal stuff. */ + static int redo_init_term = 1; + /* Initliaze readline (and terminal if not already). */ rl_initialize () *************** *** 474,477 **** --- 477,486 ---- extern char *rl_display_prompt; + if (redo_init_term) + { + init_terminal_io ((char *) NULL); + redo_init_term = 0; + } + /* If we have never been called before, initialize the terminal and data structures. */ *************** *** 520,524 **** /* Initialize the terminal interface. */ ! init_terminal_io ((char *)NULL); /* Initialize default key bindings. */ --- 529,533 ---- /* Initialize the terminal interface. */ ! /* init_terminal_io ((char *)NULL); */ /* Initialize default key bindings. */ *************** *** 1279,1283 **** char *terminal_name; { ! init_terminal_io (terminal_name); } --- 1288,1293 ---- char *terminal_name; { ! redo_init_term = 1; ! /* init_terminal_io (terminal_name); */ } *************** *** 1325,1328 **** --- 1335,1360 ---- #endif /* HACK_TERMCAP_MOTION */ + #ifdef TIOCGWINSZ + { + struct winsize winsize; + + /* Oh HI, oh Brain Dead Ultrix Termcap! */ + screenwidth = tgetnum ("co"); + screenheight = tgetnum ("li"); + if (ioctl(0, TIOCGWINSZ, (char *) &winsize) >= 0) + { + if (winsize.ws_row > 0) + screenheight = winsize.ws_row; + if (winsize.ws_col > 0) + screenwidth = winsize.ws_col; + } + if (screenwidth <= 0) + screenwidth = 80; + screenwidth--; /* PWP: avoid autowrap bugs */ + + if (screenheight <= 0) + screenheight = 24; + } + #else screenwidth = tgetnum ("co"); if (screenwidth <= 0) *************** *** 1333,1337 **** if (screenheight <= 0) screenheight = 24; ! term_im = tgetstr ("im", &buffer); term_ei = tgetstr ("ei", &buffer); --- 1365,1370 ---- if (screenheight <= 0) screenheight = 24; ! #endif ! term_im = tgetstr ("im", &buffer); term_ei = tgetstr ("ei", &buffer); -- "I shall clasp my hands together and bow to the corners of the world." Number Ten Ox, "Bridge of Birds" Chris Siebenmann ...!utgpu!{ncrcan,ontmoh!moore}!ziebmef!cks cks@white.toronto.edu or ...!utgpu!{,csri!}cks