Pull up following revision(s) (requested by uwe in ticket #986): lib/libcurses/insch.c: revision 1.26 lib/libcurses/ins_wch.c: revision 1.15 lib/libcurses/ins_wstr.c: revision 1.15 lib/libcurses/insstr.c: revision 1.8 mvwins*(WINDOW *win, ...) functions - call wins* on win, not stdscr. >From Naman Jain in PR lib/55460.diff -r1.14 -r1.14.2.1 src/lib/libcurses/ins_wch.c
(martin)
--- src/lib/libcurses/ins_wch.c 2019/06/09 07:40:14 1.14
+++ src/lib/libcurses/ins_wch.c 2020/07/07 12:43:51 1.14.2.1
@@ -1,237 +1,237 @@ | @@ -1,237 +1,237 @@ | |||
1 | /* $NetBSD: ins_wch.c,v 1.14 2019/06/09 07:40:14 blymn Exp $ */ | 1 | /* $NetBSD: ins_wch.c,v 1.14.2.1 2020/07/07 12:43:51 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | 4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from code donated to the NetBSD Foundation | 7 | * This code is derived from code donated to the NetBSD Foundation | |
8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | 8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | |
9 | * | 9 | * | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | 15 | * notice, this list of conditions and the following disclaimer. | |
16 | * 2. Redistributions in binary form must reproduce the above copyright | 16 | * 2. Redistributions in binary form must reproduce the above copyright | |
17 | * notice, this list of conditions and the following disclaimer in the | 17 | * notice, this list of conditions and the following disclaimer in the | |
18 | * documentation and/or other materials provided with the distribution. | 18 | * documentation and/or other materials provided with the distribution. | |
19 | * 3. Neither the name of the NetBSD Foundation nor the names of its | 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 | 20 | * contributors may be used to endorse or promote products derived | |
21 | * from this software without specific prior written permission. | 21 | * from this software without specific prior written permission. | |
22 | * | 22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | 23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | |
24 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | 24 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
25 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 25 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | 34 | * SUCH DAMAGE. | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | #ifndef lint | 38 | #ifndef lint | |
39 | __RCSID("$NetBSD: ins_wch.c,v 1.14 2019/06/09 07:40:14 blymn Exp $"); | 39 | __RCSID("$NetBSD: ins_wch.c,v 1.14.2.1 2020/07/07 12:43:51 martin Exp $"); | |
40 | #endif /* not lint */ | 40 | #endif /* not lint */ | |
41 | 41 | |||
42 | #include <string.h> | 42 | #include <string.h> | |
43 | #include <stdlib.h> | 43 | #include <stdlib.h> | |
44 | 44 | |||
45 | #include "curses.h" | 45 | #include "curses.h" | |
46 | #include "curses_private.h" | 46 | #include "curses_private.h" | |
47 | 47 | |||
48 | /* | 48 | /* | |
49 | * ins_wch -- | 49 | * ins_wch -- | |
50 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | 50 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | |
51 | */ | 51 | */ | |
52 | int | 52 | int | |
53 | ins_wch(const cchar_t *wch) | 53 | ins_wch(const cchar_t *wch) | |
54 | { | 54 | { | |
55 | return wins_wch(stdscr, wch); | 55 | return wins_wch(stdscr, wch); | |
56 | } | 56 | } | |
57 | 57 | |||
58 | /* | 58 | /* | |
59 | * mvins_wch -- | 59 | * mvins_wch -- | |
60 | * Do an insert-char on the line at (y, x). | 60 | * Do an insert-char on the line at (y, x). | |
61 | */ | 61 | */ | |
62 | int | 62 | int | |
63 | mvins_wch(int y, int x, const cchar_t *wch) | 63 | mvins_wch(int y, int x, const cchar_t *wch) | |
64 | { | 64 | { | |
65 | return mvwins_wch(stdscr, y, x, wch); | 65 | return mvwins_wch(stdscr, y, x, wch); | |
66 | } | 66 | } | |
67 | 67 | |||
68 | /* | 68 | /* | |
69 | * mvwins_wch -- | 69 | * mvwins_wch -- | |
70 | * Do an insert-char on the line at (y, x) in the given window. | 70 | * Do an insert-char on the line at (y, x) in the given window. | |
71 | */ | 71 | */ | |
72 | int | 72 | int | |
73 | mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) | 73 | mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) | |
74 | { | 74 | { | |
75 | if (wmove(win, y, x) == ERR) | 75 | if (wmove(win, y, x) == ERR) | |
76 | return ERR; | 76 | return ERR; | |
77 | 77 | |||
78 | return wins_wch(stdscr, wch); | 78 | return wins_wch(win, wch); | |
79 | } | 79 | } | |
80 | 80 | |||
81 | /* | 81 | /* | |
82 | * wins_wch -- | 82 | * wins_wch -- | |
83 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | 83 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | |
84 | */ | 84 | */ | |
85 | int | 85 | int | |
86 | wins_wch(WINDOW *win, const cchar_t *wch) | 86 | wins_wch(WINDOW *win, const cchar_t *wch) | |
87 | { | 87 | { | |
88 | __LDATA *start, *temp1, *temp2; | 88 | __LDATA *start, *temp1, *temp2; | |
89 | __LINE *lnp; | 89 | __LINE *lnp; | |
90 | int cw, pcw, x, y, sx, ex, newx, i; | 90 | int cw, pcw, x, y, sx, ex, newx, i; | |
91 | nschar_t *np, *tnp; | 91 | nschar_t *np, *tnp; | |
92 | wchar_t ws[] = L" "; | 92 | wchar_t ws[] = L" "; | |
93 | 93 | |||
94 | /* check for non-spacing characters */ | 94 | /* check for non-spacing characters */ | |
95 | if (!wch) | 95 | if (!wch) | |
96 | return OK; | 96 | return OK; | |
97 | cw = wcwidth(wch->vals[0]); | 97 | cw = wcwidth(wch->vals[0]); | |
98 | if (cw < 0) | 98 | if (cw < 0) | |
99 | cw = 1; | 99 | cw = 1; | |
100 | if (!cw) | 100 | if (!cw) | |
101 | return wadd_wch( win, wch ); | 101 | return wadd_wch( win, wch ); | |
102 | 102 | |||
103 | #ifdef DEBUG | 103 | #ifdef DEBUG | |
104 | __CTRACE(__CTRACE_INPUT, "--before--\n"); | 104 | __CTRACE(__CTRACE_INPUT, "--before--\n"); | |
105 | for (x = 0; x < win->maxx; x++) | 105 | for (x = 0; x < win->maxx; x++) | |
106 | __CTRACE(__CTRACE_INPUT, "wins_wch: (0,%d)=(%x,%x,%p)\n", x, | 106 | __CTRACE(__CTRACE_INPUT, "wins_wch: (0,%d)=(%x,%x,%p)\n", x, | |
107 | win->alines[0]->line[x].ch, | 107 | win->alines[0]->line[x].ch, | |
108 | win->alines[0]->line[x].attr, | 108 | win->alines[0]->line[x].attr, | |
109 | win->alines[0]->line[x].nsp); | 109 | win->alines[0]->line[x].nsp); | |
110 | #endif /* DEBUG */ | 110 | #endif /* DEBUG */ | |
111 | x = win->curx; | 111 | x = win->curx; | |
112 | y = win->cury; | 112 | y = win->cury; | |
113 | #ifdef DEBUG | 113 | #ifdef DEBUG | |
114 | __CTRACE(__CTRACE_INPUT, "wins_wch: (%d,%d)\n", y, x); | 114 | __CTRACE(__CTRACE_INPUT, "wins_wch: (%d,%d)\n", y, x); | |
115 | #endif /* DEBUG */ | 115 | #endif /* DEBUG */ | |
116 | switch (wch->vals[0]) { | 116 | switch (wch->vals[0]) { | |
117 | case L'\b': | 117 | case L'\b': | |
118 | if (--x < 0) | 118 | if (--x < 0) | |
119 | x = 0; | 119 | x = 0; | |
120 | win->curx = x; | 120 | win->curx = x; | |
121 | return OK; | 121 | return OK; | |
122 | case L'\r': | 122 | case L'\r': | |
123 | win->curx = 0; | 123 | win->curx = 0; | |
124 | return OK; | 124 | return OK; | |
125 | case L'\n': | 125 | case L'\n': | |
126 | wclrtoeol(win); | 126 | wclrtoeol(win); | |
127 | if (y == win->scr_b) { | 127 | if (y == win->scr_b) { | |
128 | if (!(win->flags & __SCROLLOK)) | 128 | if (!(win->flags & __SCROLLOK)) | |
129 | return ERR; | 129 | return ERR; | |
130 | scroll(win); | 130 | scroll(win); | |
131 | } | 131 | } | |
132 | return OK; | 132 | return OK; | |
133 | case L'\t': | 133 | case L'\t': | |
134 | if (wins_nwstr(win, ws, min(win->maxx - x, | 134 | if (wins_nwstr(win, ws, min(win->maxx - x, | |
135 | TABSIZE - (x % TABSIZE))) == ERR) | 135 | TABSIZE - (x % TABSIZE))) == ERR) | |
136 | return ERR; | 136 | return ERR; | |
137 | return OK; | 137 | return OK; | |
138 | } | 138 | } | |
139 | 139 | |||
140 | /* locate current cell */ | 140 | /* locate current cell */ | |
141 | x = win->curx; | 141 | x = win->curx; | |
142 | y = win->cury; | 142 | y = win->cury; | |
143 | lnp = win->alines[y]; | 143 | lnp = win->alines[y]; | |
144 | start = &win->alines[y]->line[x]; | 144 | start = &win->alines[y]->line[x]; | |
145 | sx = x; | 145 | sx = x; | |
146 | pcw = WCOL(*start); | 146 | pcw = WCOL(*start); | |
147 | if (pcw < 0) { | 147 | if (pcw < 0) { | |
148 | start += pcw; | 148 | start += pcw; | |
149 | sx += pcw; | 149 | sx += pcw; | |
150 | } | 150 | } | |
151 | if (cw > win->maxx - sx) | 151 | if (cw > win->maxx - sx) | |
152 | return ERR; | 152 | return ERR; | |
153 | lnp->flags |= __ISDIRTY; | 153 | lnp->flags |= __ISDIRTY; | |
154 | newx = sx + win->ch_off; | 154 | newx = sx + win->ch_off; | |
155 | if (newx < *lnp->firstchp) | 155 | if (newx < *lnp->firstchp) | |
156 | *lnp->firstchp = newx; | 156 | *lnp->firstchp = newx; | |
157 | 157 | |||
158 | /* shift all complete characters */ | 158 | /* shift all complete characters */ | |
159 | #ifdef DEBUG | 159 | #ifdef DEBUG | |
160 | __CTRACE(__CTRACE_INPUT, "wins_wch: shift all characters\n"); | 160 | __CTRACE(__CTRACE_INPUT, "wins_wch: shift all characters\n"); | |
161 | #endif /* DEBUG */ | 161 | #endif /* DEBUG */ | |
162 | temp1 = &win->alines[y]->line[win->maxx - 1]; | 162 | temp1 = &win->alines[y]->line[win->maxx - 1]; | |
163 | temp2 = temp1 - cw; | 163 | temp2 = temp1 - cw; | |
164 | pcw = WCOL(*(temp2 + 1)); | 164 | pcw = WCOL(*(temp2 + 1)); | |
165 | if (pcw < 0) { | 165 | if (pcw < 0) { | |
166 | #ifdef DEBUG | 166 | #ifdef DEBUG | |
167 | __CTRACE(__CTRACE_INPUT, "wins_wch: clear EOL\n"); | 167 | __CTRACE(__CTRACE_INPUT, "wins_wch: clear EOL\n"); | |
168 | #endif /* DEBUG */ | 168 | #endif /* DEBUG */ | |
169 | temp2 += pcw; | 169 | temp2 += pcw; | |
170 | while (temp1 > temp2 + cw) { | 170 | while (temp1 > temp2 + cw) { | |
171 | np = temp1->nsp; | 171 | np = temp1->nsp; | |
172 | if (np) { | 172 | if (np) { | |
173 | while (np) { | 173 | while (np) { | |
174 | tnp = np->next; | 174 | tnp = np->next; | |
175 | free(np); | 175 | free(np); | |
176 | np = tnp; | 176 | np = tnp; | |
177 | } | 177 | } | |
178 | temp1->nsp = NULL; | 178 | temp1->nsp = NULL; | |
179 | } | 179 | } | |
180 | temp1->ch = (wchar_t)btowc((int)win->bch ); | 180 | temp1->ch = (wchar_t)btowc((int)win->bch ); | |
181 | if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) | 181 | if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) | |
182 | return ERR; | 182 | return ERR; | |
183 | temp1->attr = win->battr; | 183 | temp1->attr = win->battr; | |
184 | SET_WCOL(*temp1, 1); | 184 | SET_WCOL(*temp1, 1); | |
185 | temp1--; | 185 | temp1--; | |
186 | } | 186 | } | |
187 | } | 187 | } | |
188 | while (temp2 >= start) { | 188 | while (temp2 >= start) { | |
189 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | 189 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | |
190 | temp1--, temp2--; | 190 | temp1--, temp2--; | |
191 | } | 191 | } | |
192 | 192 | |||
193 | /* update character under cursor */ | 193 | /* update character under cursor */ | |
194 | start->nsp = NULL; | 194 | start->nsp = NULL; | |
195 | start->ch = wch->vals[0]; | 195 | start->ch = wch->vals[0]; | |
196 | start->attr = wch->attributes & WA_ATTRIBUTES; | 196 | start->attr = wch->attributes & WA_ATTRIBUTES; | |
197 | SET_WCOL(*start, cw); | 197 | SET_WCOL(*start, cw); | |
198 | if (wch->elements > 1) { | 198 | if (wch->elements > 1) { | |
199 | for (i = 1; i < wch->elements; i++) { | 199 | for (i = 1; i < wch->elements; i++) { | |
200 | np = malloc(sizeof(nschar_t)); | 200 | np = malloc(sizeof(nschar_t)); | |
201 | if (!np) | 201 | if (!np) | |
202 | return ERR; | 202 | return ERR; | |
203 | np->ch = wch->vals[i]; | 203 | np->ch = wch->vals[i]; | |
204 | np->next = start->nsp; | 204 | np->next = start->nsp; | |
205 | start->nsp = np; | 205 | start->nsp = np; | |
206 | } | 206 | } | |
207 | } | 207 | } | |
208 | #ifdef DEBUG | 208 | #ifdef DEBUG | |
209 | __CTRACE(__CTRACE_INPUT, "wins_wch: insert (%x,%x,%p)\n", | 209 | __CTRACE(__CTRACE_INPUT, "wins_wch: insert (%x,%x,%p)\n", | |
210 | start->ch, start->attr, start->nsp); | 210 | start->ch, start->attr, start->nsp); | |
211 | #endif /* DEBUG */ | 211 | #endif /* DEBUG */ | |
212 | temp1 = start + 1; | 212 | temp1 = start + 1; | |
213 | ex = x + 1; | 213 | ex = x + 1; | |
214 | while (ex - x < cw) { | 214 | while (ex - x < cw) { | |
215 | temp1->ch = wch->vals[0]; | 215 | temp1->ch = wch->vals[0]; | |
216 | SET_WCOL(*temp1, x - ex); | 216 | SET_WCOL(*temp1, x - ex); | |
217 | temp1->nsp = NULL; | 217 | temp1->nsp = NULL; | |
218 | ex++, temp1++; | 218 | ex++, temp1++; | |
219 | } | 219 | } | |
220 | #ifdef DEBUG | 220 | #ifdef DEBUG | |
221 | { | 221 | { | |
222 | __CTRACE(__CTRACE_INPUT, "--after---\n"); | 222 | __CTRACE(__CTRACE_INPUT, "--after---\n"); | |
223 | for (x = 0; x < win->maxx; x++) | 223 | for (x = 0; x < win->maxx; x++) | |
224 | __CTRACE(__CTRACE_INPUT, | 224 | __CTRACE(__CTRACE_INPUT, | |
225 | "wins_wch: (0,%d)=(%x,%x,%p)\n", x, | 225 | "wins_wch: (0,%d)=(%x,%x,%p)\n", x, | |
226 | win->alines[0]->line[x].ch, | 226 | win->alines[0]->line[x].ch, | |
227 | win->alines[0]->line[x].attr, | 227 | win->alines[0]->line[x].attr, | |
228 | win->alines[0]->line[x].nsp); | 228 | win->alines[0]->line[x].nsp); | |
229 | } | 229 | } | |
230 | #endif /* DEBUG */ | 230 | #endif /* DEBUG */ | |
231 | newx = win->maxx - 1 + win->ch_off; | 231 | newx = win->maxx - 1 + win->ch_off; | |
232 | if (newx > *lnp->lastchp) | 232 | if (newx > *lnp->lastchp) | |
233 | *lnp->lastchp = newx; | 233 | *lnp->lastchp = newx; | |
234 | __touchline(win, y, sx, (int)win->maxx - 1); | 234 | __touchline(win, y, sx, (int)win->maxx - 1); | |
235 | __sync(win); | 235 | __sync(win); | |
236 | return OK; | 236 | return OK; | |
237 | } | 237 | } |
--- src/lib/libcurses/ins_wstr.c 2019/06/09 07:40:14 1.14
+++ src/lib/libcurses/ins_wstr.c 2020/07/07 12:43:51 1.14.2.1
@@ -1,330 +1,330 @@ | @@ -1,330 +1,330 @@ | |||
1 | /* $NetBSD: ins_wstr.c,v 1.14 2019/06/09 07:40:14 blymn Exp $ */ | 1 | /* $NetBSD: ins_wstr.c,v 1.14.2.1 2020/07/07 12:43:51 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | 4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from code donated to the NetBSD Foundation | 7 | * This code is derived from code donated to the NetBSD Foundation | |
8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | 8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | |
9 | * | 9 | * | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | 15 | * notice, this list of conditions and the following disclaimer. | |
16 | * 2. Redistributions in binary form must reproduce the above copyright | 16 | * 2. Redistributions in binary form must reproduce the above copyright | |
17 | * notice, this list of conditions and the following disclaimer in the | 17 | * notice, this list of conditions and the following disclaimer in the | |
18 | * documentation and/or other materials provided with the distribution. | 18 | * documentation and/or other materials provided with the distribution. | |
19 | * 3. Neither the name of the NetBSD Foundation nor the names of its | 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 | 20 | * contributors may be used to endorse or promote products derived | |
21 | * from this software without specific prior written permission. | 21 | * from this software without specific prior written permission. | |
22 | * | 22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | 23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | |
24 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | 24 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
25 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 25 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | 34 | * SUCH DAMAGE. | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | #ifndef lint | 38 | #ifndef lint | |
39 | __RCSID("$NetBSD: ins_wstr.c,v 1.14 2019/06/09 07:40:14 blymn Exp $"); | 39 | __RCSID("$NetBSD: ins_wstr.c,v 1.14.2.1 2020/07/07 12:43:51 martin Exp $"); | |
40 | #endif /* not lint */ | 40 | #endif /* not lint */ | |
41 | 41 | |||
42 | #include <string.h> | 42 | #include <string.h> | |
43 | #include <stdlib.h> | 43 | #include <stdlib.h> | |
44 | 44 | |||
45 | #include "curses.h" | 45 | #include "curses.h" | |
46 | #include "curses_private.h" | 46 | #include "curses_private.h" | |
47 | 47 | |||
48 | /* | 48 | /* | |
49 | * ins_wstr -- | 49 | * ins_wstr -- | |
50 | * insert a multi-character wide-character string into the current window | 50 | * insert a multi-character wide-character string into the current window | |
51 | */ | 51 | */ | |
52 | int | 52 | int | |
53 | ins_wstr(const wchar_t *wstr) | 53 | ins_wstr(const wchar_t *wstr) | |
54 | { | 54 | { | |
55 | return wins_wstr(stdscr, wstr); | 55 | return wins_wstr(stdscr, wstr); | |
56 | } | 56 | } | |
57 | 57 | |||
58 | /* | 58 | /* | |
59 | * ins_nwstr -- | 59 | * ins_nwstr -- | |
60 | * insert a multi-character wide-character string into the current window | 60 | * insert a multi-character wide-character string into the current window | |
61 | * with at most n characters | 61 | * with at most n characters | |
62 | */ | 62 | */ | |
63 | int | 63 | int | |
64 | ins_nwstr(const wchar_t *wstr, int n) | 64 | ins_nwstr(const wchar_t *wstr, int n) | |
65 | { | 65 | { | |
66 | return wins_nwstr(stdscr, wstr, n); | 66 | return wins_nwstr(stdscr, wstr, n); | |
67 | } | 67 | } | |
68 | 68 | |||
69 | /* | 69 | /* | |
70 | * mvins_wstr -- | 70 | * mvins_wstr -- | |
71 | * Do an insert-string on the line at (y, x). | 71 | * Do an insert-string on the line at (y, x). | |
72 | */ | 72 | */ | |
73 | int | 73 | int | |
74 | mvins_wstr(int y, int x, const wchar_t *wstr) | 74 | mvins_wstr(int y, int x, const wchar_t *wstr) | |
75 | { | 75 | { | |
76 | return mvwins_wstr(stdscr, y, x, wstr); | 76 | return mvwins_wstr(stdscr, y, x, wstr); | |
77 | } | 77 | } | |
78 | 78 | |||
79 | /* | 79 | /* | |
80 | * mvins_nwstr -- | 80 | * mvins_nwstr -- | |
81 | * Do an insert-n-string on the line at (y, x). | 81 | * Do an insert-n-string on the line at (y, x). | |
82 | */ | 82 | */ | |
83 | int | 83 | int | |
84 | mvins_nwstr(int y, int x, const wchar_t *wstr, int n) | 84 | mvins_nwstr(int y, int x, const wchar_t *wstr, int n) | |
85 | { | 85 | { | |
86 | return mvwins_nwstr(stdscr, y, x, wstr, n); | 86 | return mvwins_nwstr(stdscr, y, x, wstr, n); | |
87 | } | 87 | } | |
88 | 88 | |||
89 | /* | 89 | /* | |
90 | * mvwins_wstr -- | 90 | * mvwins_wstr -- | |
91 | * Do an insert-string on the line at (y, x) in the given window. | 91 | * Do an insert-string on the line at (y, x) in the given window. | |
92 | */ | 92 | */ | |
93 | int | 93 | int | |
94 | mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) | 94 | mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) | |
95 | { | 95 | { | |
96 | if (wmove(win, y, x) == ERR) | 96 | if (wmove(win, y, x) == ERR) | |
97 | return ERR; | 97 | return ERR; | |
98 | 98 | |||
99 | return wins_wstr(stdscr, wstr); | 99 | return wins_wstr(win, wstr); | |
100 | } | 100 | } | |
101 | 101 | |||
102 | /* | 102 | /* | |
103 | * mvwins_nwstr -- | 103 | * mvwins_nwstr -- | |
104 | * Do an insert-n-string on the line at (y, x) in the given window. | 104 | * Do an insert-n-string on the line at (y, x) in the given window. | |
105 | */ | 105 | */ | |
106 | int | 106 | int | |
107 | mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) | 107 | mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) | |
108 | { | 108 | { | |
109 | if (wmove(win, y, x) == ERR) | 109 | if (wmove(win, y, x) == ERR) | |
110 | return ERR; | 110 | return ERR; | |
111 | 111 | |||
112 | return wins_nwstr(stdscr, wstr, n); | 112 | return wins_nwstr(win, wstr, n); | |
113 | } | 113 | } | |
114 | 114 | |||
115 | 115 | |||
116 | /* | 116 | /* | |
117 | * wins_wstr -- | 117 | * wins_wstr -- | |
118 | * Do an insert-string on the line, leaving (cury, curx) unchanged. | 118 | * Do an insert-string on the line, leaving (cury, curx) unchanged. | |
119 | */ | 119 | */ | |
120 | int | 120 | int | |
121 | wins_wstr(WINDOW *win, const wchar_t *wstr) | 121 | wins_wstr(WINDOW *win, const wchar_t *wstr) | |
122 | { | 122 | { | |
123 | return wins_nwstr(win, wstr, -1); | 123 | return wins_nwstr(win, wstr, -1); | |
124 | } | 124 | } | |
125 | 125 | |||
126 | /* | 126 | /* | |
127 | * wins_nwstr -- | 127 | * wins_nwstr -- | |
128 | * Do an insert-n-string on the line, leaving (cury, curx) unchanged. | 128 | * Do an insert-n-string on the line, leaving (cury, curx) unchanged. | |
129 | */ | 129 | */ | |
130 | int | 130 | int | |
131 | wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) | 131 | wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) | |
132 | { | 132 | { | |
133 | __LDATA *start, *temp1, *temp2; | 133 | __LDATA *start, *temp1, *temp2; | |
134 | __LINE *lnp; | 134 | __LINE *lnp; | |
135 | const wchar_t *scp; | 135 | const wchar_t *scp; | |
136 | int width, len, sx, x, y, cw, pcw, newx; | 136 | int width, len, sx, x, y, cw, pcw, newx; | |
137 | nschar_t *np; | 137 | nschar_t *np; | |
138 | wchar_t ws[] = L" "; | 138 | wchar_t ws[] = L" "; | |
139 | 139 | |||
140 | /* check for leading non-spacing character */ | 140 | /* check for leading non-spacing character */ | |
141 | if (!wstr) | 141 | if (!wstr) | |
142 | return OK; | 142 | return OK; | |
143 | cw = wcwidth(*wstr); | 143 | cw = wcwidth(*wstr); | |
144 | if (cw < 0) | 144 | if (cw < 0) | |
145 | cw = 1; | 145 | cw = 1; | |
146 | if (!cw) | 146 | if (!cw) | |
147 | return ERR; | 147 | return ERR; | |
148 | 148 | |||
149 | scp = wstr + 1; | 149 | scp = wstr + 1; | |
150 | width = cw; | 150 | width = cw; | |
151 | len = 1; | 151 | len = 1; | |
152 | n--; | 152 | n--; | |
153 | while (*scp) { | 153 | while (*scp) { | |
154 | int w; | 154 | int w; | |
155 | if (!n) | 155 | if (!n) | |
156 | break; | 156 | break; | |
157 | w = wcwidth(*scp); | 157 | w = wcwidth(*scp); | |
158 | if (w < 0) | 158 | if (w < 0) | |
159 | w = 1; | 159 | w = 1; | |
160 | n--, len++, width += w; | 160 | n--, len++, width += w; | |
161 | scp++; | 161 | scp++; | |
162 | } | 162 | } | |
163 | #ifdef DEBUG | 163 | #ifdef DEBUG | |
164 | __CTRACE(__CTRACE_INPUT, "wins_nwstr: width=%d,len=%d\n", width, len); | 164 | __CTRACE(__CTRACE_INPUT, "wins_nwstr: width=%d,len=%d\n", width, len); | |
165 | #endif /* DEBUG */ | 165 | #endif /* DEBUG */ | |
166 | 166 | |||
167 | if (cw > win->maxx - win->curx + 1) | 167 | if (cw > win->maxx - win->curx + 1) | |
168 | return ERR; | 168 | return ERR; | |
169 | start = &win->alines[win->cury]->line[win->curx]; | 169 | start = &win->alines[win->cury]->line[win->curx]; | |
170 | sx = win->curx; | 170 | sx = win->curx; | |
171 | lnp = win->alines[win->cury]; | 171 | lnp = win->alines[win->cury]; | |
172 | pcw = WCOL(*start); | 172 | pcw = WCOL(*start); | |
173 | if (pcw < 0) { | 173 | if (pcw < 0) { | |
174 | sx += pcw; | 174 | sx += pcw; | |
175 | start += pcw; | 175 | start += pcw; | |
176 | } | 176 | } | |
177 | #ifdef DEBUG | 177 | #ifdef DEBUG | |
178 | __CTRACE(__CTRACE_INPUT, "wins_nwstr: start@(%d)\n", sx); | 178 | __CTRACE(__CTRACE_INPUT, "wins_nwstr: start@(%d)\n", sx); | |
179 | #endif /* DEBUG */ | 179 | #endif /* DEBUG */ | |
180 | pcw = WCOL(*start); | 180 | pcw = WCOL(*start); | |
181 | lnp->flags |= __ISDIRTY; | 181 | lnp->flags |= __ISDIRTY; | |
182 | newx = sx + win->ch_off; | 182 | newx = sx + win->ch_off; | |
183 | if (newx < *lnp->firstchp) | 183 | if (newx < *lnp->firstchp) | |
184 | *lnp->firstchp = newx; | 184 | *lnp->firstchp = newx; | |
185 | #ifdef DEBUG | 185 | #ifdef DEBUG | |
186 | { | 186 | { | |
187 | __CTRACE(__CTRACE_INPUT, "========before=======\n"); | 187 | __CTRACE(__CTRACE_INPUT, "========before=======\n"); | |
188 | for (x = 0; x < win->maxx; x++) | 188 | for (x = 0; x < win->maxx; x++) | |
189 | __CTRACE(__CTRACE_INPUT, | 189 | __CTRACE(__CTRACE_INPUT, | |
190 | "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", | 190 | "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", | |
191 | (int) win->cury, x, | 191 | (int) win->cury, x, | |
192 | win->alines[win->cury]->line[x].ch, | 192 | win->alines[win->cury]->line[x].ch, | |
193 | win->alines[win->cury]->line[x].attr, | 193 | win->alines[win->cury]->line[x].attr, | |
194 | win->alines[win->cury]->line[x].nsp); | 194 | win->alines[win->cury]->line[x].nsp); | |
195 | } | 195 | } | |
196 | #endif /* DEBUG */ | 196 | #endif /* DEBUG */ | |
197 | 197 | |||
198 | /* shift all complete characters */ | 198 | /* shift all complete characters */ | |
199 | if (sx + width + pcw <= win->maxx) { | 199 | if (sx + width + pcw <= win->maxx) { | |
200 | #ifdef DEBUG | 200 | #ifdef DEBUG | |
201 | __CTRACE(__CTRACE_INPUT, "wins_nwstr: shift all characters\n"); | 201 | __CTRACE(__CTRACE_INPUT, "wins_nwstr: shift all characters\n"); | |
202 | #endif /* DEBUG */ | 202 | #endif /* DEBUG */ | |
203 | temp1 = &win->alines[win->cury]->line[win->maxx - 1]; | 203 | temp1 = &win->alines[win->cury]->line[win->maxx - 1]; | |
204 | temp2 = temp1 - width; | 204 | temp2 = temp1 - width; | |
205 | pcw = WCOL(*(temp2 + 1)); | 205 | pcw = WCOL(*(temp2 + 1)); | |
206 | if (pcw < 0) { | 206 | if (pcw < 0) { | |
207 | #ifdef DEBUG | 207 | #ifdef DEBUG | |
208 | __CTRACE(__CTRACE_INPUT, | 208 | __CTRACE(__CTRACE_INPUT, | |
209 | "wins_nwstr: clear from %d to EOL(%d)\n", | 209 | "wins_nwstr: clear from %d to EOL(%d)\n", | |
210 | win->maxx + pcw, win->maxx - 1); | 210 | win->maxx + pcw, win->maxx - 1); | |
211 | #endif /* DEBUG */ | 211 | #endif /* DEBUG */ | |
212 | temp2 += pcw; | 212 | temp2 += pcw; | |
213 | while (temp1 > temp2 + width) { | 213 | while (temp1 > temp2 + width) { | |
214 | temp1->ch = (wchar_t)btowc((int) win->bch); | 214 | temp1->ch = (wchar_t)btowc((int) win->bch); | |
215 | if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) | 215 | if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) | |
216 | return ERR; | 216 | return ERR; | |
217 | temp1->attr = win->battr; | 217 | temp1->attr = win->battr; | |
218 | SET_WCOL(*temp1, 1); | 218 | SET_WCOL(*temp1, 1); | |
219 | #ifdef DEBUG | 219 | #ifdef DEBUG | |
220 | __CTRACE(__CTRACE_INPUT, | 220 | __CTRACE(__CTRACE_INPUT, | |
221 | "wins_nwstr: empty cell(%p)\n", temp1); | 221 | "wins_nwstr: empty cell(%p)\n", temp1); | |
222 | #endif /* DEBUG */ | 222 | #endif /* DEBUG */ | |
223 | temp1--; | 223 | temp1--; | |
224 | } | 224 | } | |
225 | } | 225 | } | |
226 | while (temp2 >= start) { | 226 | while (temp2 >= start) { | |
227 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | 227 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | |
228 | temp1--, temp2--; | 228 | temp1--, temp2--; | |
229 | } | 229 | } | |
230 | #ifdef DEBUG | 230 | #ifdef DEBUG | |
231 | { | 231 | { | |
232 | __CTRACE(__CTRACE_INPUT, "=====after shift====\n"); | 232 | __CTRACE(__CTRACE_INPUT, "=====after shift====\n"); | |
233 | for (x = 0; x < win->maxx; x++) | 233 | for (x = 0; x < win->maxx; x++) | |
234 | __CTRACE(__CTRACE_INPUT, | 234 | __CTRACE(__CTRACE_INPUT, | |
235 | "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", | 235 | "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", | |
236 | (int) win->cury, x, | 236 | (int) win->cury, x, | |
237 | win->alines[win->cury]->line[x].ch, | 237 | win->alines[win->cury]->line[x].ch, | |
238 | win->alines[win->cury]->line[x].attr, | 238 | win->alines[win->cury]->line[x].attr, | |
239 | win->alines[win->cury]->line[x].nsp); | 239 | win->alines[win->cury]->line[x].nsp); | |
240 | } | 240 | } | |
241 | #endif /* DEBUG */ | 241 | #endif /* DEBUG */ | |
242 | } | 242 | } | |
243 | 243 | |||
244 | /* update string columns */ | 244 | /* update string columns */ | |
245 | x = win->curx; | 245 | x = win->curx; | |
246 | y = win->cury; | 246 | y = win->cury; | |
247 | for (scp = wstr, temp1 = start; len; len--, scp++) { | 247 | for (scp = wstr, temp1 = start; len; len--, scp++) { | |
248 | switch (*scp) { | 248 | switch (*scp) { | |
249 | case L'\b': | 249 | case L'\b': | |
250 | if (--x < 0) | 250 | if (--x < 0) | |
251 | x = 0; | 251 | x = 0; | |
252 | win->curx = x; | 252 | win->curx = x; | |
253 | continue;; | 253 | continue;; | |
254 | case L'\r': | 254 | case L'\r': | |
255 | win->curx = 0; | 255 | win->curx = 0; | |
256 | continue; | 256 | continue; | |
257 | case L'\n': | 257 | case L'\n': | |
258 | wclrtoeol(win); | 258 | wclrtoeol(win); | |
259 | if (y == win->scr_b) { | 259 | if (y == win->scr_b) { | |
260 | if (!(win->flags & __SCROLLOK)) | 260 | if (!(win->flags & __SCROLLOK)) | |
261 | return ERR; | 261 | return ERR; | |
262 | scroll(win); | 262 | scroll(win); | |
263 | } | 263 | } | |
264 | continue; | 264 | continue; | |
265 | case L'\t': | 265 | case L'\t': | |
266 | if (wins_nwstr(win, ws, | 266 | if (wins_nwstr(win, ws, | |
267 | min(win->maxx - x, TABSIZE - (x % TABSIZE))) | 267 | min(win->maxx - x, TABSIZE - (x % TABSIZE))) | |
268 | == ERR) | 268 | == ERR) | |
269 | return ERR; | 269 | return ERR; | |
270 | continue; | 270 | continue; | |
271 | } | 271 | } | |
272 | cw = wcwidth(*scp); | 272 | cw = wcwidth(*scp); | |
273 | if (cw < 0) | 273 | if (cw < 0) | |
274 | cw = 1; | 274 | cw = 1; | |
275 | if (cw) { | 275 | if (cw) { | |
276 | /* 1st column */ | 276 | /* 1st column */ | |
277 | temp1->ch = (wchar_t)*scp; | 277 | temp1->ch = (wchar_t)*scp; | |
278 | temp1->attr = win->wattr; | 278 | temp1->attr = win->wattr; | |
279 | SET_WCOL(*temp1, cw); | 279 | SET_WCOL(*temp1, cw); | |
280 | temp1->nsp = NULL; | 280 | temp1->nsp = NULL; | |
281 | #ifdef DEBUG | 281 | #ifdef DEBUG | |
282 | __CTRACE(__CTRACE_INPUT, | 282 | __CTRACE(__CTRACE_INPUT, | |
283 | "wins_nwstr: add spacing char(%x)\n", temp1->ch); | 283 | "wins_nwstr: add spacing char(%x)\n", temp1->ch); | |
284 | #endif /* DEBUG */ | 284 | #endif /* DEBUG */ | |
285 | temp2 = temp1++; | 285 | temp2 = temp1++; | |
286 | if (cw > 1) { | 286 | if (cw > 1) { | |
287 | x = -1; | 287 | x = -1; | |
288 | while (temp1 < temp2 + cw) { | 288 | while (temp1 < temp2 + cw) { | |
289 | /* the rest columns */ | 289 | /* the rest columns */ | |
290 | temp1->ch = (wchar_t)*scp; | 290 | temp1->ch = (wchar_t)*scp; | |
291 | temp1->attr = win->wattr; | 291 | temp1->attr = win->wattr; | |
292 | temp1->nsp = NULL; | 292 | temp1->nsp = NULL; | |
293 | SET_WCOL(*temp1, x); | 293 | SET_WCOL(*temp1, x); | |
294 | temp1++, x--; | 294 | temp1++, x--; | |
295 | } | 295 | } | |
296 | temp1--; | 296 | temp1--; | |
297 | } | 297 | } | |
298 | } else { | 298 | } else { | |
299 | /* non-spacing character */ | 299 | /* non-spacing character */ | |
300 | np = malloc(sizeof(nschar_t)); | 300 | np = malloc(sizeof(nschar_t)); | |
301 | if (!np) | 301 | if (!np) | |
302 | return ERR; | 302 | return ERR; | |
303 | np->ch = *scp; | 303 | np->ch = *scp; | |
304 | np->next = temp1->nsp; | 304 | np->next = temp1->nsp; | |
305 | temp1->nsp = np; | 305 | temp1->nsp = np; | |
306 | #ifdef DEBUG | 306 | #ifdef DEBUG | |
307 | __CTRACE(__CTRACE_INPUT, | 307 | __CTRACE(__CTRACE_INPUT, | |
308 | "wins_nstr: add non-spacing char(%x)\n", np->ch); | 308 | "wins_nstr: add non-spacing char(%x)\n", np->ch); | |
309 | #endif /* DEBUG */ | 309 | #endif /* DEBUG */ | |
310 | } | 310 | } | |
311 | } | 311 | } | |
312 | #ifdef DEBUG | 312 | #ifdef DEBUG | |
313 | { | 313 | { | |
314 | __CTRACE(__CTRACE_INPUT, "========after=======\n"); | 314 | __CTRACE(__CTRACE_INPUT, "========after=======\n"); | |
315 | for (x = 0; x < win->maxx; x++) | 315 | for (x = 0; x < win->maxx; x++) | |
316 | __CTRACE(__CTRACE_INPUT, | 316 | __CTRACE(__CTRACE_INPUT, | |
317 | "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", | 317 | "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", | |
318 | (int) win->cury, x, | 318 | (int) win->cury, x, | |
319 | win->alines[win->cury]->line[x].ch, | 319 | win->alines[win->cury]->line[x].ch, | |
320 | win->alines[win->cury]->line[x].attr, | 320 | win->alines[win->cury]->line[x].attr, | |
321 | win->alines[win->cury]->line[x].nsp); | 321 | win->alines[win->cury]->line[x].nsp); | |
322 | } | 322 | } | |
323 | #endif /* DEBUG */ | 323 | #endif /* DEBUG */ | |
324 | newx = win->maxx - 1 + win->ch_off; | 324 | newx = win->maxx - 1 + win->ch_off; | |
325 | if (newx > *lnp->lastchp) | 325 | if (newx > *lnp->lastchp) | |
326 | *lnp->lastchp = newx; | 326 | *lnp->lastchp = newx; | |
327 | __touchline(win, (int) win->cury, sx, (int) win->maxx - 1); | 327 | __touchline(win, (int) win->cury, sx, (int) win->maxx - 1); | |
328 | __sync(win); | 328 | __sync(win); | |
329 | return OK; | 329 | return OK; | |
330 | } | 330 | } |
--- src/lib/libcurses/insch.c 2019/06/09 07:40:14 1.25
+++ src/lib/libcurses/insch.c 2020/07/07 12:43:51 1.25.2.1
@@ -1,133 +1,133 @@ | @@ -1,133 +1,133 @@ | |||
1 | /* $NetBSD: insch.c,v 1.25 2019/06/09 07:40:14 blymn Exp $ */ | 1 | /* $NetBSD: insch.c,v 1.25.2.1 2020/07/07 12:43:51 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1981, 1993, 1994 | 4 | * Copyright (c) 1981, 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. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 15 | * 3. Neither the name of the University nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
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[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94"; | 35 | static char sccsid[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: insch.c,v 1.25 2019/06/09 07:40:14 blymn Exp $"); | 37 | __RCSID("$NetBSD: insch.c,v 1.25.2.1 2020/07/07 12:43:51 martin Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <string.h> | 41 | #include <string.h> | |
42 | #include <stdlib.h> | 42 | #include <stdlib.h> | |
43 | 43 | |||
44 | #include "curses.h" | 44 | #include "curses.h" | |
45 | #include "curses_private.h" | 45 | #include "curses_private.h" | |
46 | 46 | |||
47 | #ifndef _CURSES_USE_MACROS | 47 | #ifndef _CURSES_USE_MACROS | |
48 | 48 | |||
49 | /* | 49 | /* | |
50 | * insch -- | 50 | * insch -- | |
51 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | 51 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | |
52 | */ | 52 | */ | |
53 | int | 53 | int | |
54 | insch(chtype ch) | 54 | insch(chtype ch) | |
55 | { | 55 | { | |
56 | 56 | |||
57 | return winsch(stdscr, ch); | 57 | return winsch(stdscr, ch); | |
58 | } | 58 | } | |
59 | 59 | |||
60 | /* | 60 | /* | |
61 | * mvinsch -- | 61 | * mvinsch -- | |
62 | * Do an insert-char on the line at (y, x). | 62 | * Do an insert-char on the line at (y, x). | |
63 | */ | 63 | */ | |
64 | int | 64 | int | |
65 | mvinsch(int y, int x, chtype ch) | 65 | mvinsch(int y, int x, chtype ch) | |
66 | { | 66 | { | |
67 | 67 | |||
68 | return mvwinsch(stdscr, y, x, ch); | 68 | return mvwinsch(stdscr, y, x, ch); | |
69 | } | 69 | } | |
70 | 70 | |||
71 | /* | 71 | /* | |
72 | * mvwinsch -- | 72 | * mvwinsch -- | |
73 | * Do an insert-char on the line at (y, x) in the given window. | 73 | * Do an insert-char on the line at (y, x) in the given window. | |
74 | */ | 74 | */ | |
75 | int | 75 | int | |
76 | mvwinsch(WINDOW *win, int y, int x, chtype ch) | 76 | mvwinsch(WINDOW *win, int y, int x, chtype ch) | |
77 | { | 77 | { | |
78 | 78 | |||
79 | if (wmove(win, y, x) == ERR) | 79 | if (wmove(win, y, x) == ERR) | |
80 | return ERR; | 80 | return ERR; | |
81 | 81 | |||
82 | return winsch(stdscr, ch); | 82 | return winsch(win, ch); | |
83 | } | 83 | } | |
84 | 84 | |||
85 | #endif | 85 | #endif | |
86 | 86 | |||
87 | /* | 87 | /* | |
88 | * winsch -- | 88 | * winsch -- | |
89 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | 89 | * Do an insert-char on the line, leaving (cury, curx) unchanged. | |
90 | */ | 90 | */ | |
91 | int | 91 | int | |
92 | winsch(WINDOW *win, chtype ch) | 92 | winsch(WINDOW *win, chtype ch) | |
93 | { | 93 | { | |
94 | __LDATA *end, *temp1, *temp2; | 94 | __LDATA *end, *temp1, *temp2; | |
95 | attr_t attr; | 95 | attr_t attr; | |
96 | 96 | |||
97 | if (__using_color) | 97 | if (__using_color) | |
98 | attr = win->battr & __COLOR; | 98 | attr = win->battr & __COLOR; | |
99 | else | 99 | else | |
100 | attr = 0; | 100 | attr = 0; | |
101 | end = &win->alines[win->cury]->line[win->curx]; | 101 | end = &win->alines[win->cury]->line[win->curx]; | |
102 | temp1 = &win->alines[win->cury]->line[win->maxx - 1]; | 102 | temp1 = &win->alines[win->cury]->line[win->maxx - 1]; | |
103 | temp2 = temp1 - 1; | 103 | temp2 = temp1 - 1; | |
104 | while (temp1 > end) { | 104 | while (temp1 > end) { | |
105 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | 105 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | |
106 | temp1--, temp2--; | 106 | temp1--, temp2--; | |
107 | } | 107 | } | |
108 | temp1->ch = (wchar_t)ch & __CHARTEXT; | 108 | temp1->ch = (wchar_t)ch & __CHARTEXT; | |
109 | if (temp1->ch == ' ') | 109 | if (temp1->ch == ' ') | |
110 | temp1->ch = win->bch; | 110 | temp1->ch = win->bch; | |
111 | temp1->attr = (attr_t) ch & __ATTRIBUTES; | 111 | temp1->attr = (attr_t) ch & __ATTRIBUTES; | |
112 | if (temp1->attr & __COLOR) | 112 | if (temp1->attr & __COLOR) | |
113 | temp1->attr |= (win->battr & ~__COLOR); | 113 | temp1->attr |= (win->battr & ~__COLOR); | |
114 | else | 114 | else | |
115 | temp1->attr |= win->battr; | 115 | temp1->attr |= win->battr; | |
116 | #ifdef HAVE_WCHAR | 116 | #ifdef HAVE_WCHAR | |
117 | if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) | 117 | if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) | |
118 | return ERR; | 118 | return ERR; | |
119 | SET_WCOL(*temp1, 1); | 119 | SET_WCOL(*temp1, 1); | |
120 | #endif /* HAVE_WCHAR */ | 120 | #endif /* HAVE_WCHAR */ | |
121 | __touchline(win, (int)win->cury, (int)win->curx, (int)win->maxx - 1); | 121 | __touchline(win, (int)win->cury, (int)win->curx, (int)win->maxx - 1); | |
122 | if (win->cury == LINES - 1 && | 122 | if (win->cury == LINES - 1 && | |
123 | (win->alines[LINES - 1]->line[COLS - 1].ch != ' ' || | 123 | (win->alines[LINES - 1]->line[COLS - 1].ch != ' ' || | |
124 | win->alines[LINES - 1]->line[COLS - 1].attr != attr)) { | 124 | win->alines[LINES - 1]->line[COLS - 1].attr != attr)) { | |
125 | if (win->flags & __SCROLLOK) { | 125 | if (win->flags & __SCROLLOK) { | |
126 | wrefresh(win); | 126 | wrefresh(win); | |
127 | scroll(win); | 127 | scroll(win); | |
128 | win->cury--; | 128 | win->cury--; | |
129 | } else | 129 | } else | |
130 | return ERR; | 130 | return ERR; | |
131 | } | 131 | } | |
132 | return OK; | 132 | return OK; | |
133 | } | 133 | } |
--- src/lib/libcurses/insstr.c 2019/06/09 07:40:14 1.7
+++ src/lib/libcurses/insstr.c 2020/07/07 12:43:51 1.7.2.1
@@ -1,218 +1,218 @@ | @@ -1,218 +1,218 @@ | |||
1 | /* $NetBSD: insstr.c,v 1.7 2019/06/09 07:40:14 blymn Exp $ */ | 1 | /* $NetBSD: insstr.c,v 1.7.2.1 2020/07/07 12:43:51 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | 4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from code donated to the NetBSD Foundation | 7 | * This code is derived from code donated to the NetBSD Foundation | |
8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | 8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | |
9 | * | 9 | * | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | 15 | * notice, this list of conditions and the following disclaimer. | |
16 | * 2. Redistributions in binary form must reproduce the above copyright | 16 | * 2. Redistributions in binary form must reproduce the above copyright | |
17 | * notice, this list of conditions and the following disclaimer in the | 17 | * notice, this list of conditions and the following disclaimer in the | |
18 | * documentation and/or other materials provided with the distribution. | 18 | * documentation and/or other materials provided with the distribution. | |
19 | * 3. Neither the name of the NetBSD Foundation nor the names of its | 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 | 20 | * contributors may be used to endorse or promote products derived | |
21 | * from this software without specific prior written permission. | 21 | * from this software without specific prior written permission. | |
22 | * | 22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | 23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | |
24 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | 24 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
25 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 25 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | 34 | * SUCH DAMAGE. | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | #ifndef lint | 38 | #ifndef lint | |
39 | __RCSID("$NetBSD: insstr.c,v 1.7 2019/06/09 07:40:14 blymn Exp $"); | 39 | __RCSID("$NetBSD: insstr.c,v 1.7.2.1 2020/07/07 12:43:51 martin Exp $"); | |
40 | #endif /* not lint */ | 40 | #endif /* not lint */ | |
41 | 41 | |||
42 | #include <string.h> | 42 | #include <string.h> | |
43 | #include <stdlib.h> | 43 | #include <stdlib.h> | |
44 | 44 | |||
45 | #include "curses.h" | 45 | #include "curses.h" | |
46 | #include "curses_private.h" | 46 | #include "curses_private.h" | |
47 | 47 | |||
48 | #ifndef _CURSES_USE_MACROS | 48 | #ifndef _CURSES_USE_MACROS | |
49 | 49 | |||
50 | /* | 50 | /* | |
51 | * insstr -- | 51 | * insstr -- | |
52 | * insert a multi-byte character string into the current window | 52 | * insert a multi-byte character string into the current window | |
53 | */ | 53 | */ | |
54 | int | 54 | int | |
55 | insstr(const char *str) | 55 | insstr(const char *str) | |
56 | { | 56 | { | |
57 | 57 | |||
58 | return winsstr(stdscr, str); | 58 | return winsstr(stdscr, str); | |
59 | } | 59 | } | |
60 | 60 | |||
61 | /* | 61 | /* | |
62 | * insnstr -- | 62 | * insnstr -- | |
63 | * insert a multi-byte character string into the current window | 63 | * insert a multi-byte character string into the current window | |
64 | * with at most n characters | 64 | * with at most n characters | |
65 | */ | 65 | */ | |
66 | int | 66 | int | |
67 | insnstr(const char *str, int n) | 67 | insnstr(const char *str, int n) | |
68 | { | 68 | { | |
69 | 69 | |||
70 | return winsnstr(stdscr, str, n); | 70 | return winsnstr(stdscr, str, n); | |
71 | } | 71 | } | |
72 | 72 | |||
73 | /* | 73 | /* | |
74 | * mvinsstr -- | 74 | * mvinsstr -- | |
75 | * Do an insert-string on the line at (y, x). | 75 | * Do an insert-string on the line at (y, x). | |
76 | */ | 76 | */ | |
77 | int | 77 | int | |
78 | mvinsstr(int y, int x, const char *str) | 78 | mvinsstr(int y, int x, const char *str) | |
79 | { | 79 | { | |
80 | 80 | |||
81 | return mvwinsstr(stdscr, y, x, str); | 81 | return mvwinsstr(stdscr, y, x, str); | |
82 | } | 82 | } | |
83 | 83 | |||
84 | /* | 84 | /* | |
85 | * mvinsnstr -- | 85 | * mvinsnstr -- | |
86 | * Do an insert-n-string on the line at (y, x). | 86 | * Do an insert-n-string on the line at (y, x). | |
87 | */ | 87 | */ | |
88 | int | 88 | int | |
89 | mvinsnstr(int y, int x, const char *str, int n) | 89 | mvinsnstr(int y, int x, const char *str, int n) | |
90 | { | 90 | { | |
91 | 91 | |||
92 | return mvwinsnstr(stdscr, y, x, str, n); | 92 | return mvwinsnstr(stdscr, y, x, str, n); | |
93 | } | 93 | } | |
94 | 94 | |||
95 | /* | 95 | /* | |
96 | * mvwinsstr -- | 96 | * mvwinsstr -- | |
97 | * Do an insert-string on the line at (y, x) in the given window. | 97 | * Do an insert-string on the line at (y, x) in the given window. | |
98 | */ | 98 | */ | |
99 | int | 99 | int | |
100 | mvwinsstr(WINDOW *win, int y, int x, const char *str) | 100 | mvwinsstr(WINDOW *win, int y, int x, const char *str) | |
101 | { | 101 | { | |
102 | 102 | |||
103 | if (wmove(win, y, x) == ERR) | 103 | if (wmove(win, y, x) == ERR) | |
104 | return ERR; | 104 | return ERR; | |
105 | 105 | |||
106 | return winsstr(stdscr, str); | 106 | return winsstr(win, str); | |
107 | } | 107 | } | |
108 | 108 | |||
109 | /* | 109 | /* | |
110 | * mvwinsnstr -- | 110 | * mvwinsnstr -- | |
111 | * Do an insert-n-string on the line at (y, x) in the given window. | 111 | * Do an insert-n-string on the line at (y, x) in the given window. | |
112 | */ | 112 | */ | |
113 | int | 113 | int | |
114 | mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) | 114 | mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) | |
115 | { | 115 | { | |
116 | 116 | |||
117 | if (wmove(win, y, x) == ERR) | 117 | if (wmove(win, y, x) == ERR) | |
118 | return ERR; | 118 | return ERR; | |
119 | 119 | |||
120 | return winsnstr(stdscr, str, n); | 120 | return winsnstr(win, str, n); | |
121 | } | 121 | } | |
122 | 122 | |||
123 | #endif | 123 | #endif | |
124 | 124 | |||
125 | /* | 125 | /* | |
126 | * winsstr -- | 126 | * winsstr -- | |
127 | * Do an insert-string on the line, leaving (cury, curx) unchanged. | 127 | * Do an insert-string on the line, leaving (cury, curx) unchanged. | |
128 | * No wrapping. | 128 | * No wrapping. | |
129 | */ | 129 | */ | |
130 | int | 130 | int | |
131 | winsstr(WINDOW *win, const char *str) | 131 | winsstr(WINDOW *win, const char *str) | |
132 | { | 132 | { | |
133 | 133 | |||
134 | return winsnstr(win, str, -1); | 134 | return winsnstr(win, str, -1); | |
135 | } | 135 | } | |
136 | 136 | |||
137 | /* | 137 | /* | |
138 | * winsnstr -- | 138 | * winsnstr -- | |
139 | * Do an insert-n-string on the line, leaving (cury, curx) unchanged. | 139 | * Do an insert-n-string on the line, leaving (cury, curx) unchanged. | |
140 | * Performs wrapping. | 140 | * Performs wrapping. | |
141 | */ | 141 | */ | |
142 | int | 142 | int | |
143 | winsnstr(WINDOW *win, const char *str, int n) | 143 | winsnstr(WINDOW *win, const char *str, int n) | |
144 | { | 144 | { | |
145 | __LDATA *end, *temp1, *temp2; | 145 | __LDATA *end, *temp1, *temp2; | |
146 | const char *scp; | 146 | const char *scp; | |
147 | int len, x; | 147 | int len, x; | |
148 | __LINE *lnp; | 148 | __LINE *lnp; | |
149 | #ifdef HAVE_WCHAR | 149 | #ifdef HAVE_WCHAR | |
150 | nschar_t *np, *tnp; | 150 | nschar_t *np, *tnp; | |
151 | #endif /* HAVE_WCHAR */ | 151 | #endif /* HAVE_WCHAR */ | |
152 | 152 | |||
153 | /* find string length */ | 153 | /* find string length */ | |
154 | if (n > 0) | 154 | if (n > 0) | |
155 | for (scp = str, len = 0; n-- && *scp++; ++len); | 155 | for (scp = str, len = 0; n-- && *scp++; ++len); | |
156 | else | 156 | else | |
157 | for (scp = str, len = 0; *scp++; ++len); | 157 | for (scp = str, len = 0; *scp++; ++len); | |
158 | #ifdef DEBUG | 158 | #ifdef DEBUG | |
159 | __CTRACE(__CTRACE_INPUT, "winsnstr: len = %d\n", len); | 159 | __CTRACE(__CTRACE_INPUT, "winsnstr: len = %d\n", len); | |
160 | #endif /* DEBUG */ | 160 | #endif /* DEBUG */ | |
161 | 161 | |||
162 | /* move string */ | 162 | /* move string */ | |
163 | end = &win->alines[win->cury]->line[win->curx]; | 163 | end = &win->alines[win->cury]->line[win->curx]; | |
164 | if (len < win->maxx - win->curx) { | 164 | if (len < win->maxx - win->curx) { | |
165 | #ifdef DEBUG | 165 | #ifdef DEBUG | |
166 | __CTRACE(__CTRACE_INPUT, "winsnstr: shift %d cells\n", len); | 166 | __CTRACE(__CTRACE_INPUT, "winsnstr: shift %d cells\n", len); | |
167 | #endif /* DEBUG */ | 167 | #endif /* DEBUG */ | |
168 | temp1 = &win->alines[win->cury]->line[win->maxx - 1]; | 168 | temp1 = &win->alines[win->cury]->line[win->maxx - 1]; | |
169 | temp2 = temp1 - len; | 169 | temp2 = temp1 - len; | |
170 | while (temp2 >= end) { | 170 | while (temp2 >= end) { | |
171 | #ifdef HAVE_WCHAR | 171 | #ifdef HAVE_WCHAR | |
172 | np = temp1->nsp; | 172 | np = temp1->nsp; | |
173 | if (np){ | 173 | if (np){ | |
174 | while (np) { | 174 | while (np) { | |
175 | tnp = np->next; | 175 | tnp = np->next; | |
176 | free(np); | 176 | free(np); | |
177 | np = tnp; | 177 | np = tnp; | |
178 | } | 178 | } | |
179 | temp1->nsp = NULL; | 179 | temp1->nsp = NULL; | |
180 | } | 180 | } | |
181 | #endif /* HAVE_WCHAR */ | 181 | #endif /* HAVE_WCHAR */ | |
182 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | 182 | (void)memcpy(temp1, temp2, sizeof(__LDATA)); | |
183 | temp1--, temp2--; | 183 | temp1--, temp2--; | |
184 | } | 184 | } | |
185 | } | 185 | } | |
186 | 186 | |||
187 | for (scp = str, temp1 = end, x = win->curx; | 187 | for (scp = str, temp1 = end, x = win->curx; | |
188 | *scp && x < len + win->curx && x < win->maxx; | 188 | *scp && x < len + win->curx && x < win->maxx; | |
189 | scp++, temp1++, x++) | 189 | scp++, temp1++, x++) | |
190 | { | 190 | { | |
191 | temp1->ch = (wchar_t)*scp & __CHARTEXT; | 191 | temp1->ch = (wchar_t)*scp & __CHARTEXT; | |
192 | temp1->attr = win->wattr; | 192 | temp1->attr = win->wattr; | |
193 | #ifdef HAVE_WCHAR | 193 | #ifdef HAVE_WCHAR | |
194 | SET_WCOL(*temp1, 1); | 194 | SET_WCOL(*temp1, 1); | |
195 | #endif /* HAVE_WCHAR */ | 195 | #endif /* HAVE_WCHAR */ | |
196 | } | 196 | } | |
197 | #ifdef DEBUG | 197 | #ifdef DEBUG | |
198 | { | 198 | { | |
199 | int i; | 199 | int i; | |
200 | 200 | |||
201 | for (i = win->curx; i < win->curx + len; i++) { | 201 | for (i = win->curx; i < win->curx + len; i++) { | |
202 | __CTRACE(__CTRACE_INPUT, | 202 | __CTRACE(__CTRACE_INPUT, | |
203 | "winsnstr: (%d,%d)=('%c',%x)\n", win->cury, i, | 203 | "winsnstr: (%d,%d)=('%c',%x)\n", win->cury, i, | |
204 | win->alines[win->cury]->line[i].ch, | 204 | win->alines[win->cury]->line[i].ch, | |
205 | win->alines[win->cury]->line[i].attr); | 205 | win->alines[win->cury]->line[i].attr); | |
206 | } | 206 | } | |
207 | } | 207 | } | |
208 | #endif /* DEBUG */ | 208 | #endif /* DEBUG */ | |
209 | lnp = win->alines[win->cury]; | 209 | lnp = win->alines[win->cury]; | |
210 | lnp->flags |= __ISDIRTY; | 210 | lnp->flags |= __ISDIRTY; | |
211 | if (win->ch_off < *lnp->firstchp) | 211 | if (win->ch_off < *lnp->firstchp) | |
212 | *lnp->firstchp = win->ch_off; | 212 | *lnp->firstchp = win->ch_off; | |
213 | if (win->ch_off + win->maxx - 1 > *lnp->lastchp) | 213 | if (win->ch_off + win->maxx - 1 > *lnp->lastchp) | |
214 | *lnp->lastchp = win->ch_off + win->maxx - 1; | 214 | *lnp->lastchp = win->ch_off + win->maxx - 1; | |
215 | __touchline(win, (int)win->cury, (int)win->curx, (int)win->maxx - 1); | 215 | __touchline(win, (int)win->cury, (int)win->curx, (int)win->maxx - 1); | |
216 | __sync(win); | 216 | __sync(win); | |
217 | return OK; | 217 | return OK; | |
218 | } | 218 | } |