msg_sys.def revision 1.35 1 1.35 dsl /* $NetBSD: msg_sys.def,v 1.35 2006/09/06 19:13:51 dsl Exp $ */
2 1.1 phil
3 1.1 phil /*
4 1.1 phil * Copyright 1997 Piermont Information Systems Inc.
5 1.1 phil * All rights reserved.
6 1.1 phil *
7 1.1 phil * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 1.1 phil *
9 1.1 phil * Redistribution and use in source and binary forms, with or without
10 1.1 phil * modification, are permitted provided that the following conditions
11 1.1 phil * are met:
12 1.1 phil * 1. Redistributions of source code must retain the above copyright
13 1.1 phil * notice, this list of conditions and the following disclaimer.
14 1.1 phil * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 phil * notice, this list of conditions and the following disclaimer in the
16 1.1 phil * documentation and/or other materials provided with the distribution.
17 1.1 phil * 3. All advertising materials mentioning features or use of this software
18 1.1 phil * must display the following acknowledgement:
19 1.1 phil * This product includes software develooped for the NetBSD Project by
20 1.1 phil * Piermont Information Systems Inc.
21 1.1 phil * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22 1.1 phil * or promote products derived from this software without specific prior
23 1.1 phil * written permission.
24 1.1 phil *
25 1.1 phil * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 1.1 phil * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 phil * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 phil * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 1.1 phil * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 phil * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 phil * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 phil * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 phil * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 phil * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 1.1 phil * THE POSSIBILITY OF SUCH DAMAGE.
36 1.1 phil *
37 1.1 phil */
38 1.1 phil
39 1.1 phil static WINDOW *msg_win = NULL;
40 1.6 cgd static char *cbuffer;
41 1.6 cgd static size_t cbuffersize;
42 1.1 phil
43 1.8 cgd static int last_i_was_nl, last_i_was_space;
44 1.8 cgd static int last_o_was_punct, last_o_was_space;
45 1.7 cgd
46 1.14 cgd static void _msg_beep(void);
47 1.21 dsl static int _msg_vprintf(int, const char *, va_list);
48 1.27 dsl #define MSG_PROMPT_ECHO 1
49 1.27 dsl #define MSG_PROMPT_HIDE_DFLT 2
50 1.21 dsl static void _msg_vprompt(const char *, int, const char *, char *,
51 1.21 dsl size_t, va_list);
52 1.21 dsl
53 1.21 dsl static char *msgmap = MAP_FAILED;
54 1.21 dsl static size_t msgmapsz;
55 1.21 dsl static int msgmapcount;
56 1.12 cgd
57 1.1 phil /* Routines */
58 1.1 phil
59 1.14 cgd static void
60 1.15 cgd _msg_beep(void)
61 1.1 phil {
62 1.21 dsl
63 1.14 cgd fprintf(stderr, "\a");
64 1.1 phil }
65 1.1 phil
66 1.20 dsl WINDOW *
67 1.20 dsl msg_window(WINDOW *window)
68 1.1 phil {
69 1.6 cgd size_t ncbuffersize;
70 1.6 cgd char *ncbuffer;
71 1.20 dsl WINDOW *old;
72 1.6 cgd
73 1.20 dsl old = msg_win;
74 1.20 dsl if (!window)
75 1.20 dsl return old;
76 1.1 phil msg_win = window;
77 1.6 cgd
78 1.6 cgd ncbuffersize = getmaxx(window) * getmaxy(window) + 1;
79 1.20 dsl while (ncbuffersize > cbuffersize) {
80 1.6 cgd ncbuffer = malloc(ncbuffersize);
81 1.20 dsl if (ncbuffer == NULL) {
82 1.20 dsl /* we might get truncated messages... */
83 1.20 dsl ncbuffersize <<= 1;
84 1.20 dsl continue;
85 1.20 dsl }
86 1.6 cgd if (cbuffer != NULL)
87 1.6 cgd free(cbuffer);
88 1.6 cgd cbuffer = ncbuffer;
89 1.6 cgd cbuffersize = ncbuffersize;
90 1.20 dsl break;
91 1.6 cgd }
92 1.20 dsl last_o_was_punct = 0;
93 1.20 dsl last_o_was_space = 1;
94 1.20 dsl return old;
95 1.1 phil }
96 1.1 phil
97 1.21 dsl int
98 1.21 dsl msg_file(const char *file)
99 1.21 dsl {
100 1.21 dsl int fd;
101 1.21 dsl
102 1.21 dsl if (msgmap != MAP_FAILED)
103 1.21 dsl munmap(msgmap, msgmapsz);
104 1.21 dsl msgmap = MAP_FAILED;
105 1.21 dsl if (!file)
106 1.21 dsl return 0;
107 1.21 dsl fd = open(file, O_RDONLY, 0);
108 1.21 dsl if (fd == -1)
109 1.21 dsl return -1;
110 1.21 dsl msgmapsz = lseek(fd, 0, SEEK_END);
111 1.21 dsl msgmap = mmap(0, msgmapsz, PROT_READ, MAP_SHARED, fd, 0);
112 1.21 dsl close(fd);
113 1.21 dsl if (msgmap == MAP_FAILED)
114 1.21 dsl return -1;
115 1.21 dsl /* check_magic */
116 1.22 dsl if (strcmp(msgmap, "MSGTXTS") != 0) {
117 1.21 dsl msg_file(NULL);
118 1.21 dsl return -1;
119 1.21 dsl }
120 1.21 dsl msgmapcount = atoi(msgmap + 8);
121 1.21 dsl return 0;
122 1.21 dsl }
123 1.21 dsl
124 1.21 dsl const char *
125 1.21 dsl msg_string(msg msg_no)
126 1.1 phil {
127 1.19 dsl int m = (intptr_t)msg_no;
128 1.19 dsl
129 1.19 dsl if (m > sizeof msg_list / sizeof msg_list[0])
130 1.19 dsl /* guess that we were passed a text string */
131 1.19 dsl return msg_no;
132 1.21 dsl
133 1.21 dsl if (msgmap != MAP_FAILED && m != 0 && m <= msgmapcount) {
134 1.21 dsl unsigned int offset = atoi(msgmap + 8 + 8 * m);
135 1.21 dsl if (offset != 0 && offset < msgmapsz)
136 1.21 dsl return msgmap + offset;
137 1.21 dsl }
138 1.21 dsl
139 1.19 dsl return msg_list[m];
140 1.1 phil }
141 1.1 phil
142 1.21 dsl void
143 1.21 dsl msg_clear(void)
144 1.1 phil {
145 1.21 dsl
146 1.21 dsl wclear(msg_win);
147 1.8 cgd last_o_was_punct = 0;
148 1.8 cgd last_o_was_space = 1;
149 1.1 phil }
150 1.1 phil
151 1.21 dsl void
152 1.21 dsl msg_standout(void)
153 1.1 phil {
154 1.21 dsl
155 1.1 phil wstandout(msg_win);
156 1.1 phil }
157 1.1 phil
158 1.21 dsl void
159 1.21 dsl msg_standend(void)
160 1.1 phil {
161 1.21 dsl
162 1.1 phil wstandend(msg_win);
163 1.1 phil }
164 1.1 phil
165 1.12 cgd static int
166 1.16 cgd _msg_vprintf(int auto_fill, const char *fmt, va_list ap)
167 1.1 phil {
168 1.8 cgd const char *wstart, *afterw;
169 1.8 cgd int wordlen, nspaces;
170 1.1 phil int ret;
171 1.1 phil
172 1.21 dsl ret = vsnprintf(cbuffer, cbuffersize, fmt, ap);
173 1.8 cgd
174 1.10 cgd if (!auto_fill) {
175 1.10 cgd waddstr(msg_win, cbuffer);
176 1.10 cgd
177 1.10 cgd /*
178 1.10 cgd * nothing is perfect if they flow text after a table,
179 1.10 cgd * but this may be decent.
180 1.10 cgd */
181 1.10 cgd last_i_was_nl = last_i_was_space = 1;
182 1.10 cgd last_o_was_punct = 0;
183 1.10 cgd last_o_was_space = 1;
184 1.10 cgd goto out;
185 1.10 cgd }
186 1.10 cgd
187 1.8 cgd for (wstart = afterw = cbuffer; *wstart; wstart = afterw) {
188 1.8 cgd
189 1.8 cgd /* eat one space, or a whole word of non-spaces */
190 1.31 dsl if (isspace((unsigned char)*afterw))
191 1.8 cgd afterw++;
192 1.8 cgd else
193 1.31 dsl while (*afterw && !isspace((unsigned char)*afterw))
194 1.8 cgd afterw++;
195 1.8 cgd
196 1.8 cgd /* this is an nl: special formatting necessary */
197 1.8 cgd if (*wstart == '\n') {
198 1.8 cgd if (last_i_was_nl || last_i_was_space) {
199 1.8 cgd
200 1.8 cgd if (getcurx(msg_win) != 0)
201 1.8 cgd waddch(msg_win, '\n');
202 1.8 cgd if (last_i_was_nl) {
203 1.8 cgd /* last was an nl: paragraph break */
204 1.8 cgd waddch(msg_win, '\n');
205 1.8 cgd } else {
206 1.8 cgd /* last was space: line break */
207 1.8 cgd }
208 1.8 cgd last_o_was_punct = 0;
209 1.8 cgd last_o_was_space = 1;
210 1.8 cgd } else {
211 1.8 cgd /* last_o_was_punct unchanged */
212 1.8 cgd /* last_o_was_space unchanged */
213 1.8 cgd }
214 1.8 cgd last_i_was_space = 1;
215 1.8 cgd last_i_was_nl = 1;
216 1.8 cgd continue;
217 1.8 cgd }
218 1.8 cgd
219 1.8 cgd /* this is a tab: special formatting necessary. */
220 1.8 cgd if (*wstart == '\t') {
221 1.8 cgd if (last_i_was_nl) {
222 1.8 cgd /* last was an nl: list indent */
223 1.8 cgd if (getcurx(msg_win) != 0)
224 1.8 cgd waddch(msg_win, '\n');
225 1.8 cgd } else {
226 1.8 cgd /* last was not an nl: columns */
227 1.8 cgd }
228 1.8 cgd waddch(msg_win, '\t');
229 1.8 cgd last_i_was_nl = 0;
230 1.8 cgd last_i_was_space = 1;
231 1.8 cgd last_o_was_punct = 0;
232 1.8 cgd last_o_was_space = 1;
233 1.8 cgd continue;
234 1.8 cgd }
235 1.8 cgd
236 1.8 cgd /* this is a space: ignore it but set flags */
237 1.8 cgd last_i_was_nl = 0; /* all newlines handled above */
238 1.31 dsl last_i_was_space = isspace((unsigned char)*wstart);
239 1.8 cgd if (last_i_was_space)
240 1.8 cgd continue;
241 1.8 cgd
242 1.8 cgd /*
243 1.8 cgd * we have a real "word," i.e. a sequence of non-space
244 1.8 cgd * characters. wstart is now the start of the word,
245 1.8 cgd * afterw is the next character after the end.
246 1.8 cgd */
247 1.8 cgd wordlen = afterw - wstart;
248 1.8 cgd nspaces = last_o_was_space ? 0 : (last_o_was_punct ? 2 : 1);
249 1.8 cgd if ((getcurx(msg_win) + nspaces + wordlen) >=
250 1.8 cgd getmaxx(msg_win) &&
251 1.8 cgd wordlen < (getmaxx(msg_win) / 3)) {
252 1.8 cgd /* wrap the line */
253 1.8 cgd waddch(msg_win, '\n');
254 1.8 cgd nspaces = 0;
255 1.8 cgd }
256 1.8 cgd
257 1.8 cgd /* output the word, preceded by spaces if necessary */
258 1.8 cgd while (nspaces-- > 0)
259 1.8 cgd waddch(msg_win, ' ');
260 1.8 cgd waddbytes(msg_win, wstart, wordlen);
261 1.8 cgd
262 1.8 cgd /* set up the 'last' state for the next time around */
263 1.8 cgd switch (afterw[-1]) {
264 1.8 cgd case '.':
265 1.8 cgd case '?':
266 1.8 cgd case '!':
267 1.8 cgd last_o_was_punct = 1;
268 1.8 cgd break;
269 1.8 cgd default:
270 1.8 cgd last_o_was_punct = 0;
271 1.8 cgd break;
272 1.8 cgd }
273 1.8 cgd last_o_was_space = 0;
274 1.8 cgd
275 1.8 cgd /* ... and do it all again! */
276 1.8 cgd }
277 1.8 cgd
278 1.8 cgd /* String ended with a newline. They really want a line break. */
279 1.8 cgd if (last_i_was_nl) {
280 1.8 cgd if (getcurx(msg_win) != 0)
281 1.8 cgd waddch(msg_win, '\n');
282 1.8 cgd last_o_was_punct = 0;
283 1.8 cgd last_o_was_space = 1;
284 1.8 cgd }
285 1.8 cgd
286 1.10 cgd out:
287 1.21 dsl wrefresh(msg_win);
288 1.1 phil return ret;
289 1.1 phil }
290 1.1 phil
291 1.21 dsl void
292 1.21 dsl msg_display(msg msg_no, ...)
293 1.1 phil {
294 1.1 phil va_list ap;
295 1.1 phil
296 1.7 cgd msg_clear();
297 1.7 cgd
298 1.1 phil va_start(ap, msg_no);
299 1.16 cgd (void)_msg_vprintf(1, msg_string(msg_no), ap);
300 1.1 phil va_end(ap);
301 1.1 phil }
302 1.1 phil
303 1.21 dsl void
304 1.21 dsl msg_display_add(msg msg_no, ...)
305 1.1 phil {
306 1.1 phil va_list ap;
307 1.1 phil
308 1.21 dsl va_start(ap, msg_no);
309 1.16 cgd (void)_msg_vprintf(1, msg_string(msg_no), ap);
310 1.21 dsl va_end(ap);
311 1.1 phil }
312 1.1 phil
313 1.19 dsl static void
314 1.27 dsl _msg_vprompt(const char *fmt, int flags, const char *def, char *val,
315 1.35 dsl size_t val_buf_len, va_list ap)
316 1.1 phil {
317 1.1 phil int ch;
318 1.27 dsl int len, pos, npos, off;
319 1.27 dsl int first;
320 1.27 dsl int txt_y, txt_x;
321 1.35 dsl char *ibuf = alloca(val_buf_len);
322 1.27 dsl int maxx;
323 1.1 phil
324 1.27 dsl keypad(msg_win, TRUE);
325 1.24 dsl _msg_vprintf(0, fmt, ap);
326 1.27 dsl ibuf[0] = 0;
327 1.1 phil if (def != NULL && *def) {
328 1.27 dsl if (flags & MSG_PROMPT_HIDE_DFLT)
329 1.35 dsl strlcpy(ibuf, def, val_buf_len);
330 1.27 dsl else {
331 1.27 dsl waddstr(msg_win, " [");
332 1.27 dsl waddstr(msg_win, def);
333 1.27 dsl waddstr(msg_win, "]");
334 1.27 dsl }
335 1.1 phil }
336 1.21 dsl waddstr(msg_win, ": ");
337 1.27 dsl len = strlen(ibuf);
338 1.27 dsl pos = len;
339 1.27 dsl getyx(msg_win, txt_y, txt_x);
340 1.27 dsl maxx = getmaxx(msg_win) - txt_x - 1;
341 1.27 dsl off = 0;
342 1.27 dsl
343 1.27 dsl for (first = 1; ; first = 0) {
344 1.27 dsl
345 1.27 dsl if (flags & MSG_PROMPT_ECHO) {
346 1.27 dsl /* shift text right as we near the buffer start */
347 1.27 dsl if (pos - off < 4)
348 1.27 dsl off = pos - 4;
349 1.27 dsl /* keep offset to a minimum if we are at the end */
350 1.27 dsl if (pos == len)
351 1.27 dsl off = pos - maxx;
352 1.27 dsl if (off < 0 || len <= maxx)
353 1.27 dsl off = 0;
354 1.27 dsl /* shift text left as we near the buffer end */
355 1.27 dsl npos = pos + 4;
356 1.27 dsl if (npos > len)
357 1.27 dsl npos = len;
358 1.27 dsl if (npos - off > maxx)
359 1.27 dsl off = npos - maxx;
360 1.27 dsl /* calc. length to display */
361 1.27 dsl npos = len - off;
362 1.27 dsl if (npos > maxx)
363 1.27 dsl npos = maxx;
364 1.27 dsl mvwaddnstr(msg_win, txt_y, txt_x, ibuf + off, npos);
365 1.27 dsl wclrtoeol(msg_win);
366 1.27 dsl if (off != 0)
367 1.27 dsl mvwaddstr(msg_win, txt_y, txt_x, "+");
368 1.27 dsl wmove(msg_win, txt_y, txt_x + pos - off);
369 1.27 dsl wrefresh(msg_win);
370 1.27 dsl }
371 1.27 dsl
372 1.27 dsl ch = wgetch(msg_win);
373 1.27 dsl if (ch == '\n')
374 1.27 dsl break;
375 1.1 phil
376 1.27 dsl switch (ch) {
377 1.27 dsl case KEY_BACKSPACE:
378 1.27 dsl case 'h' & 0x1f: case 0x7f: /* bs or del - delete left */
379 1.27 dsl if (first) {
380 1.27 dsl /* delete all of default string */
381 1.27 dsl len = pos = 0;
382 1.27 dsl break;
383 1.27 dsl }
384 1.27 dsl if (pos > 0) {
385 1.27 dsl memmove(ibuf + pos - 1, ibuf + pos, len - pos);
386 1.27 dsl len--;
387 1.27 dsl pos--;
388 1.1 phil } else
389 1.14 cgd _msg_beep();
390 1.27 dsl break;
391 1.27 dsl case 'u' & 0x1f: /* ^U; line kill */
392 1.27 dsl /* kill line */
393 1.27 dsl len = pos = 0;
394 1.27 dsl break;
395 1.27 dsl case 'w' & 0x1f: /* ^W; word kill */
396 1.9 cgd /*
397 1.9 cgd * word kill kills the spaces and the 'word'
398 1.9 cgd * (non-spaces) last typed. the spaces before
399 1.9 cgd * the 'word' aren't killed.
400 1.9 cgd */
401 1.27 dsl npos = pos;
402 1.31 dsl while (npos > 0 && isspace((unsigned char)ibuf[npos - 1]))
403 1.27 dsl npos--;
404 1.31 dsl while (npos > 0 && !isspace((unsigned char)ibuf[npos - 1]))
405 1.27 dsl npos--;
406 1.27 dsl memmove(ibuf + npos, ibuf + pos, len - pos);
407 1.27 dsl len -= pos - npos;
408 1.27 dsl pos = npos;
409 1.27 dsl break;
410 1.27 dsl case KEY_LEFT:
411 1.27 dsl if (pos > 0)
412 1.27 dsl pos--;
413 1.27 dsl break;
414 1.27 dsl case KEY_RIGHT:
415 1.27 dsl if (len == 0 && pos == 0 && def != NULL) {
416 1.27 dsl /* restore default! */
417 1.35 dsl strlcpy(ibuf, def, val_buf_len);
418 1.27 dsl len = pos = strlen(ibuf);
419 1.27 dsl break;
420 1.9 cgd }
421 1.27 dsl if (pos < len)
422 1.27 dsl pos++;
423 1.27 dsl break;
424 1.27 dsl default:
425 1.35 dsl if (len < (val_buf_len - 1) && isprint(ch)) {
426 1.27 dsl memmove(ibuf + pos + 1, ibuf + pos, len - pos);
427 1.27 dsl ibuf[pos++] = ch;
428 1.27 dsl len++;
429 1.27 dsl } else
430 1.27 dsl _msg_beep();
431 1.27 dsl break;
432 1.27 dsl }
433 1.1 phil }
434 1.27 dsl
435 1.27 dsl if (flags & MSG_PROMPT_ECHO) {
436 1.27 dsl mvwaddch(msg_win, txt_y, txt_x + len - off, '\n');
437 1.8 cgd last_o_was_punct = 0;
438 1.8 cgd last_o_was_space = 1;
439 1.8 cgd }
440 1.1 phil
441 1.3 cgd /* copy the appropriate string to the output */
442 1.32 dsl if (len != 0 || flags & MSG_PROMPT_HIDE_DFLT) {
443 1.27 dsl ibuf[len] = '\0';
444 1.35 dsl strlcpy(val, ibuf, val_buf_len);
445 1.5 cgd } else if (def != NULL && val != def) {
446 1.35 dsl strlcpy(val, def, val_buf_len);
447 1.3 cgd }
448 1.1 phil }
449 1.1 phil
450 1.13 cgd void
451 1.35 dsl msg_prompt(msg msg_no, const char *def, char *val, size_t val_buf_len, ...)
452 1.1 phil {
453 1.1 phil va_list ap;
454 1.1 phil
455 1.13 cgd msg_clear();
456 1.13 cgd
457 1.35 dsl va_start(ap, val_buf_len);
458 1.27 dsl _msg_vprompt(msg_string(msg_no), MSG_PROMPT_ECHO,
459 1.35 dsl def, val, val_buf_len, ap);
460 1.21 dsl va_end(ap);
461 1.19 dsl }
462 1.19 dsl
463 1.19 dsl void
464 1.20 dsl msg_prompt_win(msg msg_no, int x, int y, int w, int h,
465 1.35 dsl const char *def, char *val, size_t val_buf_len, ...)
466 1.19 dsl {
467 1.19 dsl va_list ap;
468 1.34 he WINDOW *win;
469 1.33 he WINDOW *svmsg = NULL, *sv_win = NULL; /* XXX -Wuninitialized [many] */
470 1.20 dsl int maxx, maxy;
471 1.27 dsl int msg_flags = MSG_PROMPT_ECHO | MSG_PROMPT_HIDE_DFLT;
472 1.19 dsl
473 1.21 dsl maxx = getmaxx(msg_win);
474 1.21 dsl maxy = getmaxy(msg_win);
475 1.20 dsl if (w == 0) {
476 1.35 dsl va_start(ap, val_buf_len);
477 1.20 dsl w = vsnprintf(NULL, 0, msg_string(msg_no), ap);
478 1.20 dsl va_end(ap);
479 1.35 dsl if (def != NULL && *def != 0 && w + val_buf_len * 2 < maxx) {
480 1.22 dsl w += 2 + strlen(def) + 1;
481 1.27 dsl msg_flags &= ~MSG_PROMPT_HIDE_DFLT;
482 1.27 dsl }
483 1.35 dsl w += 1 + 2 + val_buf_len + 1;
484 1.27 dsl if (w > maxx) {
485 1.27 dsl if (!(msg_flags & MSG_PROMPT_HIDE_DFLT)) {
486 1.27 dsl w -= 2 + strlen(def) + 1;
487 1.27 dsl msg_flags |= MSG_PROMPT_HIDE_DFLT;
488 1.27 dsl }
489 1.20 dsl w = maxx;
490 1.27 dsl }
491 1.20 dsl }
492 1.19 dsl
493 1.20 dsl if (x == -1)
494 1.27 dsl x = (maxx - w) / 2 + 1;
495 1.20 dsl if (h < 3)
496 1.20 dsl h = 3;
497 1.20 dsl if (y < 3)
498 1.20 dsl y = (maxy - h) / 2;
499 1.20 dsl if (y + h > maxy)
500 1.20 dsl y = maxy - h;
501 1.20 dsl
502 1.21 dsl win = subwin(msg_win, h, w, y, x);
503 1.20 dsl if (win == NULL)
504 1.20 dsl wprintw(msg_win, "msg_prompt_win: "
505 1.20 dsl "newwin(%d, %d, %d, %d) failed\n",
506 1.20 dsl h, w, y, x);
507 1.20 dsl else {
508 1.29 dsl /*
509 1.29 dsl * Save screen contents from under our window
510 1.29 dsl * Due to a mis-feature of NetBSD curses, curscr contains
511 1.29 dsl * the data processed by doupdate() not that by wnoutrefresh().
512 1.29 dsl * We must call doupdate() here to ensure we save the correct
513 1.29 dsl * data. See PR 26660
514 1.29 dsl */
515 1.29 dsl doupdate();
516 1.28 dsl sv_win = dupwin(win);
517 1.28 dsl if (sv_win)
518 1.28 dsl overwrite(curscr, sv_win);
519 1.20 dsl wbkgd(win, getbkgd(msg_win));
520 1.20 dsl wattrset(win, getattrs(msg_win));
521 1.20 dsl box(win, 0, 0);
522 1.20 dsl wrefresh(win);
523 1.19 dsl
524 1.27 dsl /* Change message window to be our little box */
525 1.28 dsl svmsg = msg_window(subwin(msg_win, h - 2, w - 2, y + 1, x + 1));
526 1.20 dsl wbkgd(msg_win, getbkgd(win));
527 1.20 dsl wattrset(msg_win, getattrs(win));
528 1.19 dsl
529 1.20 dsl msg_clear();
530 1.19 dsl }
531 1.19 dsl
532 1.35 dsl va_start(ap, val_buf_len);
533 1.35 dsl _msg_vprompt(msg_string(msg_no), msg_flags, def, val, val_buf_len, ap);
534 1.20 dsl va_end(ap);
535 1.19 dsl
536 1.20 dsl if (win != NULL) {
537 1.20 dsl wclear(win);
538 1.28 dsl if (sv_win) {
539 1.28 dsl /* Restore original screen contents */
540 1.28 dsl overwrite(sv_win, win);
541 1.28 dsl delwin(sv_win);
542 1.28 dsl }
543 1.28 dsl wnoutrefresh(win);
544 1.27 dsl /* Restore normal message window */
545 1.28 dsl delwin(msg_window(svmsg));
546 1.20 dsl delwin(win);
547 1.20 dsl }
548 1.13 cgd }
549 1.13 cgd
550 1.13 cgd void
551 1.35 dsl msg_prompt_add(msg msg_no, const char *def, char *val, size_t val_buf_len, ...)
552 1.13 cgd {
553 1.13 cgd va_list ap;
554 1.13 cgd
555 1.35 dsl va_start(ap, val_buf_len);
556 1.35 dsl _msg_vprompt(msg_string(msg_no), MSG_PROMPT_ECHO, def, val, val_buf_len, ap);
557 1.1 phil va_end(ap);
558 1.1 phil }
559 1.1 phil
560 1.13 cgd void
561 1.35 dsl msg_prompt_noecho(msg msg_no, const char *def, char *val, size_t val_buf_len, ...)
562 1.1 phil {
563 1.1 phil va_list ap;
564 1.1 phil
565 1.7 cgd msg_clear();
566 1.7 cgd
567 1.35 dsl va_start(ap, val_buf_len);
568 1.35 dsl _msg_vprompt(msg_string(msg_no), 0, def, val, val_buf_len, ap);
569 1.21 dsl va_end(ap);
570 1.1 phil }
571 1.10 cgd
572 1.21 dsl void
573 1.21 dsl msg_table_add(msg msg_no, ...)
574 1.10 cgd {
575 1.10 cgd va_list ap;
576 1.10 cgd
577 1.21 dsl va_start(ap, msg_no);
578 1.16 cgd (void)_msg_vprintf(0, msg_string(msg_no), ap);
579 1.21 dsl va_end(ap);
580 1.10 cgd }
581 1.10 cgd
582 1.26 dsl int
583 1.26 dsl msg_row(void)
584 1.26 dsl {
585 1.26 dsl
586 1.26 dsl return getcury(msg_win) + getbegy(msg_win);
587 1.26 dsl }
588