2019-11-16 20:38:09 +03:00
|
|
|
/* $NetBSD: msg_sys.def,v 1.48 2019/11/16 17:38:09 martin Exp $ */
|
1997-09-27 01:16:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2012-03-06 20:26:01 +04:00
|
|
|
* 3. The name of Piermont Information Systems Inc. may not be used to endorse
|
1997-09-27 01:16:38 +04:00
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2012-03-02 17:11:57 +04:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
1997-09-27 01:16:38 +04:00
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
2012-03-02 17:11:57 +04:00
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
1997-09-27 01:16:38 +04:00
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static WINDOW *msg_win = NULL;
|
1999-06-22 19:00:37 +04:00
|
|
|
static char *cbuffer;
|
|
|
|
static size_t cbuffersize;
|
1997-09-27 01:16:38 +04:00
|
|
|
|
1999-06-23 21:32:32 +04:00
|
|
|
static int last_i_was_nl, last_i_was_space;
|
|
|
|
static int last_o_was_punct, last_o_was_space;
|
1999-06-23 13:19:33 +04:00
|
|
|
|
1999-07-04 14:35:19 +04:00
|
|
|
static void _msg_beep(void);
|
2003-06-28 02:11:59 +04:00
|
|
|
static int _msg_vprintf(int, const char *, va_list);
|
2004-06-05 23:05:36 +04:00
|
|
|
#define MSG_PROMPT_ECHO 1
|
|
|
|
#define MSG_PROMPT_HIDE_DFLT 2
|
2003-06-28 02:11:59 +04:00
|
|
|
static void _msg_vprompt(const char *, int, const char *, char *,
|
|
|
|
size_t, va_list);
|
|
|
|
|
|
|
|
static char *msgmap = MAP_FAILED;
|
|
|
|
static size_t msgmapsz;
|
2010-01-02 19:08:20 +03:00
|
|
|
static unsigned int msgmapcount;
|
1999-07-04 14:13:12 +04:00
|
|
|
|
1997-09-27 01:16:38 +04:00
|
|
|
/* Routines */
|
|
|
|
|
1999-07-04 14:35:19 +04:00
|
|
|
static void
|
1999-07-04 14:39:40 +04:00
|
|
|
_msg_beep(void)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
2003-06-28 02:11:59 +04:00
|
|
|
|
1999-07-04 14:35:19 +04:00
|
|
|
fprintf(stderr, "\a");
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
2003-06-10 21:24:17 +04:00
|
|
|
WINDOW *
|
|
|
|
msg_window(WINDOW *window)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
1999-06-22 19:00:37 +04:00
|
|
|
size_t ncbuffersize;
|
|
|
|
char *ncbuffer;
|
2003-06-10 21:24:17 +04:00
|
|
|
WINDOW *old;
|
1999-06-22 19:00:37 +04:00
|
|
|
|
2003-06-10 21:24:17 +04:00
|
|
|
old = msg_win;
|
|
|
|
if (!window)
|
|
|
|
return old;
|
1997-09-27 01:16:38 +04:00
|
|
|
msg_win = window;
|
1999-06-22 19:00:37 +04:00
|
|
|
|
|
|
|
ncbuffersize = getmaxx(window) * getmaxy(window) + 1;
|
2003-06-10 21:24:17 +04:00
|
|
|
while (ncbuffersize > cbuffersize) {
|
1999-06-22 19:00:37 +04:00
|
|
|
ncbuffer = malloc(ncbuffersize);
|
2003-06-10 21:24:17 +04:00
|
|
|
if (ncbuffer == NULL) {
|
|
|
|
/* we might get truncated messages... */
|
|
|
|
ncbuffersize <<= 1;
|
|
|
|
continue;
|
|
|
|
}
|
1999-06-22 19:00:37 +04:00
|
|
|
if (cbuffer != NULL)
|
|
|
|
free(cbuffer);
|
|
|
|
cbuffer = ncbuffer;
|
|
|
|
cbuffersize = ncbuffersize;
|
2003-06-10 21:24:17 +04:00
|
|
|
break;
|
1999-06-22 19:00:37 +04:00
|
|
|
}
|
2003-06-10 21:24:17 +04:00
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
|
|
|
return old;
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
int
|
|
|
|
msg_file(const char *file)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (msgmap != MAP_FAILED)
|
|
|
|
munmap(msgmap, msgmapsz);
|
|
|
|
msgmap = MAP_FAILED;
|
|
|
|
if (!file)
|
|
|
|
return 0;
|
|
|
|
fd = open(file, O_RDONLY, 0);
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
msgmapsz = lseek(fd, 0, SEEK_END);
|
|
|
|
msgmap = mmap(0, msgmapsz, PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
close(fd);
|
|
|
|
if (msgmap == MAP_FAILED)
|
|
|
|
return -1;
|
|
|
|
/* check_magic */
|
2003-07-07 16:22:35 +04:00
|
|
|
if (strcmp(msgmap, "MSGTXTS") != 0) {
|
2003-06-28 02:11:59 +04:00
|
|
|
msg_file(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msgmapcount = atoi(msgmap + 8);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
msg_string(msg msg_no)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
2010-01-02 19:08:20 +03:00
|
|
|
uintptr_t m = (uintptr_t)msg_no;
|
2003-06-04 23:00:26 +04:00
|
|
|
|
|
|
|
if (m > sizeof msg_list / sizeof msg_list[0])
|
|
|
|
/* guess that we were passed a text string */
|
|
|
|
return msg_no;
|
2003-06-28 02:11:59 +04:00
|
|
|
|
|
|
|
if (msgmap != MAP_FAILED && m != 0 && m <= msgmapcount) {
|
|
|
|
unsigned int offset = atoi(msgmap + 8 + 8 * m);
|
|
|
|
if (offset != 0 && offset < msgmapsz)
|
|
|
|
return msgmap + offset;
|
|
|
|
}
|
|
|
|
|
2003-06-04 23:00:26 +04:00
|
|
|
return msg_list[m];
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
void
|
|
|
|
msg_clear(void)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
2003-06-28 02:11:59 +04:00
|
|
|
|
|
|
|
wclear(msg_win);
|
1999-06-23 21:32:32 +04:00
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
void
|
|
|
|
msg_standout(void)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
2003-06-28 02:11:59 +04:00
|
|
|
|
1997-09-27 01:16:38 +04:00
|
|
|
wstandout(msg_win);
|
|
|
|
}
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
void
|
|
|
|
msg_standend(void)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
2003-06-28 02:11:59 +04:00
|
|
|
|
1997-09-27 01:16:38 +04:00
|
|
|
wstandend(msg_win);
|
|
|
|
}
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
static int __printflike(2, 0)
|
1999-07-05 01:30:14 +04:00
|
|
|
_msg_vprintf(int auto_fill, const char *fmt, va_list ap)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
1999-06-23 21:32:32 +04:00
|
|
|
const char *wstart, *afterw;
|
|
|
|
int wordlen, nspaces;
|
1997-09-27 01:16:38 +04:00
|
|
|
int ret;
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
ret = vsnprintf(cbuffer, cbuffersize, fmt, ap);
|
1999-06-23 21:32:32 +04:00
|
|
|
|
1999-07-04 11:40:51 +04:00
|
|
|
if (!auto_fill) {
|
|
|
|
waddstr(msg_win, cbuffer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nothing is perfect if they flow text after a table,
|
|
|
|
* but this may be decent.
|
|
|
|
*/
|
|
|
|
last_i_was_nl = last_i_was_space = 1;
|
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
1999-06-23 21:32:32 +04:00
|
|
|
for (wstart = afterw = cbuffer; *wstart; wstart = afterw) {
|
|
|
|
|
|
|
|
/* eat one space, or a whole word of non-spaces */
|
2004-11-05 23:45:48 +03:00
|
|
|
if (isspace((unsigned char)*afterw))
|
1999-06-23 21:32:32 +04:00
|
|
|
afterw++;
|
|
|
|
else
|
2004-11-05 23:45:48 +03:00
|
|
|
while (*afterw && !isspace((unsigned char)*afterw))
|
1999-06-23 21:32:32 +04:00
|
|
|
afterw++;
|
|
|
|
|
|
|
|
/* this is an nl: special formatting necessary */
|
|
|
|
if (*wstart == '\n') {
|
|
|
|
if (last_i_was_nl || last_i_was_space) {
|
|
|
|
|
|
|
|
if (getcurx(msg_win) != 0)
|
|
|
|
waddch(msg_win, '\n');
|
|
|
|
if (last_i_was_nl) {
|
|
|
|
/* last was an nl: paragraph break */
|
|
|
|
waddch(msg_win, '\n');
|
|
|
|
} else {
|
|
|
|
/* last was space: line break */
|
|
|
|
}
|
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
|
|
|
} else {
|
|
|
|
/* last_o_was_punct unchanged */
|
|
|
|
/* last_o_was_space unchanged */
|
|
|
|
}
|
|
|
|
last_i_was_space = 1;
|
|
|
|
last_i_was_nl = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is a tab: special formatting necessary. */
|
|
|
|
if (*wstart == '\t') {
|
|
|
|
if (last_i_was_nl) {
|
|
|
|
/* last was an nl: list indent */
|
|
|
|
if (getcurx(msg_win) != 0)
|
|
|
|
waddch(msg_win, '\n');
|
|
|
|
} else {
|
|
|
|
/* last was not an nl: columns */
|
|
|
|
}
|
|
|
|
waddch(msg_win, '\t');
|
|
|
|
last_i_was_nl = 0;
|
|
|
|
last_i_was_space = 1;
|
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is a space: ignore it but set flags */
|
|
|
|
last_i_was_nl = 0; /* all newlines handled above */
|
2004-11-05 23:45:48 +03:00
|
|
|
last_i_was_space = isspace((unsigned char)*wstart);
|
1999-06-23 21:32:32 +04:00
|
|
|
if (last_i_was_space)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have a real "word," i.e. a sequence of non-space
|
|
|
|
* characters. wstart is now the start of the word,
|
|
|
|
* afterw is the next character after the end.
|
|
|
|
*/
|
|
|
|
wordlen = afterw - wstart;
|
|
|
|
nspaces = last_o_was_space ? 0 : (last_o_was_punct ? 2 : 1);
|
|
|
|
if ((getcurx(msg_win) + nspaces + wordlen) >=
|
|
|
|
getmaxx(msg_win) &&
|
|
|
|
wordlen < (getmaxx(msg_win) / 3)) {
|
|
|
|
/* wrap the line */
|
|
|
|
waddch(msg_win, '\n');
|
|
|
|
nspaces = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output the word, preceded by spaces if necessary */
|
|
|
|
while (nspaces-- > 0)
|
|
|
|
waddch(msg_win, ' ');
|
|
|
|
waddbytes(msg_win, wstart, wordlen);
|
|
|
|
|
|
|
|
/* set up the 'last' state for the next time around */
|
|
|
|
switch (afterw[-1]) {
|
|
|
|
case '.':
|
|
|
|
case '?':
|
|
|
|
case '!':
|
|
|
|
last_o_was_punct = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
last_o_was_punct = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_o_was_space = 0;
|
|
|
|
|
|
|
|
/* ... and do it all again! */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* String ended with a newline. They really want a line break. */
|
|
|
|
if (last_i_was_nl) {
|
|
|
|
if (getcurx(msg_win) != 0)
|
|
|
|
waddch(msg_win, '\n');
|
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
|
|
|
}
|
|
|
|
|
1999-07-04 11:40:51 +04:00
|
|
|
out:
|
2003-06-28 02:11:59 +04:00
|
|
|
wrefresh(msg_win);
|
1997-09-27 01:16:38 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
void
|
2019-06-20 03:45:18 +03:00
|
|
|
msg_display(msg msg_no)
|
|
|
|
{
|
|
|
|
|
2019-06-20 14:31:12 +03:00
|
|
|
msg_clear();
|
2019-06-20 03:45:18 +03:00
|
|
|
msg_printf("%s", msg_string(msg_no));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(2, 3)
|
|
|
|
msg_fmt_display(msg msg_no, const char *fmt, ...)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
1999-06-23 13:19:33 +04:00
|
|
|
msg_clear();
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)_msg_vprintf(1, fmtcheck(msg_string(msg_no), fmt), ap);
|
1997-09-27 01:16:38 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
void
|
2019-06-20 03:45:18 +03:00
|
|
|
msg_display_add(msg msg_no)
|
|
|
|
{
|
|
|
|
|
|
|
|
msg_printf("%s", msg_string(msg_no));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(2, 3)
|
|
|
|
msg_fmt_display_add(msg msg_no, const char *fmt, ...)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)_msg_vprintf(1, fmtcheck(msg_string(msg_no), fmt), ap);
|
2003-06-28 02:11:59 +04:00
|
|
|
va_end(ap);
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
void __printflike(1, 2)
|
2012-03-02 18:27:48 +04:00
|
|
|
msg_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)_msg_vprintf(1, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
static void __printflike(1, 0)
|
2004-06-05 23:05:36 +04:00
|
|
|
_msg_vprompt(const char *fmt, int flags, const char *def, char *val,
|
2006-09-06 23:13:51 +04:00
|
|
|
size_t val_buf_len, va_list ap)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
|
|
|
int ch;
|
2004-06-05 23:05:36 +04:00
|
|
|
int len, pos, npos, off;
|
|
|
|
int first;
|
|
|
|
int txt_y, txt_x;
|
2006-09-06 23:24:15 +04:00
|
|
|
char *ibuf;
|
2004-06-05 23:05:36 +04:00
|
|
|
int maxx;
|
1997-09-27 01:16:38 +04:00
|
|
|
|
2006-09-06 23:24:15 +04:00
|
|
|
if (val == NULL || val_buf_len == 0) {
|
|
|
|
/* No answer wanted */
|
|
|
|
val = NULL;
|
|
|
|
val_buf_len = 1;
|
|
|
|
}
|
|
|
|
|
2006-12-03 04:18:34 +03:00
|
|
|
ibuf = malloc(val_buf_len);
|
2006-09-06 23:24:15 +04:00
|
|
|
|
2004-06-05 23:05:36 +04:00
|
|
|
keypad(msg_win, TRUE);
|
2003-07-25 11:48:02 +04:00
|
|
|
_msg_vprintf(0, fmt, ap);
|
2004-06-05 23:05:36 +04:00
|
|
|
ibuf[0] = 0;
|
1997-09-27 01:16:38 +04:00
|
|
|
if (def != NULL && *def) {
|
2004-06-05 23:05:36 +04:00
|
|
|
if (flags & MSG_PROMPT_HIDE_DFLT)
|
2006-09-06 23:13:51 +04:00
|
|
|
strlcpy(ibuf, def, val_buf_len);
|
2004-06-05 23:05:36 +04:00
|
|
|
else {
|
|
|
|
waddstr(msg_win, " [");
|
|
|
|
waddstr(msg_win, def);
|
|
|
|
waddstr(msg_win, "]");
|
|
|
|
}
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
2003-06-28 02:11:59 +04:00
|
|
|
waddstr(msg_win, ": ");
|
2004-06-05 23:05:36 +04:00
|
|
|
len = strlen(ibuf);
|
|
|
|
pos = len;
|
|
|
|
getyx(msg_win, txt_y, txt_x);
|
|
|
|
maxx = getmaxx(msg_win) - txt_x - 1;
|
|
|
|
off = 0;
|
|
|
|
|
|
|
|
for (first = 1; ; first = 0) {
|
|
|
|
|
|
|
|
if (flags & MSG_PROMPT_ECHO) {
|
|
|
|
/* shift text right as we near the buffer start */
|
|
|
|
if (pos - off < 4)
|
|
|
|
off = pos - 4;
|
|
|
|
/* keep offset to a minimum if we are at the end */
|
|
|
|
if (pos == len)
|
|
|
|
off = pos - maxx;
|
|
|
|
if (off < 0 || len <= maxx)
|
|
|
|
off = 0;
|
|
|
|
/* shift text left as we near the buffer end */
|
|
|
|
npos = pos + 4;
|
|
|
|
if (npos > len)
|
|
|
|
npos = len;
|
|
|
|
if (npos - off > maxx)
|
|
|
|
off = npos - maxx;
|
|
|
|
/* calc. length to display */
|
|
|
|
npos = len - off;
|
|
|
|
if (npos > maxx)
|
|
|
|
npos = maxx;
|
|
|
|
mvwaddnstr(msg_win, txt_y, txt_x, ibuf + off, npos);
|
|
|
|
wclrtoeol(msg_win);
|
|
|
|
if (off != 0)
|
|
|
|
mvwaddstr(msg_win, txt_y, txt_x, "+");
|
|
|
|
wmove(msg_win, txt_y, txt_x + pos - off);
|
|
|
|
wrefresh(msg_win);
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = wgetch(msg_win);
|
|
|
|
if (ch == '\n')
|
|
|
|
break;
|
1997-09-27 01:16:38 +04:00
|
|
|
|
2004-06-05 23:05:36 +04:00
|
|
|
switch (ch) {
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
case 'h' & 0x1f: case 0x7f: /* bs or del - delete left */
|
|
|
|
if (first) {
|
|
|
|
/* delete all of default string */
|
|
|
|
len = pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pos > 0) {
|
|
|
|
memmove(ibuf + pos - 1, ibuf + pos, len - pos);
|
|
|
|
len--;
|
|
|
|
pos--;
|
1997-09-27 01:16:38 +04:00
|
|
|
} else
|
1999-07-04 14:35:19 +04:00
|
|
|
_msg_beep();
|
2004-06-05 23:05:36 +04:00
|
|
|
break;
|
2019-01-22 21:39:49 +03:00
|
|
|
case 'l' & 0x1f:
|
|
|
|
endwin();
|
|
|
|
doupdate();
|
|
|
|
break;
|
2004-06-05 23:05:36 +04:00
|
|
|
case 'u' & 0x1f: /* ^U; line kill */
|
|
|
|
/* kill line */
|
|
|
|
len = pos = 0;
|
|
|
|
break;
|
|
|
|
case 'w' & 0x1f: /* ^W; word kill */
|
1999-06-23 21:42:11 +04:00
|
|
|
/*
|
|
|
|
* word kill kills the spaces and the 'word'
|
|
|
|
* (non-spaces) last typed. the spaces before
|
|
|
|
* the 'word' aren't killed.
|
|
|
|
*/
|
2004-06-05 23:05:36 +04:00
|
|
|
npos = pos;
|
2004-11-05 23:45:48 +03:00
|
|
|
while (npos > 0 && isspace((unsigned char)ibuf[npos - 1]))
|
2004-06-05 23:05:36 +04:00
|
|
|
npos--;
|
2004-11-05 23:45:48 +03:00
|
|
|
while (npos > 0 && !isspace((unsigned char)ibuf[npos - 1]))
|
2004-06-05 23:05:36 +04:00
|
|
|
npos--;
|
|
|
|
memmove(ibuf + npos, ibuf + pos, len - pos);
|
|
|
|
len -= pos - npos;
|
|
|
|
pos = npos;
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
if (pos > 0)
|
|
|
|
pos--;
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
if (len == 0 && pos == 0 && def != NULL) {
|
|
|
|
/* restore default! */
|
2006-09-06 23:13:51 +04:00
|
|
|
strlcpy(ibuf, def, val_buf_len);
|
2004-06-05 23:05:36 +04:00
|
|
|
len = pos = strlen(ibuf);
|
|
|
|
break;
|
1999-06-23 21:42:11 +04:00
|
|
|
}
|
2004-06-05 23:05:36 +04:00
|
|
|
if (pos < len)
|
|
|
|
pos++;
|
|
|
|
break;
|
|
|
|
default:
|
2010-01-02 19:08:20 +03:00
|
|
|
if (len < (int)(val_buf_len - 1) && isprint(ch)) {
|
2004-06-05 23:05:36 +04:00
|
|
|
memmove(ibuf + pos + 1, ibuf + pos, len - pos);
|
|
|
|
ibuf[pos++] = ch;
|
|
|
|
len++;
|
|
|
|
} else
|
|
|
|
_msg_beep();
|
|
|
|
break;
|
|
|
|
}
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
2004-06-05 23:05:36 +04:00
|
|
|
|
|
|
|
if (flags & MSG_PROMPT_ECHO) {
|
|
|
|
mvwaddch(msg_win, txt_y, txt_x + len - off, '\n');
|
1999-06-23 21:32:32 +04:00
|
|
|
last_o_was_punct = 0;
|
|
|
|
last_o_was_space = 1;
|
|
|
|
}
|
1997-09-27 01:16:38 +04:00
|
|
|
|
2006-09-06 23:24:15 +04:00
|
|
|
if (val != NULL) {
|
|
|
|
/* copy the appropriate string to the output */
|
|
|
|
if (len != 0 || flags & MSG_PROMPT_HIDE_DFLT) {
|
|
|
|
ibuf[len] = '\0';
|
|
|
|
strlcpy(val, ibuf, val_buf_len);
|
|
|
|
} else if (def != NULL && val != def) {
|
|
|
|
strlcpy(val, def, val_buf_len);
|
|
|
|
}
|
1999-06-19 04:00:48 +04:00
|
|
|
}
|
2006-12-03 04:18:34 +03:00
|
|
|
free(ibuf);
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
1999-07-04 14:29:30 +04:00
|
|
|
void
|
2019-06-20 03:45:18 +03:00
|
|
|
msg_prompt(msg msg_no, const char *def, char *val, size_t val_buf_len)
|
|
|
|
{
|
|
|
|
|
|
|
|
msg_fmt_prompt(msg_no, def, val, val_buf_len, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(5, 6)
|
|
|
|
msg_fmt_prompt(msg msg_no, const char *def, char *val, size_t val_buf_len,
|
|
|
|
const char *fmt, ...)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
1999-07-04 14:29:30 +04:00
|
|
|
msg_clear();
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), MSG_PROMPT_ECHO,
|
2006-09-06 23:13:51 +04:00
|
|
|
def, val, val_buf_len, ap);
|
2003-06-28 02:11:59 +04:00
|
|
|
va_end(ap);
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
2003-06-04 23:00:26 +04:00
|
|
|
void
|
2003-06-10 21:24:17 +04:00
|
|
|
msg_prompt_win(msg msg_no, int x, int y, int w, int h,
|
2019-06-20 03:45:18 +03:00
|
|
|
const char *def, char *val, size_t val_buf_len)
|
|
|
|
{
|
|
|
|
msg_fmt_prompt_win(msg_no, x, y, w, h, def, val, val_buf_len, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(9, 10)
|
|
|
|
msg_fmt_prompt_win(msg msg_no, int x, int y, int w, int h,
|
|
|
|
const char *def, char *val, size_t val_buf_len, const char *fmt, ...)
|
2003-06-04 23:00:26 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
2006-05-12 11:20:13 +04:00
|
|
|
WINDOW *win;
|
2006-05-12 11:19:43 +04:00
|
|
|
WINDOW *svmsg = NULL, *sv_win = NULL; /* XXX -Wuninitialized [many] */
|
2003-06-10 21:24:17 +04:00
|
|
|
int maxx, maxy;
|
2004-06-05 23:05:36 +04:00
|
|
|
int msg_flags = MSG_PROMPT_ECHO | MSG_PROMPT_HIDE_DFLT;
|
2019-03-01 20:02:21 +03:00
|
|
|
const char *np, *ep;
|
2003-06-10 21:24:17 +04:00
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
maxx = getmaxx(msg_win);
|
|
|
|
maxy = getmaxy(msg_win);
|
2003-06-10 21:24:17 +04:00
|
|
|
if (w == 0) {
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
w = vsnprintf(NULL, 0, fmtcheck(msg_string(msg_no), fmt), ap);
|
2003-06-10 21:24:17 +04:00
|
|
|
va_end(ap);
|
2019-06-20 03:45:18 +03:00
|
|
|
if (def != NULL && *def != 0 && w + (int)val_buf_len * 2 < maxx) {
|
2003-07-07 16:22:35 +04:00
|
|
|
w += 2 + strlen(def) + 1;
|
2004-06-05 23:05:36 +04:00
|
|
|
msg_flags &= ~MSG_PROMPT_HIDE_DFLT;
|
|
|
|
}
|
2006-09-06 23:13:51 +04:00
|
|
|
w += 1 + 2 + val_buf_len + 1;
|
2004-06-05 23:05:36 +04:00
|
|
|
if (w > maxx) {
|
|
|
|
if (!(msg_flags & MSG_PROMPT_HIDE_DFLT)) {
|
|
|
|
w -= 2 + strlen(def) + 1;
|
|
|
|
msg_flags |= MSG_PROMPT_HIDE_DFLT;
|
|
|
|
}
|
2003-06-10 21:24:17 +04:00
|
|
|
w = maxx;
|
2004-06-05 23:05:36 +04:00
|
|
|
}
|
2019-01-21 23:28:08 +03:00
|
|
|
} else if (w > 0 && def != NULL && *def != 0) {
|
|
|
|
size_t tl = strlen(def);
|
|
|
|
if (tl + 1 + 2 + val_buf_len + 1 < (unsigned)w)
|
|
|
|
msg_flags &= ~MSG_PROMPT_HIDE_DFLT;
|
2003-06-10 21:24:17 +04:00
|
|
|
}
|
2003-06-04 23:00:26 +04:00
|
|
|
|
2003-06-10 21:24:17 +04:00
|
|
|
if (x == -1)
|
2004-06-05 23:05:36 +04:00
|
|
|
x = (maxx - w) / 2 + 1;
|
2019-03-01 20:02:21 +03:00
|
|
|
if (h < 0) {
|
|
|
|
h = 3;
|
|
|
|
for (np = msg_string(msg_no); (ep = strchr(np, '\n'));
|
|
|
|
np = ep + 1)
|
|
|
|
h++;
|
|
|
|
}
|
2003-06-10 21:24:17 +04:00
|
|
|
if (h < 3)
|
|
|
|
h = 3;
|
|
|
|
if (y < 3)
|
|
|
|
y = (maxy - h) / 2;
|
|
|
|
if (y + h > maxy)
|
|
|
|
y = maxy - h;
|
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
win = subwin(msg_win, h, w, y, x);
|
2003-06-10 21:24:17 +04:00
|
|
|
if (win == NULL)
|
|
|
|
wprintw(msg_win, "msg_prompt_win: "
|
|
|
|
"newwin(%d, %d, %d, %d) failed\n",
|
|
|
|
h, w, y, x);
|
|
|
|
else {
|
2004-08-14 19:15:57 +04:00
|
|
|
/*
|
|
|
|
* Save screen contents from under our window
|
|
|
|
* Due to a mis-feature of NetBSD curses, curscr contains
|
|
|
|
* the data processed by doupdate() not that by wnoutrefresh().
|
|
|
|
* We must call doupdate() here to ensure we save the correct
|
|
|
|
* data. See PR 26660
|
|
|
|
*/
|
|
|
|
doupdate();
|
2004-08-13 22:26:52 +04:00
|
|
|
sv_win = dupwin(win);
|
|
|
|
if (sv_win)
|
|
|
|
overwrite(curscr, sv_win);
|
2003-06-10 21:24:17 +04:00
|
|
|
wbkgd(win, getbkgd(msg_win));
|
|
|
|
wattrset(win, getattrs(msg_win));
|
|
|
|
box(win, 0, 0);
|
|
|
|
wrefresh(win);
|
2003-06-04 23:00:26 +04:00
|
|
|
|
2004-06-05 23:05:36 +04:00
|
|
|
/* Change message window to be our little box */
|
2004-08-13 22:26:52 +04:00
|
|
|
svmsg = msg_window(subwin(msg_win, h - 2, w - 2, y + 1, x + 1));
|
2003-06-10 21:24:17 +04:00
|
|
|
wbkgd(msg_win, getbkgd(win));
|
|
|
|
wattrset(msg_win, getattrs(win));
|
2003-06-04 23:00:26 +04:00
|
|
|
|
2003-06-10 21:24:17 +04:00
|
|
|
msg_clear();
|
2003-06-04 23:00:26 +04:00
|
|
|
}
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
2019-06-26 00:09:33 +03:00
|
|
|
_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), msg_flags, def, val,
|
|
|
|
val_buf_len, ap);
|
2003-06-10 21:24:17 +04:00
|
|
|
va_end(ap);
|
2003-06-04 23:00:26 +04:00
|
|
|
|
2003-06-10 21:24:17 +04:00
|
|
|
if (win != NULL) {
|
|
|
|
wclear(win);
|
2004-08-13 22:26:52 +04:00
|
|
|
if (sv_win) {
|
|
|
|
/* Restore original screen contents */
|
|
|
|
overwrite(sv_win, win);
|
|
|
|
delwin(sv_win);
|
|
|
|
}
|
|
|
|
wnoutrefresh(win);
|
2004-06-05 23:05:36 +04:00
|
|
|
/* Restore normal message window */
|
2004-08-13 22:26:52 +04:00
|
|
|
delwin(msg_window(svmsg));
|
2003-06-10 21:24:17 +04:00
|
|
|
delwin(win);
|
|
|
|
}
|
2003-06-04 23:00:26 +04:00
|
|
|
}
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
void
|
|
|
|
msg_prompt_add(msg msg_no, const char *def, char *val, size_t val_buf_len)
|
|
|
|
{
|
|
|
|
|
|
|
|
msg_fmt_prompt_add(msg_no, def, val, val_buf_len, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(5, 6)
|
|
|
|
msg_fmt_prompt_add(msg msg_no, const char *def, char *val, size_t val_buf_len,
|
|
|
|
const char *fmt, ...)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), MSG_PROMPT_ECHO, def,
|
|
|
|
val, val_buf_len, ap);
|
1999-07-04 14:29:30 +04:00
|
|
|
va_end(ap);
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
|
|
|
|
1999-07-04 14:29:30 +04:00
|
|
|
void
|
2019-06-20 03:45:18 +03:00
|
|
|
msg_prompt_noecho(msg msg_no, const char *def, char *val, size_t val_buf_len)
|
|
|
|
{
|
|
|
|
msg_fmt_prompt_noecho(msg_no, def, val, val_buf_len, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(5, 6)
|
|
|
|
msg_fmt_prompt_noecho(msg msg_no, const char *def, char *val,
|
|
|
|
size_t val_buf_len, const char *fmt, ...)
|
1997-09-27 01:16:38 +04:00
|
|
|
{
|
1999-07-04 14:29:30 +04:00
|
|
|
va_list ap;
|
1997-09-27 01:16:38 +04:00
|
|
|
|
1999-07-04 14:29:30 +04:00
|
|
|
msg_clear();
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), 0, def, val,
|
|
|
|
val_buf_len, ap);
|
2003-06-28 02:11:59 +04:00
|
|
|
va_end(ap);
|
1997-09-27 01:16:38 +04:00
|
|
|
}
|
1999-07-04 11:40:51 +04:00
|
|
|
|
2003-06-28 02:11:59 +04:00
|
|
|
void
|
2019-06-20 03:45:18 +03:00
|
|
|
msg_table_add(msg msg_no)
|
|
|
|
{
|
|
|
|
|
2019-11-16 20:38:09 +03:00
|
|
|
msg_fmt_table_add(msg_no, "");
|
2019-06-20 03:45:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void __printflike(2, 3)
|
|
|
|
msg_fmt_table_add(msg msg_no, const char *fmt, ...)
|
1999-07-04 11:40:51 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2019-06-20 03:45:18 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)_msg_vprintf(0, fmtcheck(msg_string(msg_no), fmt), ap);
|
2003-06-28 02:11:59 +04:00
|
|
|
va_end(ap);
|
1999-07-04 11:40:51 +04:00
|
|
|
}
|
|
|
|
|
2003-09-25 22:32:10 +04:00
|
|
|
int
|
|
|
|
msg_row(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return getcury(msg_win) + getbegy(msg_win);
|
|
|
|
}
|