xref: /minix3/lib/libcurses/in_wch.c (revision 51ffecc181005cb45a40108612ee28d1daaeeb86)
1*51ffecc1SBen Gras /*   $NetBSD: in_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */
2*51ffecc1SBen Gras 
3*51ffecc1SBen Gras /*
4*51ffecc1SBen Gras  * Copyright (c) 2005 The NetBSD Foundation Inc.
5*51ffecc1SBen Gras  * All rights reserved.
6*51ffecc1SBen Gras  *
7*51ffecc1SBen Gras  * This code is derived from code donated to the NetBSD Foundation
8*51ffecc1SBen Gras  * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
9*51ffecc1SBen Gras  *
10*51ffecc1SBen Gras  *
11*51ffecc1SBen Gras  * Redistribution and use in source and binary forms, with or without
12*51ffecc1SBen Gras  * modification, are permitted provided that the following conditions
13*51ffecc1SBen Gras  * are met:
14*51ffecc1SBen Gras  * 1. Redistributions of source code must retain the above copyright
15*51ffecc1SBen Gras  *	notice, this list of conditions and the following disclaimer.
16*51ffecc1SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
17*51ffecc1SBen Gras  *	notice, this list of conditions and the following disclaimer in the
18*51ffecc1SBen Gras  *	documentation and/or other materials provided with the distribution.
19*51ffecc1SBen Gras  * 3. Neither the name of the NetBSD Foundation nor the names of its
20*51ffecc1SBen Gras  *	contributors may be used to endorse or promote products derived
21*51ffecc1SBen Gras  *	from this software without specific prior written permission.
22*51ffecc1SBen Gras  *
23*51ffecc1SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
24*51ffecc1SBen Gras  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25*51ffecc1SBen Gras  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26*51ffecc1SBen Gras  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*51ffecc1SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28*51ffecc1SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29*51ffecc1SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30*51ffecc1SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31*51ffecc1SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32*51ffecc1SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33*51ffecc1SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34*51ffecc1SBen Gras  * SUCH DAMAGE.
35*51ffecc1SBen Gras  */
36*51ffecc1SBen Gras 
37*51ffecc1SBen Gras #include <sys/cdefs.h>
38*51ffecc1SBen Gras #ifndef lint
39*51ffecc1SBen Gras __RCSID("$NetBSD: in_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $");
40*51ffecc1SBen Gras #endif						  /* not lint */
41*51ffecc1SBen Gras 
42*51ffecc1SBen Gras #include "curses.h"
43*51ffecc1SBen Gras #include "curses_private.h"
44*51ffecc1SBen Gras 
45*51ffecc1SBen Gras /*
46*51ffecc1SBen Gras  * in_wch --
47*51ffecc1SBen Gras  *	Return wide character at cursor position from stdscr.
48*51ffecc1SBen Gras  */
49*51ffecc1SBen Gras int
in_wch(cchar_t * wcval)50*51ffecc1SBen Gras in_wch(cchar_t *wcval)
51*51ffecc1SBen Gras {
52*51ffecc1SBen Gras #ifndef HAVE_WCHAR
53*51ffecc1SBen Gras 	return ERR;
54*51ffecc1SBen Gras #else
55*51ffecc1SBen Gras 	return win_wch(stdscr, wcval);
56*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
57*51ffecc1SBen Gras }
58*51ffecc1SBen Gras 
59*51ffecc1SBen Gras /*
60*51ffecc1SBen Gras  * mvin_wch --
61*51ffecc1SBen Gras  *  Return wide character at position (y, x) from stdscr.
62*51ffecc1SBen Gras  */
63*51ffecc1SBen Gras int
mvin_wch(int y,int x,cchar_t * wcval)64*51ffecc1SBen Gras mvin_wch(int y, int x, cchar_t *wcval)
65*51ffecc1SBen Gras {
66*51ffecc1SBen Gras #ifndef HAVE_WCHAR
67*51ffecc1SBen Gras 	return ERR;
68*51ffecc1SBen Gras #else
69*51ffecc1SBen Gras 	return mvwin_wch(stdscr, y, x, wcval);
70*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
71*51ffecc1SBen Gras }
72*51ffecc1SBen Gras 
73*51ffecc1SBen Gras /*
74*51ffecc1SBen Gras  * mvwin_wch --
75*51ffecc1SBen Gras  *  Return wide character at position (y, x) from the given window.
76*51ffecc1SBen Gras  */
77*51ffecc1SBen Gras int
mvwin_wch(WINDOW * win,int y,int x,cchar_t * wcval)78*51ffecc1SBen Gras mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval)
79*51ffecc1SBen Gras {
80*51ffecc1SBen Gras #ifndef HAVE_WCHAR
81*51ffecc1SBen Gras 	return ERR;
82*51ffecc1SBen Gras #else
83*51ffecc1SBen Gras 	if (wmove(win, y, x) == ERR)
84*51ffecc1SBen Gras 		return ERR;
85*51ffecc1SBen Gras 
86*51ffecc1SBen Gras 	return win_wch(win, wcval);
87*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
88*51ffecc1SBen Gras }
89*51ffecc1SBen Gras 
90*51ffecc1SBen Gras /*
91*51ffecc1SBen Gras  * win_wch --
92*51ffecc1SBen Gras  *	Return wide character at cursor position.
93*51ffecc1SBen Gras  */
94*51ffecc1SBen Gras int
win_wch(WINDOW * win,cchar_t * wcval)95*51ffecc1SBen Gras win_wch(WINDOW *win, cchar_t *wcval)
96*51ffecc1SBen Gras {
97*51ffecc1SBen Gras #ifndef HAVE_WCHAR
98*51ffecc1SBen Gras 	return ERR;
99*51ffecc1SBen Gras #else
100*51ffecc1SBen Gras 	nschar_t *np;
101*51ffecc1SBen Gras 	__LDATA *lp = &win->alines[ win->cury ]->line[ win->curx ];
102*51ffecc1SBen Gras 	int cw = WCOL( *lp );
103*51ffecc1SBen Gras 
104*51ffecc1SBen Gras 	if ( cw < 0 )
105*51ffecc1SBen Gras 		lp += cw;
106*51ffecc1SBen Gras 	wcval->vals[ 0 ] = lp->ch;
107*51ffecc1SBen Gras 	wcval->attributes = lp->attr;
108*51ffecc1SBen Gras 	wcval->elements = 1;
109*51ffecc1SBen Gras 	np = lp->nsp;
110*51ffecc1SBen Gras 	if (np) {
111*51ffecc1SBen Gras 		do {
112*51ffecc1SBen Gras 			wcval->vals[ wcval->elements++ ] = np->ch;
113*51ffecc1SBen Gras 			np = np-> next;
114*51ffecc1SBen Gras 		} while ( np );
115*51ffecc1SBen Gras 	}
116*51ffecc1SBen Gras 
117*51ffecc1SBen Gras 	return OK;
118*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
119*51ffecc1SBen Gras }
120