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