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