X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_inchstr.c;h=bf30e3ce26637651c897e545023a09435ba47fd9;hp=4779ae09d75bc5a0abb09490dd41b30d0ff47909;hb=e33150410925e7858dacebb585a9bd90db683d86;hpb=0eb88fc5281804773e2a0c7a488a4452463535ce diff --git a/ncurses/base/lib_inchstr.c b/ncurses/base/lib_inchstr.c index 4779ae09..bf30e3ce 100644 --- a/ncurses/base/lib_inchstr.c +++ b/ncurses/base/lib_inchstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2010,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,9 +29,9 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ - /* ** lib_inchstr.c ** @@ -41,22 +41,28 @@ #include -MODULE_ID("$Id: lib_inchstr.c,v 1.7 1998/02/11 12:13:55 tom Exp $") +MODULE_ID("$Id: lib_inchstr.c,v 1.16 2017/04/30 00:10:25 tom Exp $") -int winchnstr(WINDOW *win, chtype *str, int n) +NCURSES_EXPORT(int) +winchnstr(WINDOW *win, chtype *str, int n) { - int i = 0; + int i = 0; - T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n)); + T((T_CALLED("winchnstr(%p,%p,%d)"), (void *) win, (void *) str, n)); - if (!str) - returnCode(0); + if (!win || !str) { + i = ERR; + } else { + int row = win->_cury; + int col = win->_curx; + NCURSES_CH_T *text = win->_line[row].text; - if (win) { - for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) - str[i] = win->_line[win->_cury].text[win->_curx + i]; + for (; (n < 0 || (i < n)) && (col + i <= win->_maxx); i++) { + str[i] = (((chtype) CharOf(text[col + i]) & A_CHARTEXT) | + AttrOf(text[col + i])); } - str[i] = (chtype)0; + str[i] = (chtype) 0; + } - returnCode(i); + returnCode(i); }