| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: addbytes.c,v 1.36 2010/02/23 19:48:26 drochner Exp $ */ | | 1 | /* $NetBSD: addbytes.c,v 1.37 2010/11/23 05:38:35 tnozaki Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1987, 1993, 1994 | | 4 | * Copyright (c) 1987, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -24,31 +24,32 @@ | | | @@ -24,31 +24,32 @@ |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | #if 0 | | 34 | #if 0 |
35 | static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94"; | | 35 | static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94"; |
36 | #else | | 36 | #else |
37 | __RCSID("$NetBSD: addbytes.c,v 1.36 2010/02/23 19:48:26 drochner Exp $"); | | 37 | __RCSID("$NetBSD: addbytes.c,v 1.37 2010/11/23 05:38:35 tnozaki Exp $"); |
38 | #endif | | 38 | #endif |
39 | #endif /* not lint */ | | 39 | #endif /* not lint */ |
40 | | | 40 | |
41 | #include <stdlib.h> | | 41 | #include <stdlib.h> |
| | | 42 | #include <string.h> |
42 | #include "curses.h" | | 43 | #include "curses.h" |
43 | #include "curses_private.h" | | 44 | #include "curses_private.h" |
44 | #ifdef DEBUG | | 45 | #ifdef DEBUG |
45 | #include <assert.h> | | 46 | #include <assert.h> |
46 | #endif | | 47 | #endif |
47 | | | 48 | |
48 | #define SYNCH_IN {y = win->cury; x = win->curx;} | | 49 | #define SYNCH_IN {y = win->cury; x = win->curx;} |
49 | #define SYNCH_OUT {win->cury = y; win->curx = x;} | | 50 | #define SYNCH_OUT {win->cury = y; win->curx = x;} |
50 | #define PSYNCH_IN {*y = win->cury; *x = win->curx;} | | 51 | #define PSYNCH_IN {*y = win->cury; *x = win->curx;} |
51 | #define PSYNCH_OUT {win->cury = *y; win->curx = *x;} | | 52 | #define PSYNCH_OUT {win->cury = *y; win->curx = *x;} |
52 | | | 53 | |
53 | #ifndef _CURSES_USE_MACROS | | 54 | #ifndef _CURSES_USE_MACROS |
54 | | | 55 | |
| @@ -119,54 +120,54 @@ __waddbytes(WINDOW *win, const char *byt | | | @@ -119,54 +120,54 @@ __waddbytes(WINDOW *win, const char *byt |
119 | | | 120 | |
120 | for (i = 0; i < win->maxy; i++) { | | 121 | for (i = 0; i < win->maxy; i++) { |
121 | assert(win->alines[i]->sentinel == SENTINEL_VALUE); | | 122 | assert(win->alines[i]->sentinel == SENTINEL_VALUE); |
122 | } | | 123 | } |
123 | | | 124 | |
124 | __CTRACE(__CTRACE_INPUT, "ADDBYTES: add %d bytes\n", count); | | 125 | __CTRACE(__CTRACE_INPUT, "ADDBYTES: add %d bytes\n", count); |
125 | #endif | | 126 | #endif |
126 | | | 127 | |
127 | err = OK; | | 128 | err = OK; |
128 | SYNCH_IN; | | 129 | SYNCH_IN; |
129 | lp = win->alines[y]; | | 130 | lp = win->alines[y]; |
130 | | | 131 | |
131 | #ifdef HAVE_WCHAR | | 132 | #ifdef HAVE_WCHAR |
132 | (void)mbrtowc(NULL, NULL, (size_t)0, &st); | | 133 | (void)memset(&st, 0, sizeof(st)); |
133 | #endif | | 134 | #endif |
134 | while (count > 0) { | | 135 | while (count > 0) { |
135 | #ifndef HAVE_WCHAR | | 136 | #ifndef HAVE_WCHAR |
136 | c = *bytes++; | | 137 | c = *bytes++; |
137 | #ifdef DEBUG | | 138 | #ifdef DEBUG |
138 | __CTRACE(__CTRACE_INPUT, "ADDBYTES('%c', %x) at (%d, %d)\n", | | 139 | __CTRACE(__CTRACE_INPUT, "ADDBYTES('%c', %x) at (%d, %d)\n", |
139 | c, attr, y, x); | | 140 | c, attr, y, x); |
140 | #endif | | 141 | #endif |
141 | err = _cursesi_addbyte(win, &lp, &y, &x, c, attr); | | 142 | err = _cursesi_addbyte(win, &lp, &y, &x, c, attr); |
142 | count--; | | 143 | count--; |
143 | #else | | 144 | #else |
144 | /* | | 145 | /* |
145 | * For wide character support only, try and convert the | | 146 | * For wide character support only, try and convert the |
146 | * given string into a wide character - we do this because | | 147 | * given string into a wide character - we do this because |
147 | * this is how ncurses behaves (not that I think this is | | 148 | * this is how ncurses behaves (not that I think this is |
148 | * actually the correct thing to do but if we don't do it | | 149 | * actually the correct thing to do but if we don't do it |
149 | * a lot of things that rely on this behaviour will break | | 150 | * a lot of things that rely on this behaviour will break |
150 | * and we will be blamed). If the conversion succeeds | | 151 | * and we will be blamed). If the conversion succeeds |
151 | * then we eat the n characters used to make the wide char | | 152 | * then we eat the n characters used to make the wide char |
152 | * from the string. | | 153 | * from the string. |
153 | */ | | 154 | */ |
154 | n = (int)mbrtowc(&wc, bytes, (size_t)count, &st); | | 155 | n = (int)mbrtowc(&wc, bytes, (size_t)count, &st); |
155 | if (n < 0) { | | 156 | if (n < 0) { |
156 | /* not a valid conversion just eat a char */ | | 157 | /* not a valid conversion just eat a char */ |
157 | wc = *bytes; | | 158 | wc = *bytes; |
158 | n = 1; | | 159 | n = 1; |
159 | (void)mbrtowc(NULL, NULL, (size_t)0, &st); | | 160 | (void)memset(&st, 0, sizeof(&st)); |
160 | } else if (wc == 0) { | | 161 | } else if (wc == 0) { |
161 | break; | | 162 | break; |
162 | } | | 163 | } |
163 | #ifdef DEBUG | | 164 | #ifdef DEBUG |
164 | __CTRACE(__CTRACE_INPUT, | | 165 | __CTRACE(__CTRACE_INPUT, |
165 | "ADDBYTES WIDE(0x%x [%s], %x) at (%d, %d), ate %d bytes\n", | | 166 | "ADDBYTES WIDE(0x%x [%s], %x) at (%d, %d), ate %d bytes\n", |
166 | (unsigned) wc, unctrl((unsigned) wc), attr, y, x, n); | | 167 | (unsigned) wc, unctrl((unsigned) wc), attr, y, x, n); |
167 | #endif | | 168 | #endif |
168 | cc.vals[0] = wc; | | 169 | cc.vals[0] = wc; |
169 | cc.elements = 1; | | 170 | cc.elements = 1; |
170 | cc.attributes = attr; | | 171 | cc.attributes = attr; |
171 | err = _cursesi_addwchar(win, &lp, &y, &x, &cc); | | 172 | err = _cursesi_addwchar(win, &lp, &y, &x, &cc); |
172 | bytes += n; | | 173 | bytes += n; |