xref: /minix3/lib/libcurses/add_wch.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*   $NetBSD: add_wch.c,v 1.4 2013/11/09 11:16:59 blymn Exp $ */
251ffecc1SBen Gras 
351ffecc1SBen Gras /*
451ffecc1SBen Gras  * Copyright (c) 2005 The NetBSD Foundation Inc.
551ffecc1SBen Gras  * All rights reserved.
651ffecc1SBen Gras  *
751ffecc1SBen Gras  * This code is derived from code donated to the NetBSD Foundation
851ffecc1SBen Gras  * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
951ffecc1SBen Gras  *
1051ffecc1SBen Gras  *
1151ffecc1SBen Gras  * Redistribution and use in source and binary forms, with or without
1251ffecc1SBen Gras  * modification, are permitted provided that the following conditions
1351ffecc1SBen Gras  * are met:
1451ffecc1SBen Gras  * 1. Redistributions of source code must retain the above copyright
1551ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer.
1651ffecc1SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
1751ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer in the
1851ffecc1SBen Gras  *    documentation and/or other materials provided with the distribution.
1951ffecc1SBen Gras  * 3. Neither the name of the NetBSD Foundation nor the names of its
2051ffecc1SBen Gras  *    contributors may be used to endorse or promote products derived
2151ffecc1SBen Gras  *    from this software without specific prior written permission.
2251ffecc1SBen Gras  *
2351ffecc1SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
2451ffecc1SBen Gras  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
2551ffecc1SBen Gras  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2651ffecc1SBen Gras  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2751ffecc1SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2851ffecc1SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2951ffecc1SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3051ffecc1SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3151ffecc1SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3251ffecc1SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3351ffecc1SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3451ffecc1SBen Gras  * SUCH DAMAGE.
3551ffecc1SBen Gras  */
3651ffecc1SBen Gras 
3751ffecc1SBen Gras #include <sys/cdefs.h>
3851ffecc1SBen Gras #ifndef lint
39*84d9c625SLionel Sambuc __RCSID("$NetBSD: add_wch.c,v 1.4 2013/11/09 11:16:59 blymn Exp $");
4051ffecc1SBen Gras #endif /* not lint */
4151ffecc1SBen Gras 
4251ffecc1SBen Gras #include <stdlib.h>
4351ffecc1SBen Gras #include "curses.h"
4451ffecc1SBen Gras #include "curses_private.h"
4551ffecc1SBen Gras #ifdef DEBUG
4651ffecc1SBen Gras #include <assert.h>
4751ffecc1SBen Gras #endif
4851ffecc1SBen Gras 
4951ffecc1SBen Gras /*
5051ffecc1SBen Gras  * add_wch --
5151ffecc1SBen Gras  *	Add the wide character to the current position in stdscr.
5251ffecc1SBen Gras  *
5351ffecc1SBen Gras  */
5451ffecc1SBen Gras int
add_wch(const cchar_t * wch)5551ffecc1SBen Gras add_wch(const cchar_t *wch)
5651ffecc1SBen Gras {
5751ffecc1SBen Gras #ifndef HAVE_WCHAR
5851ffecc1SBen Gras 	return ERR;
5951ffecc1SBen Gras #else
6051ffecc1SBen Gras 	return wadd_wch(stdscr, wch);
6151ffecc1SBen Gras #endif /* HAVE_WCHAR */
6251ffecc1SBen Gras }
6351ffecc1SBen Gras 
6451ffecc1SBen Gras 
6551ffecc1SBen Gras /*
6651ffecc1SBen Gras  * mvadd_wch --
6751ffecc1SBen Gras  *      Add the wide character to stdscr at the given location.
6851ffecc1SBen Gras  */
6951ffecc1SBen Gras int
mvadd_wch(int y,int x,const cchar_t * wch)7051ffecc1SBen Gras mvadd_wch(int y, int x, const cchar_t *wch)
7151ffecc1SBen Gras {
7251ffecc1SBen Gras #ifndef HAVE_WCHAR
7351ffecc1SBen Gras 	return ERR;
7451ffecc1SBen Gras #else
7551ffecc1SBen Gras 	return mvwadd_wch(stdscr, y, x, wch);
7651ffecc1SBen Gras #endif /* HAVE_WCHAR */
7751ffecc1SBen Gras }
7851ffecc1SBen Gras 
7951ffecc1SBen Gras 
8051ffecc1SBen Gras /*
8151ffecc1SBen Gras  * mvwadd_wch --
8251ffecc1SBen Gras  *      Add the character to the given window at the given location.
8351ffecc1SBen Gras  */
8451ffecc1SBen Gras int
mvwadd_wch(WINDOW * win,int y,int x,const cchar_t * wch)8551ffecc1SBen Gras mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch)
8651ffecc1SBen Gras {
8751ffecc1SBen Gras #ifndef HAVE_WCHAR
8851ffecc1SBen Gras 	return ERR;
8951ffecc1SBen Gras #else
9051ffecc1SBen Gras 	if (wmove(win, y, x) == ERR)
9151ffecc1SBen Gras 		return ERR;
9251ffecc1SBen Gras 
9351ffecc1SBen Gras 	return wadd_wch(win, wch);
9451ffecc1SBen Gras #endif /* HAVE_WCHAR */
9551ffecc1SBen Gras }
9651ffecc1SBen Gras 
9751ffecc1SBen Gras 
9851ffecc1SBen Gras /*
9951ffecc1SBen Gras  * wadd_wch --
10051ffecc1SBen Gras  *	Add the wide character to the current position in the
10151ffecc1SBen Gras  *	given window.
10251ffecc1SBen Gras  *
10351ffecc1SBen Gras  */
10451ffecc1SBen Gras int
wadd_wch(WINDOW * win,const cchar_t * wch)10551ffecc1SBen Gras wadd_wch(WINDOW *win, const cchar_t *wch)
10651ffecc1SBen Gras {
10751ffecc1SBen Gras #ifndef HAVE_WCHAR
10851ffecc1SBen Gras 	return ERR;
10951ffecc1SBen Gras #else
11051ffecc1SBen Gras 	int x = win->curx, y = win->cury;
11151ffecc1SBen Gras 	__LINE *lnp = NULL;
11251ffecc1SBen Gras 
11351ffecc1SBen Gras #ifdef DEBUG
11451ffecc1SBen Gras 	int i;
11551ffecc1SBen Gras 
11651ffecc1SBen Gras 	for (i = 0; i < win->maxy; i++) {
11751ffecc1SBen Gras 		assert(win->alines[i]->sentinel == SENTINEL_VALUE);
11851ffecc1SBen Gras 	}
11951ffecc1SBen Gras 	__CTRACE(__CTRACE_INPUT, "wadd_wch: win(%p)", win);
12051ffecc1SBen Gras #endif
12151ffecc1SBen Gras 	lnp = win->alines[y];
122*84d9c625SLionel Sambuc 	return _cursesi_addwchar(win, &lnp, &y, &x, wch, 1);
12351ffecc1SBen Gras #endif /* HAVE_WCHAR */
12451ffecc1SBen Gras }
125