Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses Truncate string to RHS of the window - SUSv2 s...



details:   https://anonhg.NetBSD.org/src/rev/9570eefdaa49
branches:  trunk
changeset: 781760:9570eefdaa49
user:      blymn <blymn%NetBSD.org@localhost>
date:      Fri Sep 28 06:00:39 2012 +0000

description:
Truncate string to RHS of the window - SUSv2 says we should.

diffstat:

 lib/libcurses/addchnstr.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r c4f846b17451 -r 9570eefdaa49 lib/libcurses/addchnstr.c
--- a/lib/libcurses/addchnstr.c Thu Sep 27 23:10:00 2012 +0000
+++ b/lib/libcurses/addchnstr.c Fri Sep 28 06:00:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $     */
+/*     $NetBSD: addchnstr.c,v 1.5 2012/09/28 06:00:39 blymn Exp $      */
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $");
+__RCSID("$NetBSD: addchnstr.c,v 1.5 2012/09/28 06:00:39 blymn Exp $");
 #endif                         /* not lint */
 
 #include <stdlib.h>
@@ -122,8 +122,11 @@
 /*
  * waddchnstr --
  *     Add a string (at most n characters) to the given window
- *     starting at (_cury, _curx).  If n is negative, add the
- *     entire string.
+ *     starting at (_cury, _curx) until the end of line is reached or
+ *      n characters have been added.  If n is negative, add as much
+ *     of the string that will fit on the current line.  SUSv2 says
+ *      that the addchnstr family does not wrap and strings are truncated
+ *      to the RHS of the window.
  */
 int
 waddchnstr(WINDOW *win, const chtype *chstr, int n)
@@ -144,6 +147,10 @@
        else
                for (chp = chstr, len = 0; *chp++; ++len);
 
+       /* check if string is too long for current location */
+       if (len > (win->maxx - win->curx))
+               len = win->maxx - win->curx;
+
        if ((ocp = malloc(len + 1)) == NULL)
                return ERR;
        chp = chstr;



Home | Main Index | Thread Index | Old Index