1/****************************************************************************
2 * Copyright (c) 2004 Free Software Foundation, Inc.                        *
3 *                                                                          *
4 * Permission is hereby granted, free of charge, to any person obtaining a  *
5 * copy of this software and associated documentation files (the            *
6 * "Software"), to deal in the Software without restriction, including      *
7 * without limitation the rights to use, copy, modify, merge, publish,      *
8 * distribute, distribute with modifications, sublicense, and/or sell       *
9 * copies of the Software, and to permit persons to whom the Software is    *
10 * furnished to do so, subject to the following conditions:                 *
11 *                                                                          *
12 * The above copyright notice and this permission notice shall be included  *
13 * in all copies or substantial portions of the Software.                   *
14 *                                                                          *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 *                                                                          *
23 * Except as contained in this notice, the name(s) of the above copyright   *
24 * holders shall not be used in advertising or otherwise to promote the     *
25 * sale, use or other dealings in this Software without prior written       *
26 * authorization.                                                           *
27 ****************************************************************************/
28
29/*
30**	lib_add_wch.c
31**
32**	The routine wadd_wch().
33**
34*/
35
36#include <curses.priv.h>
37
38MODULE_ID("$Id: lib_add_wch.c,v 1.4 2004/09/19 00:33:51 tom Exp $")
39
40NCURSES_EXPORT(int)
41wadd_wch(WINDOW *win, const cchar_t * wch)
42{
43    PUTC_DATA;
44    int n;
45    int code = ERR;
46
47    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win,
48				      _tracech_t(wch)));
49
50    if (win != 0) {
51	PUTC_INIT;
52	while (PUTC_i < CCHARW_MAX) {
53	    if ((PUTC_ch = wch->chars[PUTC_i++]) == L'\0')
54		break;
55	    if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
56		code = ERR;
57		if (is8bits(PUTC_ch))
58		    code = waddch(win, UChar(PUTC_ch) | wch->attr);
59		break;
60	    }
61	    for (n = 0; n < PUTC_n; n++) {
62		if ((code = waddch(win, UChar(PUTC_buf[n]) | wch->attr)) == ERR) {
63		    break;
64		}
65	    }
66	    if (code == ERR)
67		break;
68	}
69    }
70
71    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
72    return (code);
73}
74
75NCURSES_EXPORT(int)
76wecho_wchar(WINDOW *win, const cchar_t * wch)
77{
78    PUTC_DATA;
79    int n;
80    int code = ERR;
81
82    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win,
83				      _tracech_t(wch)));
84
85    if (win != 0) {
86	PUTC_INIT;
87	while (PUTC_i < CCHARW_MAX) {
88	    if ((PUTC_ch = wch->chars[PUTC_i++]) == L'\0')
89		break;
90	    if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
91		code = ERR;
92		if (is8bits(PUTC_ch))
93		    code = waddch(win, UChar(PUTC_ch) | wch->attr);
94		break;
95	    }
96	    for (n = 0; n < PUTC_n; n++) {
97		if ((code = waddch(win, UChar(PUTC_buf[n]) | wch->attr)) == ERR) {
98		    break;
99		}
100	    }
101	    if (code == ERR)
102		break;
103	}
104	wrefresh(win);
105    }
106
107    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
108    return (code);
109}
110