To: vim-dev@vim.org Subject: Patch 6.1.362 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.362 Problem: tgetent() may return zero for success. tgetflag() may return -1 for an error. Solution: Check tgetflag() for returning a positive value. Add an autoconf check for the value that tgetent() returns. Files: src/auto/configure, src/config.h.in, src/configure.in, src/term.c *** ../vim61.361/src/auto/configure Mon Jan 6 21:55:57 2003 --- src/auto/configure Mon Feb 17 12:00:06 2003 *************** *** 5423,5432 **** echo "$ac_t""none found" 1>&6 fi echo $ac_n "checking whether termcap.h contains ospeed""... $ac_c" 1>&6 ! echo "configure:5381: checking whether termcap.h contains ospeed" >&5 cat > conftest.$ac_ext <&6 fi + if test "x$olibs" != "x$LIBS"; then + echo $ac_n "checking what tgetent() returns for an unknown terminal""... $ac_c" 1>&6 + echo "configure:5507: checking what tgetent() returns for an unknown terminal" >&5 + if test "$cross_compiling" = yes; then + { echo "configure: error: failed to compile test program." 1>&2; exit 1; } + else + cat > conftest.$ac_ext < + #endif + main() + {char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist"); exit(res != 0); } + EOF + if { (eval echo configure:5521: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null + then + echo "$ac_t""zero" 1>&6; cat >> confdefs.h <<\EOF + #define TGETENT_ZERO_ERR 0 + EOF + + else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + echo "$ac_t""non-zero" 1>&6 + fi + rm -fr conftest* + fi + + fi + echo $ac_n "checking whether termcap.h contains ospeed""... $ac_c" 1>&6 ! echo "configure:5539: checking whether termcap.h contains ospeed" >&5 cat > conftest.$ac_ext < + #endif + main() + {char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist"); exit(res != 0); }], + AC_MSG_RESULT(zero); AC_DEFINE(TGETENT_ZERO_ERR, 0), + AC_MSG_RESULT(non-zero), + AC_MSG_ERROR(failed to compile test program.)) fi AC_MSG_CHECKING(whether termcap.h contains ospeed) *** ../vim61.361/src/term.c Thu Feb 20 21:36:44 2003 --- src/term.c Mon Feb 17 11:51:49 2003 *************** *** 1642,1656 **** TGETSTR(string_names[i].name, &tp); } ! if ((T_MS == NULL || T_MS == empty_option) && tgetflag("ms")) T_MS = (char_u *)"y"; ! if ((T_XS == NULL || T_XS == empty_option) && tgetflag("xs")) T_XS = (char_u *)"y"; ! if ((T_DB == NULL || T_DB == empty_option) && tgetflag("db")) T_DB = (char_u *)"y"; ! if ((T_DA == NULL || T_DA == empty_option) && tgetflag("da")) T_DA = (char_u *)"y"; ! if ((T_UT == NULL || T_UT == empty_option) && tgetflag("ut")) T_UT = (char_u *)"y"; --- 1642,1663 ---- TGETSTR(string_names[i].name, &tp); } ! /* tgetflag() returns 1 if the flag is present, 0 if not and ! * possibly -1 if the flag doesn't exist. */ ! if ((T_MS == NULL || T_MS == empty_option) ! && tgetflag("ms") > 0) T_MS = (char_u *)"y"; ! if ((T_XS == NULL || T_XS == empty_option) ! && tgetflag("xs") > 0) T_XS = (char_u *)"y"; ! if ((T_DB == NULL || T_DB == empty_option) ! && tgetflag("db") > 0) T_DB = (char_u *)"y"; ! if ((T_DA == NULL || T_DA == empty_option) ! && tgetflag("da") > 0) T_DA = (char_u *)"y"; ! if ((T_UT == NULL || T_UT == empty_option) ! && tgetflag("ut") > 0) T_UT = (char_u *)"y"; *************** *** 2104,2123 **** int i; i = TGETENT(tbuf, term); ! if (i < 1) { /* On FreeBSD tputs() gets a SEGV after a tgetent() which fails. Call * tgetent() with the always existing "dumb" entry to avoid a crash or * hang. */ (void)TGETENT(tbuf, "dumb"); ! if (i == -1) return (char_u *)_("Cannot open termcap file"); if (i == 0) #ifdef TERMINFO return (char_u *)_("Terminal entry not found in terminfo"); #else ! return (char_u *)_("Terminal entry not found in termcap"); #endif } return NULL; --- 2111,2136 ---- int i; i = TGETENT(tbuf, term); ! if (i < 0 /* -1 is always an error */ ! # ifdef TGETENT_ZERO_ERR ! || i == 0 /* sometimes zero is also an error */ ! # endif ! ) { /* On FreeBSD tputs() gets a SEGV after a tgetent() which fails. Call * tgetent() with the always existing "dumb" entry to avoid a crash or * hang. */ (void)TGETENT(tbuf, "dumb"); ! if (i < 0) ! # ifdef TGETENT_ZERO_ERR return (char_u *)_("Cannot open termcap file"); if (i == 0) + # endif #ifdef TERMINFO return (char_u *)_("Terminal entry not found in terminfo"); #else ! return (char_u *)_("Terminal entry not found in termcap"); #endif } return NULL; *** ../vim61.361/src/version.c Tue Feb 25 21:41:42 2003 --- src/version.c Tue Feb 25 21:46:43 2003 *************** *** 608,609 **** --- 612,615 ---- { /* Add new patch number below this line */ + /**/ + 362, /**/ -- TIM: To the north there lies a cave, the cave of Caerbannog, wherein, carved in mystic runes, upon the very living rock, the last words of Olfin Bedwere of Rheged make plain the last resting place of the most Holy Grail. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///