Submitted by: Alexander E. Patrakov
Date: 2005-12-07
Initial Package Version: 5.5
Upstream Status: Backport
Origin: Cherry-picked from ftp://invisible-island.net/ncurses/5.5/*.gz
Description: Fixes the following bugs:

* memory leak in keyname()
* mishandling of overlapped wide characters, http://bugs.debian.org/316663
* problems with line-drawing characters on cygwin, http://bugs.debian.org/338234
* mishandling of EINTR in tcgetattr/tcsetattr, http://bugs.debian.org/339518
* mishandling of single-column multibyte characters, http://bugs.debian.org/341661

--- ncurses-5.5-20051015+/ncurses/base/MKkeyname.awk	2005-04-30 19:26:25.000000000 +0000
+++ ncurses-5.5-20051022/ncurses/base/MKkeyname.awk	2005-10-22 19:01:23.000000000 +0000
@@ -97,6 +97,7 @@
 	print "						break;"
 	print "					}"
 	print "				}"
+	print "				free(bound);"
 	print "				if (result != 0)"
 	print "					break;"
 	print "			}"
--- ncurses-5.5-20051022+/ncurses/base/lib_addch.c	2005-03-27 16:52:16.000000000 +0000
+++ ncurses-5.5-20051029/ncurses/base/lib_addch.c	2005-10-30 00:51:36.000000000 +0000
@@ -315,7 +315,7 @@
 	     * setup though.
 	     */
 	    for (i = 0; i < len; ++i) {
-		if (isWidecBase(win->_line[y].text[i])) {
+		if (isWidecBase(win->_line[y].text[x + i])) {
 		    break;
 		} else if (isWidecExt(win->_line[y].text[x + i])) {
 		    for (j = i; x + j <= win->_maxx; ++j) {
@@ -334,7 +334,9 @@
 	    for (i = 0; i < len; ++i) {
 		NCURSES_CH_T value = ch;
 		SetWidecExt(value, i);
-		TR(TRACE_VIRTPUT, ("multicolumn %d:%d", i + 1, len));
+		TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)",
+				   i + 1, len,
+				   win->_begy + y, win->_begx + x));
 		line->text[x] = value;
 		CHANGED_CELL(line, x);
 		++x;
--- ncurses-5.5-20051022+/ncurses/base/lib_bkgd.c	2005-04-16 18:03:48.000000000 +0000
+++ ncurses-5.5-20051029/ncurses/base/lib_bkgd.c	2005-10-30 00:41:09.000000000 +0000
@@ -131,11 +131,11 @@
 
 	for (y = 0; y <= win->_maxy; y++) {
 	    for (x = 0; x <= win->_maxx; x++) {
-		if (CharEq(win->_line[y].text[x], old_bkgrnd))
+		if (CharEq(win->_line[y].text[x], old_bkgrnd)) {
 		    win->_line[y].text[x] = win->_nc_bkgd;
-		else {
+		} else {
 		    NCURSES_CH_T wch = win->_line[y].text[x];
-		    RemAttr(wch, (~A_ALTCHARSET));
+		    RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT)));
 		    win->_line[y].text[x] = _nc_render(win, wch);
 		}
 	    }
--- ncurses-5.5-20051022+/ncurses/base/lib_erase.c	2001-12-19 01:06:13.000000000 +0000
+++ ncurses-5.5-20051029/ncurses/base/lib_erase.c	2005-10-30 00:36:36.000000000 +0000
@@ -58,6 +59,24 @@
 	    start = win->_line[y].text;
 	    end = &start[win->_maxx];
 
+	    /*
+	     * If this is a derived window, we have to handle the case where
+	     * a multicolumn character extends into the window that we are
+	     * erasing.
+	     */
+	    if_WIDEC({
+		if (isWidecExt(start[0])) {
+		    int x = (win->_parent != 0) ? (win->_begx) : 0;
+		    while (x-- > 0) {
+			if (isWidecBase(start[-1])) {
+			    --start;
+			    break;
+			}
+			--start;
+		    }
+		}
+	    });
+
 	    for (sp = start; sp <= end; sp++)
 		*sp = blank;
 
--- ncurses-5.5-20051029+/misc/terminfo.src	2005-10-26 23:21:06.000000000 +0000
+++ ncurses-5.5-20051112/misc/terminfo.src	2005-11-12 23:01:03.000000000 +0000
@@ -4731,32 +4731,35 @@
 #   civis [make cursor invisible] causes everything to stackdump? \E[?25l\E[?1c
 #   ech   [erase characters param] broken \E[%p1%dX
 #   kcbt  [back-tab key] not implemented in cygwin?  \E[Z
+#
+# 2005/11/12 -TD
+#	Remove cbt since it does not work in current cygwin
+#	Add 'mir' and 'in' flags based on tack
 cygwin|ansi emulation for Cygwin, 
-	am, hs, in, msgr, xon, 
+	am, hs, mir, msgr, xon, 
 	colors#8, it#8, pairs#64, 
 	acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, 
-	bel=^G, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, cr=^M, 
-	cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=\E[B, 
-	cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 
-	cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P, 
-	dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, fsl=^G, 
-	home=\E[H, hpa=\E[%i%p1%dG, ht=^I, ich=\E[%p1%d@, 
-	ich1=\E[@, il=\E[%p1%dL, il1=\E[L, ind=^J, invis=\E[8m, 
-	kb2=\E[G, kbs=^H, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, 
-	kcuu1=\E[A, kdch1=\E[3~, kend=\E[4~, kf1=\E[[A, 
-	kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, 
-	kf14=\E[26~, kf15=\E[28~, kf16=\E[29~, kf17=\E[31~, 
-	kf18=\E[32~, kf19=\E[33~, kf2=\E[[B, kf20=\E[34~, 
-	kf3=\E[[C, kf4=\E[[D, kf5=\E[[E, kf6=\E[17~, kf7=\E[18~, 
-	kf8=\E[19~, kf9=\E[20~, khome=\E[1~, kich1=\E[2~, 
-	knp=\E[6~, kpp=\E[5~, kspd=^Z, nel=^M^J, op=\E[39;49m, 
-	rc=\E8, rev=\E[7m, ri=\EM, rmacs=\E[10m, 
-	rmcup=\E[2J\E[?47l\E8, rmir=\E[4l, rmpch=\E[10m, 
-	rmso=\E[27m, rmul=\E[24m, rs1=\Ec\E]R, sc=\E7, 
-	setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 
+	bel=^G, bold=\E[1m, clear=\E[H\E[J, cr=^M, cub=\E[%p1%dD, 
+	cub1=^H, cud=\E[%p1%dB, cud1=\E[B, cuf=\E[%p1%dC, 
+	cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, 
+	cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, 
+	dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, fsl=^G, home=\E[H, 
+	hpa=\E[%i%p1%dG, ht=^I, ich=\E[%p1%d@, ich1=\E[@, 
+	il=\E[%p1%dL, il1=\E[L, ind=^J, invis=\E[8m, kb2=\E[G, 
+	kbs=^H, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, 
+	kdch1=\E[3~, kend=\E[4~, kf1=\E[[A, kf10=\E[21~, 
+	kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, 
+	kf15=\E[28~, kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, 
+	kf19=\E[33~, kf2=\E[[B, kf20=\E[34~, kf3=\E[[C, kf4=\E[[D, 
+	kf5=\E[[E, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, 
+	khome=\E[1~, kich1=\E[2~, knp=\E[6~, kpp=\E[5~, kspd=^Z, 
+	nel=^M^J, op=\E[39;49m, rc=\E8, rev=\E[7m, ri=\EM, 
+	rmacs=\E[10m, rmcup=\E[2J\E[?47l\E8, rmir=\E[4l, 
+	rmpch=\E[10m, rmso=\E[27m, rmul=\E[24m, rs1=\Ec\E]R, 
+	sc=\E7, setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 
 	sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 
-	sgr0=\E[0;10m, smacs=\E11m, smcup=\E7\E[?47h, smir=\E[4h, 
-	smpch=\E[11m, smso=\E[7m, smul=\E[4m, tsl=\E];, 
+	sgr0=\E[0;10m, smacs=\E[11m, smcup=\E7\E[?47h, 
+	smir=\E[4h, smpch=\E[11m, smso=\E[7m, smul=\E[4m, tsl=\E];, 
 	u6=\E[%i%d;%dR, u7=\E[6n, u8=\E[?6c, u9=\E[c, 
 	vpa=\E[%i%p1%dd, 
 
--- ncurses-5.5-20051112+/ncurses/tinfo/lib_ttyflags.c	2003-05-17 23:50:37.000000000 +0000
+++ ncurses-5.5-20051119/ncurses/tinfo/lib_ttyflags.c	2005-11-19 20:36:23.000000000 +0000
@@ -59,28 +59,51 @@
 NCURSES_EXPORT(int)
 _nc_get_tty_mode(TTY * buf)
 {
-    if (cur_term == 0
-	|| GET_TTY(cur_term->Filedes, buf) != 0) {
-	memset(buf, 0, sizeof(*buf));
-	return (ERR);
+    int result = OK;
+
+    if (cur_term == 0) {
+	result = ERR;
+    } else {
+	for (;;) {
+	    if (GET_TTY(cur_term->Filedes, buf) != 0) {
+		if (errno == EINTR)
+		    continue;
+		result = ERR;
+	    }
+	    break;
+	}
     }
+
+    if (result == ERR)
+	memset(buf, 0, sizeof(*buf));
+
     TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
 		    cur_term->Filedes, _nc_trace_ttymode(buf)));
-    return (OK);
+    return (result);
 }
 
 NCURSES_EXPORT(int)
 _nc_set_tty_mode(TTY * buf)
 {
-    if (cur_term == 0
-	|| SET_TTY(cur_term->Filedes, buf) != 0) {
-	if ((errno == ENOTTY) && (SP != 0))
-	    SP->_notty = TRUE;
-	return (ERR);
+    int result = OK;
+
+    if (cur_term == 0) {
+	result = ERR;
+    } else {
+	for (;;) {
+	    if (SET_TTY(cur_term->Filedes, buf) != 0) {
+		if (errno == EINTR)
+		    continue;
+		if ((errno == ENOTTY) && (SP != 0))
+		    SP->_notty = TRUE;
+		result = ERR;
+	    }
+	    break;
+	}
     }
     TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
 		    cur_term->Filedes, _nc_trace_ttymode(buf)));
-    return (OK);
+    return (result);
 }
 
 NCURSES_EXPORT(int)
--- ncurses-5.5-20051126+/ncurses/widechar/lib_ins_wch.c	2005-09-17 19:25:13.000000000 +0000
+++ ncurses-5.5-20051203/ncurses/widechar/lib_ins_wch.c	2005-12-03 20:24:19.000000000 +0000
@@ -117,7 +117,7 @@
 	    for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
 		int len = wcwidth(*cp);
 
-		if (len != 1) {
+		if (len != 1 || !is8bits(*cp)) {
 		    cchar_t tmp_cchar;
 		    wchar_t tmp_wchar = *cp;
 		    memset(&tmp_cchar, 0, sizeof(tmp_cchar));
