Tue Jul 7 12:48:42 2020 UTC ()
Pull up following revision(s) (requested by uwe in ticket #1567):

	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.


(martin)
diff -r1.11 -r1.11.4.1 src/lib/libcurses/ins_wch.c
diff -r1.11 -r1.11.4.1 src/lib/libcurses/ins_wstr.c
diff -r1.23 -r1.23.6.1 src/lib/libcurses/insch.c
diff -r1.5 -r1.5.6.1 src/lib/libcurses/insstr.c

cvs diff -r1.11 -r1.11.4.1 src/lib/libcurses/ins_wch.c (switch to unified diff)

--- src/lib/libcurses/ins_wch.c 2017/01/31 09:17:53 1.11
+++ src/lib/libcurses/ins_wch.c 2020/07/07 12:48:42 1.11.4.1
@@ -1,253 +1,253 @@ @@ -1,253 +1,253 @@
1/* $NetBSD: ins_wch.c,v 1.11 2017/01/31 09:17:53 roy Exp $ */ 1/* $NetBSD: ins_wch.c,v 1.11.4.1 2020/07/07 12:48:42 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.11 2017/01/31 09:17:53 roy Exp $"); 39__RCSID("$NetBSD: ins_wch.c,v 1.11.4.1 2020/07/07 12:48:42 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 */
52int 52int
53ins_wch(const cchar_t *wch) 53ins_wch(const cchar_t *wch)
54{ 54{
55#ifndef HAVE_WCHAR 55#ifndef HAVE_WCHAR
56 return ERR; 56 return ERR;
57#else 57#else
58 return wins_wch(stdscr, wch); 58 return wins_wch(stdscr, wch);
59#endif /* HAVE_WCHAR */ 59#endif /* HAVE_WCHAR */
60} 60}
61 61
62/* 62/*
63 * mvins_wch -- 63 * mvins_wch --
64 * Do an insert-char on the line at (y, x). 64 * Do an insert-char on the line at (y, x).
65 */ 65 */
66int 66int
67mvins_wch(int y, int x, const cchar_t *wch) 67mvins_wch(int y, int x, const cchar_t *wch)
68{ 68{
69#ifndef HAVE_WCHAR 69#ifndef HAVE_WCHAR
70 return ERR; 70 return ERR;
71#else 71#else
72 return mvwins_wch(stdscr, y, x, wch); 72 return mvwins_wch(stdscr, y, x, wch);
73#endif /* HAVE_WCHAR */ 73#endif /* HAVE_WCHAR */
74} 74}
75 75
76/* 76/*
77 * mvwins_wch -- 77 * mvwins_wch --
78 * Do an insert-char on the line at (y, x) in the given window. 78 * Do an insert-char on the line at (y, x) in the given window.
79 */ 79 */
80int 80int
81mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) 81mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch)
82{ 82{
83#ifndef HAVE_WCHAR 83#ifndef HAVE_WCHAR
84 return ERR; 84 return ERR;
85#else 85#else
86 if (wmove(win, y, x) == ERR) 86 if (wmove(win, y, x) == ERR)
87 return ERR; 87 return ERR;
88 88
89 return wins_wch(stdscr, wch); 89 return wins_wch(win, wch);
90#endif /* HAVE_WCHAR */ 90#endif /* HAVE_WCHAR */
91} 91}
92 92
93/* 93/*
94 * wins_wch -- 94 * wins_wch --
95 * Do an insert-char on the line, leaving (cury, curx) unchanged. 95 * Do an insert-char on the line, leaving (cury, curx) unchanged.
96 */ 96 */
97int 97int
98wins_wch(WINDOW *win, const cchar_t *wch) 98wins_wch(WINDOW *win, const cchar_t *wch)
99{ 99{
100#ifndef HAVE_WCHAR 100#ifndef HAVE_WCHAR
101 return ERR; 101 return ERR;
102#else 102#else
103 __LDATA *start, *temp1, *temp2; 103 __LDATA *start, *temp1, *temp2;
104 __LINE *lnp; 104 __LINE *lnp;
105 int cw, pcw, x, y, sx, ex, newx, i; 105 int cw, pcw, x, y, sx, ex, newx, i;
106 nschar_t *np, *tnp; 106 nschar_t *np, *tnp;
107 wchar_t ws[] = L" "; 107 wchar_t ws[] = L" ";
108 108
109 /* check for non-spacing characters */ 109 /* check for non-spacing characters */
110 if (!wch) 110 if (!wch)
111 return OK; 111 return OK;
112 cw = wcwidth(wch->vals[0]); 112 cw = wcwidth(wch->vals[0]);
113 if (cw < 0) 113 if (cw < 0)
114 cw = 1; 114 cw = 1;
115 if (!cw) 115 if (!cw)
116 return wadd_wch( win, wch ); 116 return wadd_wch( win, wch );
117 117
118#ifdef DEBUG 118#ifdef DEBUG
119 __CTRACE(__CTRACE_INPUT, "--before--\n"); 119 __CTRACE(__CTRACE_INPUT, "--before--\n");
120 for (x = 0; x < win->maxx; x++) 120 for (x = 0; x < win->maxx; x++)
121 __CTRACE(__CTRACE_INPUT, "wins_wch: (0,%d)=(%x,%x,%p)\n", x, 121 __CTRACE(__CTRACE_INPUT, "wins_wch: (0,%d)=(%x,%x,%p)\n", x,
122 win->alines[0]->line[x].ch, 122 win->alines[0]->line[x].ch,
123 win->alines[0]->line[x].attr, 123 win->alines[0]->line[x].attr,
124 win->alines[0]->line[x].nsp); 124 win->alines[0]->line[x].nsp);
125#endif /* DEBUG */ 125#endif /* DEBUG */
126 x = win->curx; 126 x = win->curx;
127 y = win->cury; 127 y = win->cury;
128#ifdef DEBUG 128#ifdef DEBUG
129 __CTRACE(__CTRACE_INPUT, "wins_wch: (%d,%d)\n", y, x); 129 __CTRACE(__CTRACE_INPUT, "wins_wch: (%d,%d)\n", y, x);
130#endif /* DEBUG */ 130#endif /* DEBUG */
131 switch (wch->vals[0]) { 131 switch (wch->vals[0]) {
132 case L'\b': 132 case L'\b':
133 if (--x < 0) 133 if (--x < 0)
134 x = 0; 134 x = 0;
135 win->curx = x; 135 win->curx = x;
136 return OK; 136 return OK;
137 case L'\r': 137 case L'\r':
138 win->curx = 0; 138 win->curx = 0;
139 return OK; 139 return OK;
140 case L'\n': 140 case L'\n':
141 wclrtoeol(win); 141 wclrtoeol(win);
142 if (y == win->scr_b) { 142 if (y == win->scr_b) {
143 if (!(win->flags & __SCROLLOK)) 143 if (!(win->flags & __SCROLLOK))
144 return ERR; 144 return ERR;
145 scroll(win); 145 scroll(win);
146 } 146 }
147 return OK; 147 return OK;
148 case L'\t': 148 case L'\t':
149 if (wins_nwstr(win, ws, min(win->maxx - x, 149 if (wins_nwstr(win, ws, min(win->maxx - x,
150 TABSIZE - (x % TABSIZE))) == ERR) 150 TABSIZE - (x % TABSIZE))) == ERR)
151 return ERR; 151 return ERR;
152 return OK; 152 return OK;
153 } 153 }
154 154
155 /* locate current cell */ 155 /* locate current cell */
156 x = win->curx; 156 x = win->curx;
157 y = win->cury; 157 y = win->cury;
158 lnp = win->alines[y]; 158 lnp = win->alines[y];
159 start = &win->alines[y]->line[x]; 159 start = &win->alines[y]->line[x];
160 sx = x; 160 sx = x;
161 pcw = WCOL(*start); 161 pcw = WCOL(*start);
162 if (pcw < 0) { 162 if (pcw < 0) {
163 start += pcw; 163 start += pcw;
164 sx += pcw; 164 sx += pcw;
165 } 165 }
166 if (cw > win->maxx - sx) 166 if (cw > win->maxx - sx)
167 return ERR; 167 return ERR;
168 lnp->flags |= __ISDIRTY; 168 lnp->flags |= __ISDIRTY;
169 newx = sx + win->ch_off; 169 newx = sx + win->ch_off;
170 if (newx < *lnp->firstchp) 170 if (newx < *lnp->firstchp)
171 *lnp->firstchp = newx; 171 *lnp->firstchp = newx;
172 172
173 /* shift all complete characters */ 173 /* shift all complete characters */
174#ifdef DEBUG 174#ifdef DEBUG
175 __CTRACE(__CTRACE_INPUT, "wins_wch: shift all characters\n"); 175 __CTRACE(__CTRACE_INPUT, "wins_wch: shift all characters\n");
176#endif /* DEBUG */ 176#endif /* DEBUG */
177 temp1 = &win->alines[y]->line[win->maxx - 1]; 177 temp1 = &win->alines[y]->line[win->maxx - 1];
178 temp2 = temp1 - cw; 178 temp2 = temp1 - cw;
179 pcw = WCOL(*(temp2 + 1)); 179 pcw = WCOL(*(temp2 + 1));
180 if (pcw < 0) { 180 if (pcw < 0) {
181#ifdef DEBUG 181#ifdef DEBUG
182 __CTRACE(__CTRACE_INPUT, "wins_wch: clear EOL\n"); 182 __CTRACE(__CTRACE_INPUT, "wins_wch: clear EOL\n");
183#endif /* DEBUG */ 183#endif /* DEBUG */
184 temp2 += pcw; 184 temp2 += pcw;
185 while (temp1 > temp2 + cw) { 185 while (temp1 > temp2 + cw) {
186 np = temp1->nsp; 186 np = temp1->nsp;
187 if (np) { 187 if (np) {
188 while (np) { 188 while (np) {
189 tnp = np->next; 189 tnp = np->next;
190 free(np); 190 free(np);
191 np = tnp; 191 np = tnp;
192 } 192 }
193 temp1->nsp = NULL; 193 temp1->nsp = NULL;
194 } 194 }
195 temp1->ch = (wchar_t)btowc((int)win->bch ); 195 temp1->ch = (wchar_t)btowc((int)win->bch );
196 if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) 196 if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR)
197 return ERR; 197 return ERR;
198 temp1->attr = win->battr; 198 temp1->attr = win->battr;
199 SET_WCOL(*temp1, 1); 199 SET_WCOL(*temp1, 1);
200 temp1--; 200 temp1--;
201 } 201 }
202 } 202 }
203 while (temp2 >= start) { 203 while (temp2 >= start) {
204 (void)memcpy(temp1, temp2, sizeof(__LDATA)); 204 (void)memcpy(temp1, temp2, sizeof(__LDATA));
205 temp1--, temp2--; 205 temp1--, temp2--;
206 } 206 }
207 207
208 /* update character under cursor */ 208 /* update character under cursor */
209 start->nsp = NULL; 209 start->nsp = NULL;
210 start->ch = wch->vals[0]; 210 start->ch = wch->vals[0];
211 start->attr = wch->attributes & WA_ATTRIBUTES; 211 start->attr = wch->attributes & WA_ATTRIBUTES;
212 SET_WCOL(*start, cw); 212 SET_WCOL(*start, cw);
213 if (wch->elements > 1) { 213 if (wch->elements > 1) {
214 for (i = 1; i < wch->elements; i++) { 214 for (i = 1; i < wch->elements; i++) {
215 np = malloc(sizeof(nschar_t)); 215 np = malloc(sizeof(nschar_t));
216 if (!np) 216 if (!np)
217 return ERR; 217 return ERR;
218 np->ch = wch->vals[i]; 218 np->ch = wch->vals[i];
219 np->next = start->nsp; 219 np->next = start->nsp;
220 start->nsp = np; 220 start->nsp = np;
221 } 221 }
222 } 222 }
223#ifdef DEBUG 223#ifdef DEBUG
224 __CTRACE(__CTRACE_INPUT, "wins_wch: insert (%x,%x,%p)\n", 224 __CTRACE(__CTRACE_INPUT, "wins_wch: insert (%x,%x,%p)\n",
225 start->ch, start->attr, start->nsp); 225 start->ch, start->attr, start->nsp);
226#endif /* DEBUG */ 226#endif /* DEBUG */
227 temp1 = start + 1; 227 temp1 = start + 1;
228 ex = x + 1; 228 ex = x + 1;
229 while (ex - x < cw) { 229 while (ex - x < cw) {
230 temp1->ch = wch->vals[0]; 230 temp1->ch = wch->vals[0];
231 SET_WCOL(*temp1, x - ex); 231 SET_WCOL(*temp1, x - ex);
232 temp1->nsp = NULL; 232 temp1->nsp = NULL;
233 ex++, temp1++; 233 ex++, temp1++;
234 } 234 }
235#ifdef DEBUG 235#ifdef DEBUG
236 { 236 {
237 __CTRACE(__CTRACE_INPUT, "--after---\n"); 237 __CTRACE(__CTRACE_INPUT, "--after---\n");
238 for (x = 0; x < win->maxx; x++) 238 for (x = 0; x < win->maxx; x++)
239 __CTRACE(__CTRACE_INPUT, 239 __CTRACE(__CTRACE_INPUT,
240 "wins_wch: (0,%d)=(%x,%x,%p)\n", x, 240 "wins_wch: (0,%d)=(%x,%x,%p)\n", x,
241 win->alines[0]->line[x].ch, 241 win->alines[0]->line[x].ch,
242 win->alines[0]->line[x].attr, 242 win->alines[0]->line[x].attr,
243 win->alines[0]->line[x].nsp); 243 win->alines[0]->line[x].nsp);
244 } 244 }
245#endif /* DEBUG */ 245#endif /* DEBUG */
246 newx = win->maxx - 1 + win->ch_off; 246 newx = win->maxx - 1 + win->ch_off;
247 if (newx > *lnp->lastchp) 247 if (newx > *lnp->lastchp)
248 *lnp->lastchp = newx; 248 *lnp->lastchp = newx;
249 __touchline(win, y, sx, (int)win->maxx - 1); 249 __touchline(win, y, sx, (int)win->maxx - 1);
250 __sync(win); 250 __sync(win);
251 return OK; 251 return OK;
252#endif /* HAVE_WCHAR */ 252#endif /* HAVE_WCHAR */
253} 253}

cvs diff -r1.11 -r1.11.4.1 src/lib/libcurses/ins_wstr.c (switch to unified diff)

--- src/lib/libcurses/ins_wstr.c 2017/01/31 09:17:53 1.11
+++ src/lib/libcurses/ins_wstr.c 2020/07/07 12:48:42 1.11.4.1
@@ -1,334 +1,334 @@ @@ -1,334 +1,334 @@
1/* $NetBSD: ins_wstr.c,v 1.11 2017/01/31 09:17:53 roy Exp $ */ 1/* $NetBSD: ins_wstr.c,v 1.11.4.1 2020/07/07 12:48:42 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.11 2017/01/31 09:17:53 roy Exp $"); 39__RCSID("$NetBSD: ins_wstr.c,v 1.11.4.1 2020/07/07 12:48:42 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 */
52int 52int
53ins_wstr(const wchar_t *wstr) 53ins_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 */
63int 63int
64ins_nwstr(const wchar_t *wstr, int n) 64ins_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 */
73int 73int
74mvins_wstr(int y, int x, const wchar_t *wstr) 74mvins_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 */
83int 83int
84mvins_nwstr(int y, int x, const wchar_t *wstr, int n) 84mvins_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 */
93int 93int
94mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) 94mvwins_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 */
106int 106int
107mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) 107mvwins_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 */
120int 120int
121wins_wstr(WINDOW *win, const wchar_t *wstr) 121wins_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 */
130int 130int
131wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) 131wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
132{ 132{
133#ifndef HAVE_WCHAR 133#ifndef HAVE_WCHAR
134 return ERR; 134 return ERR;
135#else 135#else
136 __LDATA *start, *temp1, *temp2; 136 __LDATA *start, *temp1, *temp2;
137 __LINE *lnp; 137 __LINE *lnp;
138 const wchar_t *scp; 138 const wchar_t *scp;
139 int width, len, sx, x, y, cw, pcw, newx; 139 int width, len, sx, x, y, cw, pcw, newx;
140 nschar_t *np; 140 nschar_t *np;
141 wchar_t ws[] = L" "; 141 wchar_t ws[] = L" ";
142 142
143 /* check for leading non-spacing character */ 143 /* check for leading non-spacing character */
144 if (!wstr) 144 if (!wstr)
145 return OK; 145 return OK;
146 cw = wcwidth(*wstr); 146 cw = wcwidth(*wstr);
147 if (cw < 0) 147 if (cw < 0)
148 cw = 1; 148 cw = 1;
149 if (!cw) 149 if (!cw)
150 return ERR; 150 return ERR;
151 151
152 scp = wstr + 1; 152 scp = wstr + 1;
153 width = cw; 153 width = cw;
154 len = 1; 154 len = 1;
155 n--; 155 n--;
156 while (*scp) { 156 while (*scp) {
157 int w; 157 int w;
158 if (!n) 158 if (!n)
159 break; 159 break;
160 w = wcwidth(*scp); 160 w = wcwidth(*scp);
161 if (w < 0) 161 if (w < 0)
162 w = 1; 162 w = 1;
163 n--, len++, width += w; 163 n--, len++, width += w;
164 scp++; 164 scp++;
165 } 165 }
166#ifdef DEBUG 166#ifdef DEBUG
167 __CTRACE(__CTRACE_INPUT, "wins_nwstr: width=%d,len=%d\n", width, len); 167 __CTRACE(__CTRACE_INPUT, "wins_nwstr: width=%d,len=%d\n", width, len);
168#endif /* DEBUG */ 168#endif /* DEBUG */
169 169
170 if (cw > win->maxx - win->curx + 1) 170 if (cw > win->maxx - win->curx + 1)
171 return ERR; 171 return ERR;
172 start = &win->alines[win->cury]->line[win->curx]; 172 start = &win->alines[win->cury]->line[win->curx];
173 sx = win->curx; 173 sx = win->curx;
174 lnp = win->alines[win->cury]; 174 lnp = win->alines[win->cury];
175 pcw = WCOL(*start); 175 pcw = WCOL(*start);
176 if (pcw < 0) { 176 if (pcw < 0) {
177 sx += pcw; 177 sx += pcw;
178 start += pcw; 178 start += pcw;
179 } 179 }
180#ifdef DEBUG 180#ifdef DEBUG
181 __CTRACE(__CTRACE_INPUT, "wins_nwstr: start@(%d)\n", sx); 181 __CTRACE(__CTRACE_INPUT, "wins_nwstr: start@(%d)\n", sx);
182#endif /* DEBUG */ 182#endif /* DEBUG */
183 pcw = WCOL(*start); 183 pcw = WCOL(*start);
184 lnp->flags |= __ISDIRTY; 184 lnp->flags |= __ISDIRTY;
185 newx = sx + win->ch_off; 185 newx = sx + win->ch_off;
186 if (newx < *lnp->firstchp) 186 if (newx < *lnp->firstchp)
187 *lnp->firstchp = newx; 187 *lnp->firstchp = newx;
188#ifdef DEBUG 188#ifdef DEBUG
189 { 189 {
190 __CTRACE(__CTRACE_INPUT, "========before=======\n"); 190 __CTRACE(__CTRACE_INPUT, "========before=======\n");
191 for (x = 0; x < win->maxx; x++) 191 for (x = 0; x < win->maxx; x++)
192 __CTRACE(__CTRACE_INPUT, 192 __CTRACE(__CTRACE_INPUT,
193 "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", 193 "wins_nwstr: (%d,%d)=(%x,%x,%p)\n",
194 (int) win->cury, x, 194 (int) win->cury, x,
195 win->alines[win->cury]->line[x].ch, 195 win->alines[win->cury]->line[x].ch,
196 win->alines[win->cury]->line[x].attr, 196 win->alines[win->cury]->line[x].attr,
197 win->alines[win->cury]->line[x].nsp); 197 win->alines[win->cury]->line[x].nsp);
198 } 198 }
199#endif /* DEBUG */ 199#endif /* DEBUG */
200 200
201 /* shift all complete characters */ 201 /* shift all complete characters */
202 if (sx + width + pcw <= win->maxx) { 202 if (sx + width + pcw <= win->maxx) {
203#ifdef DEBUG 203#ifdef DEBUG
204 __CTRACE(__CTRACE_INPUT, "wins_nwstr: shift all characters\n"); 204 __CTRACE(__CTRACE_INPUT, "wins_nwstr: shift all characters\n");
205#endif /* DEBUG */ 205#endif /* DEBUG */
206 temp1 = &win->alines[win->cury]->line[win->maxx - 1]; 206 temp1 = &win->alines[win->cury]->line[win->maxx - 1];
207 temp2 = temp1 - width; 207 temp2 = temp1 - width;
208 pcw = WCOL(*(temp2 + 1)); 208 pcw = WCOL(*(temp2 + 1));
209 if (pcw < 0) { 209 if (pcw < 0) {
210#ifdef DEBUG 210#ifdef DEBUG
211 __CTRACE(__CTRACE_INPUT, 211 __CTRACE(__CTRACE_INPUT,
212 "wins_nwstr: clear from %d to EOL(%d)\n", 212 "wins_nwstr: clear from %d to EOL(%d)\n",
213 win->maxx + pcw, win->maxx - 1); 213 win->maxx + pcw, win->maxx - 1);
214#endif /* DEBUG */ 214#endif /* DEBUG */
215 temp2 += pcw; 215 temp2 += pcw;
216 while (temp1 > temp2 + width) { 216 while (temp1 > temp2 + width) {
217 temp1->ch = (wchar_t)btowc((int) win->bch); 217 temp1->ch = (wchar_t)btowc((int) win->bch);
218 if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) 218 if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR)
219 return ERR; 219 return ERR;
220 temp1->attr = win->battr; 220 temp1->attr = win->battr;
221 SET_WCOL(*temp1, 1); 221 SET_WCOL(*temp1, 1);
222#ifdef DEBUG 222#ifdef DEBUG
223 __CTRACE(__CTRACE_INPUT, 223 __CTRACE(__CTRACE_INPUT,
224 "wins_nwstr: empty cell(%p)\n", temp1); 224 "wins_nwstr: empty cell(%p)\n", temp1);
225#endif /* DEBUG */ 225#endif /* DEBUG */
226 temp1--; 226 temp1--;
227 } 227 }
228 } 228 }
229 while (temp2 >= start) { 229 while (temp2 >= start) {
230 (void)memcpy(temp1, temp2, sizeof(__LDATA)); 230 (void)memcpy(temp1, temp2, sizeof(__LDATA));
231 temp1--, temp2--; 231 temp1--, temp2--;
232 } 232 }
233#ifdef DEBUG 233#ifdef DEBUG
234 { 234 {
235 __CTRACE(__CTRACE_INPUT, "=====after shift====\n"); 235 __CTRACE(__CTRACE_INPUT, "=====after shift====\n");
236 for (x = 0; x < win->maxx; x++) 236 for (x = 0; x < win->maxx; x++)
237 __CTRACE(__CTRACE_INPUT, 237 __CTRACE(__CTRACE_INPUT,
238 "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", 238 "wins_nwstr: (%d,%d)=(%x,%x,%p)\n",
239 (int) win->cury, x, 239 (int) win->cury, x,
240 win->alines[win->cury]->line[x].ch, 240 win->alines[win->cury]->line[x].ch,
241 win->alines[win->cury]->line[x].attr, 241 win->alines[win->cury]->line[x].attr,
242 win->alines[win->cury]->line[x].nsp); 242 win->alines[win->cury]->line[x].nsp);
243 } 243 }
244#endif /* DEBUG */ 244#endif /* DEBUG */
245 } 245 }
246 246
247 /* update string columns */ 247 /* update string columns */
248 x = win->curx; 248 x = win->curx;
249 y = win->cury; 249 y = win->cury;
250 for (scp = wstr, temp1 = start; len; len--, scp++) { 250 for (scp = wstr, temp1 = start; len; len--, scp++) {
251 switch (*scp) { 251 switch (*scp) {
252 case L'\b': 252 case L'\b':
253 if (--x < 0) 253 if (--x < 0)
254 x = 0; 254 x = 0;
255 win->curx = x; 255 win->curx = x;
256 continue;; 256 continue;;
257 case L'\r': 257 case L'\r':
258 win->curx = 0; 258 win->curx = 0;
259 continue; 259 continue;
260 case L'\n': 260 case L'\n':
261 wclrtoeol(win); 261 wclrtoeol(win);
262 if (y == win->scr_b) { 262 if (y == win->scr_b) {
263 if (!(win->flags & __SCROLLOK)) 263 if (!(win->flags & __SCROLLOK))
264 return ERR; 264 return ERR;
265 scroll(win); 265 scroll(win);
266 } 266 }
267 continue; 267 continue;
268 case L'\t': 268 case L'\t':
269 if (wins_nwstr(win, ws, 269 if (wins_nwstr(win, ws,
270 min(win->maxx - x, TABSIZE - (x % TABSIZE))) 270 min(win->maxx - x, TABSIZE - (x % TABSIZE)))
271 == ERR) 271 == ERR)
272 return ERR; 272 return ERR;
273 continue; 273 continue;
274 } 274 }
275 cw = wcwidth(*scp); 275 cw = wcwidth(*scp);
276 if (cw < 0) 276 if (cw < 0)
277 cw = 1; 277 cw = 1;
278 if (cw) { 278 if (cw) {
279 /* 1st column */ 279 /* 1st column */
280 temp1->ch = (wchar_t)*scp; 280 temp1->ch = (wchar_t)*scp;
281 temp1->attr = win->wattr; 281 temp1->attr = win->wattr;
282 SET_WCOL(*temp1, cw); 282 SET_WCOL(*temp1, cw);
283 temp1->nsp = NULL; 283 temp1->nsp = NULL;
284#ifdef DEBUG 284#ifdef DEBUG
285 __CTRACE(__CTRACE_INPUT, 285 __CTRACE(__CTRACE_INPUT,
286 "wins_nwstr: add spacing char(%x)\n", temp1->ch); 286 "wins_nwstr: add spacing char(%x)\n", temp1->ch);
287#endif /* DEBUG */ 287#endif /* DEBUG */
288 temp2 = temp1++; 288 temp2 = temp1++;
289 if (cw > 1) { 289 if (cw > 1) {
290 x = -1; 290 x = -1;
291 while (temp1 < temp2 + cw) { 291 while (temp1 < temp2 + cw) {
292 /* the rest columns */ 292 /* the rest columns */
293 temp1->ch = (wchar_t)*scp; 293 temp1->ch = (wchar_t)*scp;
294 temp1->attr = win->wattr; 294 temp1->attr = win->wattr;
295 temp1->nsp = NULL; 295 temp1->nsp = NULL;
296 SET_WCOL(*temp1, x); 296 SET_WCOL(*temp1, x);
297 temp1++, x--; 297 temp1++, x--;
298 } 298 }
299 temp1--; 299 temp1--;
300 } 300 }
301 } else { 301 } else {
302 /* non-spacing character */ 302 /* non-spacing character */
303 np = malloc(sizeof(nschar_t)); 303 np = malloc(sizeof(nschar_t));
304 if (!np) 304 if (!np)
305 return ERR; 305 return ERR;
306 np->ch = *scp; 306 np->ch = *scp;
307 np->next = temp1->nsp; 307 np->next = temp1->nsp;
308 temp1->nsp = np; 308 temp1->nsp = np;
309#ifdef DEBUG 309#ifdef DEBUG
310 __CTRACE(__CTRACE_INPUT, 310 __CTRACE(__CTRACE_INPUT,
311 "wins_nstr: add non-spacing char(%x)\n", np->ch); 311 "wins_nstr: add non-spacing char(%x)\n", np->ch);
312#endif /* DEBUG */ 312#endif /* DEBUG */
313 } 313 }
314 } 314 }
315#ifdef DEBUG 315#ifdef DEBUG
316 { 316 {
317 __CTRACE(__CTRACE_INPUT, "========after=======\n"); 317 __CTRACE(__CTRACE_INPUT, "========after=======\n");
318 for (x = 0; x < win->maxx; x++) 318 for (x = 0; x < win->maxx; x++)
319 __CTRACE(__CTRACE_INPUT, 319 __CTRACE(__CTRACE_INPUT,
320 "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", 320 "wins_nwstr: (%d,%d)=(%x,%x,%p)\n",
321 (int) win->cury, x, 321 (int) win->cury, x,
322 win->alines[win->cury]->line[x].ch, 322 win->alines[win->cury]->line[x].ch,
323 win->alines[win->cury]->line[x].attr, 323 win->alines[win->cury]->line[x].attr,
324 win->alines[win->cury]->line[x].nsp); 324 win->alines[win->cury]->line[x].nsp);
325 } 325 }
326#endif /* DEBUG */ 326#endif /* DEBUG */
327 newx = win->maxx - 1 + win->ch_off; 327 newx = win->maxx - 1 + win->ch_off;
328 if (newx > *lnp->lastchp) 328 if (newx > *lnp->lastchp)
329 *lnp->lastchp = newx; 329 *lnp->lastchp = newx;
330 __touchline(win, (int) win->cury, sx, (int) win->maxx - 1); 330 __touchline(win, (int) win->cury, sx, (int) win->maxx - 1);
331 __sync(win); 331 __sync(win);
332 return OK; 332 return OK;
333#endif /* HAVE_WCHAR */ 333#endif /* HAVE_WCHAR */
334} 334}

cvs diff -r1.23 -r1.23.6.1 src/lib/libcurses/insch.c (switch to unified diff)

--- src/lib/libcurses/insch.c 2017/01/06 13:53:18 1.23
+++ src/lib/libcurses/insch.c 2020/07/07 12:48:42 1.23.6.1
@@ -1,133 +1,133 @@ @@ -1,133 +1,133 @@
1/* $NetBSD: insch.c,v 1.23 2017/01/06 13:53:18 roy Exp $ */ 1/* $NetBSD: insch.c,v 1.23.6.1 2020/07/07 12:48:42 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
35static char sccsid[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94"; 35static char sccsid[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94";
36#else 36#else
37__RCSID("$NetBSD: insch.c,v 1.23 2017/01/06 13:53:18 roy Exp $"); 37__RCSID("$NetBSD: insch.c,v 1.23.6.1 2020/07/07 12:48:42 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 */
53int 53int
54insch(chtype ch) 54insch(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 */
64int 64int
65mvinsch(int y, int x, chtype ch) 65mvinsch(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 */
75int 75int
76mvwinsch(WINDOW *win, int y, int x, chtype ch) 76mvwinsch(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 */
91int 91int
92winsch(WINDOW *win, chtype ch) 92winsch(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}

cvs diff -r1.5 -r1.5.6.1 src/lib/libcurses/insstr.c (switch to unified diff)

--- src/lib/libcurses/insstr.c 2017/01/06 13:53:18 1.5
+++ src/lib/libcurses/insstr.c 2020/07/07 12:48:42 1.5.6.1
@@ -1,218 +1,218 @@ @@ -1,218 +1,218 @@
1/* $NetBSD: insstr.c,v 1.5 2017/01/06 13:53:18 roy Exp $ */ 1/* $NetBSD: insstr.c,v 1.5.6.1 2020/07/07 12:48:42 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.5 2017/01/06 13:53:18 roy Exp $"); 39__RCSID("$NetBSD: insstr.c,v 1.5.6.1 2020/07/07 12:48:42 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 */
54int 54int
55insstr(const char *str) 55insstr(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 */
66int 66int
67insnstr(const char *str, int n) 67insnstr(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 */
77int 77int
78mvinsstr(int y, int x, const char *str) 78mvinsstr(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 */
88int 88int
89mvinsnstr(int y, int x, const char *str, int n) 89mvinsnstr(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 */
99int 99int
100mvwinsstr(WINDOW *win, int y, int x, const char *str) 100mvwinsstr(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 */
113int 113int
114mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) 114mvwinsnstr(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 */
130int 130int
131winsstr(WINDOW *win, const char *str) 131winsstr(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 */
142int 142int
143winsnstr(WINDOW *win, const char *str, int n) 143winsnstr(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}