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