xref: /freebsd/contrib/ncurses/ncurses/base/lib_hline.c (revision aae38d10b4eebf81c0942947e8b83a9bb8651d88)
10e3d5408SPeter Wemm /****************************************************************************
2*aae38d10SBaptiste Daroussin  * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
30e3d5408SPeter Wemm  *                                                                          *
40e3d5408SPeter Wemm  * Permission is hereby granted, free of charge, to any person obtaining a  *
50e3d5408SPeter Wemm  * copy of this software and associated documentation files (the            *
60e3d5408SPeter Wemm  * "Software"), to deal in the Software without restriction, including      *
70e3d5408SPeter Wemm  * without limitation the rights to use, copy, modify, merge, publish,      *
80e3d5408SPeter Wemm  * distribute, distribute with modifications, sublicense, and/or sell       *
90e3d5408SPeter Wemm  * copies of the Software, and to permit persons to whom the Software is    *
100e3d5408SPeter Wemm  * furnished to do so, subject to the following conditions:                 *
110e3d5408SPeter Wemm  *                                                                          *
120e3d5408SPeter Wemm  * The above copyright notice and this permission notice shall be included  *
130e3d5408SPeter Wemm  * in all copies or substantial portions of the Software.                   *
140e3d5408SPeter Wemm  *                                                                          *
150e3d5408SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
160e3d5408SPeter Wemm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
170e3d5408SPeter Wemm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
180e3d5408SPeter Wemm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
190e3d5408SPeter Wemm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
200e3d5408SPeter Wemm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
210e3d5408SPeter Wemm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
220e3d5408SPeter Wemm  *                                                                          *
230e3d5408SPeter Wemm  * Except as contained in this notice, the name(s) of the above copyright   *
240e3d5408SPeter Wemm  * holders shall not be used in advertising or otherwise to promote the     *
250e3d5408SPeter Wemm  * sale, use or other dealings in this Software without prior written       *
260e3d5408SPeter Wemm  * authorization.                                                           *
270e3d5408SPeter Wemm  ****************************************************************************/
280e3d5408SPeter Wemm 
290e3d5408SPeter Wemm /****************************************************************************
300e3d5408SPeter Wemm  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
310e3d5408SPeter Wemm  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32*aae38d10SBaptiste Daroussin  *     and: Thomas E. Dickey                        1996-on                 *
33*aae38d10SBaptiste Daroussin  *     and: Sven Verdoolaege                        2001                    *
340e3d5408SPeter Wemm  ****************************************************************************/
350e3d5408SPeter Wemm 
360e3d5408SPeter Wemm /*
370e3d5408SPeter Wemm **	lib_hline.c
380e3d5408SPeter Wemm **
390e3d5408SPeter Wemm **	The routine whline().
400e3d5408SPeter Wemm **
410e3d5408SPeter Wemm */
420e3d5408SPeter Wemm 
430e3d5408SPeter Wemm #include <curses.priv.h>
440e3d5408SPeter Wemm 
45*aae38d10SBaptiste Daroussin MODULE_ID("$Id: lib_hline.c,v 1.15 2017/10/28 19:57:42 tom Exp $")
460e3d5408SPeter Wemm 
477a69bbfbSPeter Wemm NCURSES_EXPORT(int)
4815589c42SPeter Wemm whline(WINDOW *win, chtype ch, int n)
490e3d5408SPeter Wemm {
500e3d5408SPeter Wemm     int code = ERR;
510e3d5408SPeter Wemm 
5206bfebdeSXin LI     T((T_CALLED("whline(%p,%s,%d)"), (void *) win, _tracechtype(ch), n));
530e3d5408SPeter Wemm 
540e3d5408SPeter Wemm     if (win) {
550e3d5408SPeter Wemm 	struct ldat *line = &(win->_line[win->_cury]);
5639f2269fSPeter Wemm 	NCURSES_CH_T wch;
57*aae38d10SBaptiste Daroussin 	int start = win->_curx;
58*aae38d10SBaptiste Daroussin 	int end = start + n - 1;
590e3d5408SPeter Wemm 
600e3d5408SPeter Wemm 	if (end > win->_maxx)
610e3d5408SPeter Wemm 	    end = win->_maxx;
620e3d5408SPeter Wemm 
630e3d5408SPeter Wemm 	CHANGED_RANGE(line, start, end);
640e3d5408SPeter Wemm 
650e3d5408SPeter Wemm 	if (ch == 0)
664a1a9510SRong-En Fan 	    SetChar2(wch, ACS_HLINE);
6739f2269fSPeter Wemm 	else
684a1a9510SRong-En Fan 	    SetChar2(wch, ch);
6939f2269fSPeter Wemm 	wch = _nc_render(win, wch);
700e3d5408SPeter Wemm 
71*aae38d10SBaptiste Daroussin #if USE_WIDEC_SUPPORT
72*aae38d10SBaptiste Daroussin 	if (start > 0 && isWidecExt(line->text[start])) {
73*aae38d10SBaptiste Daroussin 	    SetChar2(line->text[start - 1], ' ');
74*aae38d10SBaptiste Daroussin 	}
75*aae38d10SBaptiste Daroussin 	if (end < win->_maxx && isWidecExt(line->text[end + 1])) {
76*aae38d10SBaptiste Daroussin 	    SetChar2(line->text[end + 1], ' ');
77*aae38d10SBaptiste Daroussin 	}
78*aae38d10SBaptiste Daroussin #endif
790e3d5408SPeter Wemm 	while (end >= start) {
8039f2269fSPeter Wemm 	    line->text[end] = wch;
810e3d5408SPeter Wemm 	    end--;
820e3d5408SPeter Wemm 	}
8318259542SPeter Wemm 
8418259542SPeter Wemm 	_nc_synchook(win);
850e3d5408SPeter Wemm 	code = OK;
860e3d5408SPeter Wemm     }
870e3d5408SPeter Wemm     returnCode(code);
880e3d5408SPeter Wemm }
89