Module Name: src Committed By: christos Date: Fri Jan 6 22:20:54 UTC 2012
Modified Files: src/lib/libcurses: getstr.c Log Message: PR/45791: Nat Sloss: getnstr erase character weirdness Fix processing of backspace erase char and char left. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libcurses/getstr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libcurses/getstr.c diff -u src/lib/libcurses/getstr.c:1.20 src/lib/libcurses/getstr.c:1.21 --- src/lib/libcurses/getstr.c:1.20 Mon May 28 11:01:55 2007 +++ src/lib/libcurses/getstr.c Fri Jan 6 17:20:54 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: getstr.c,v 1.20 2007/05/28 15:01:55 blymn Exp $ */ +/* $NetBSD: getstr.c,v 1.21 2012/01/06 22:20:54 christos Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -35,10 +35,11 @@ #if 0 static char sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: getstr.c,v 1.20 2007/05/28 15:01:55 blymn Exp $"); +__RCSID("$NetBSD: getstr.c,v 1.21 2012/01/06 22:20:54 christos Exp $"); #endif #endif /* not lint */ +#include <ctype.h> #include "curses.h" #include "curses_private.h" @@ -161,12 +162,12 @@ int __wgetnstr(WINDOW *win, char *str, int n) { char *ostr, ec, kc; - int c, oldx, remain; + int c, xpos, oldx, remain; ostr = str; ec = erasechar(); kc = killchar(); - oldx = win->curx; + xpos = oldx = win->curx; _DIAGASSERT(n == -1 || n > 1); remain = n - 1; @@ -182,17 +183,23 @@ __wgetnstr(WINDOW *win, char *str, int n *str = '\0'; if (str != ostr) { if ((char) c == ec) { - mvwaddch(win, win->cury, win->curx, - ' '); - wmove(win, win->cury, win->curx - 1); + mvwaddch(win, win->cury, xpos, ' '); + if (xpos > oldx) + mvwaddch(win, win->cury, + xpos - 1, ' '); + if (win->curx > xpos - 1) + wmove(win, win->cury, xpos - 1); + xpos--; } if (c == KEY_BACKSPACE || c == KEY_LEFT) { /* getch() displays the key sequence */ - mvwaddch(win, win->cury, win->curx - 1, + mvwaddch(win, win->cury, win->curx, ' '); - mvwaddch(win, win->cury, win->curx - 2, + mvwaddch(win, win->cury, win->curx - 1, ' '); - wmove(win, win->cury, win->curx - 1); + if (win->curx > xpos) + wmove(win, win->cury, xpos - 1); + xpos--; } str--; if (n != -1) { @@ -200,11 +207,12 @@ __wgetnstr(WINDOW *win, char *str, int n remain++; } } else { /* str == ostr */ - if (c == KEY_BACKSPACE || c == KEY_LEFT) - /* getch() displays the other keys */ + /* getch() displays the other keys */ + if (win->curx > oldx) mvwaddch(win, win->cury, win->curx - 1, ' '); wmove(win, win->cury, oldx); + xpos = oldx; } } else if (c == kc) { *str = '\0'; @@ -229,15 +237,20 @@ __wgetnstr(WINDOW *win, char *str, int n wmove(win, win->cury, oldx); } else if (c >= KEY_MIN && c <= KEY_MAX) { /* getch() displays these characters */ - mvwaddch(win, win->cury, win->curx - 1, ' '); - wmove(win, win->cury, win->curx - 1); + mvwaddch(win, win->cury, xpos, ' '); + wmove(win, win->cury, xpos); } else { if (remain) { + if (iscntrl((unsigned char)c)) { + mvwaddch(win, win->cury, xpos, ' '); + wmove(win, win->cury, xpos + 1); + } str++; + xpos++; remain--; } else { - mvwaddch(win, win->cury, win->curx - 1, ' '); - wmove(win, win->cury, win->curx - 1); + mvwaddch(win, win->cury, xpos, ' '); + wmove(win, win->cury, xpos - 1); } } }