Add msg_prompt_win() that will prompt in the specified window (instead of

the default one), and with a box around the window if >= 3 lines.
Stop the char delete from killingthe RHS of any box.
Make msg_string a noop for invalid strings (might be quoted text).
This commit is contained in:
dsl 2003-06-04 19:00:26 +00:00
parent b71607572c
commit 15cd94ddd8
4 changed files with 65 additions and 32 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.13 2003/05/18 07:57:36 lukem Exp $
# $NetBSD: Makefile,v 1.14 2003/06/04 19:00:26 dsl Exp $
.include <bsd.own.mk>
@ -18,6 +18,7 @@ MLINKS+= msgc.1 msg_window.1 \
msgc.1 msg_display_add.1 \
msgc.1 msg_prompt.1 \
msgc.1 msg_prompt_add.1 \
msgc.1 msg_prompt_win.1 \
msgc.1 msg_prompt_noecho.1 \
msgc.1 msg_table_add.1

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_sys.def,v 1.18 2003/01/10 20:01:12 christos Exp $ */
/* $NetBSD: msg_sys.def,v 1.19 2003/06/04 19:00:26 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -78,7 +78,12 @@ int msg_window(WINDOW *window)
const char *msg_string (msg msg_no)
{
return msg_list[(size_t)(intptr_t)msg_no];
int m = (intptr_t)msg_no;
if (m > sizeof msg_list / sizeof msg_list[0])
/* guess that we were passed a text string */
return msg_no;
return msg_list[m];
}
void msg_clear(void)
@ -245,6 +250,17 @@ void msg_display_add(msg msg_no, ...)
va_end (ap);
}
static void
_erase_ch(void)
{
int y, x;
getyx(msg_win, y, x);
x--;
wmove(msg_win, y, x);
waddch(msg_win, ' ');
wmove(msg_win, y, x);
}
static void
_msg_vprompt(const char *msg, int do_echo, const char *def, char *val,
@ -252,7 +268,6 @@ _msg_vprompt(const char *msg, int do_echo, const char *def, char *val,
{
int ch;
int count = 0;
int y,x;
char *ibuf = alloca(max_chars);
_msg_vprintf(0, msg, ap);
@ -268,23 +283,15 @@ _msg_vprompt(const char *msg, int do_echo, const char *def, char *val,
if (ch == 0x08 || ch == 0x7f) { /* bs or del */
if (count > 0) {
count--;
if (do_echo) {
getyx(msg_win, y, x);
x--;
wmove(msg_win, y, x);
wdelch(msg_win);
}
if (do_echo)
_erase_ch();
} else
_msg_beep();
} else if (ch == 0x15) { /* ^U; line kill */
while (count > 0) {
count--;
if (do_echo) {
getyx(msg_win, y, x);
x--;
wmove(msg_win, y, x);
wdelch(msg_win);
}
if (do_echo)
_erase_ch();
}
} else if (ch == 0x17) { /* ^W; word kill */
/*
@ -294,21 +301,13 @@ _msg_vprompt(const char *msg, int do_echo, const char *def, char *val,
*/
while (count > 0 && isspace(ibuf[count - 1])) {
count--;
if (do_echo) {
getyx(msg_win, y, x);
x--;
wmove(msg_win, y, x);
wdelch(msg_win);
}
if (do_echo)
_erase_ch();
}
while (count > 0 && !isspace(ibuf[count - 1])) {
count--;
if (do_echo) {
getyx(msg_win, y, x);
x--;
wmove(msg_win, y, x);
wdelch(msg_win);
}
if (do_echo)
_erase_ch();
}
} else if (count < (max_chars - 1) && isprint(ch)) {
if (do_echo)
@ -330,8 +329,7 @@ _msg_vprompt(const char *msg, int do_echo, const char *def, char *val,
ibuf[count] = '\0';
strcpy(val, ibuf); /* size known to be OK */
} else if (def != NULL && val != def) {
strncpy(val, def, max_chars);
val[max_chars - 1] = '\0';
strlcpy(val, def, max_chars);
}
}
@ -347,6 +345,32 @@ msg_prompt(msg msg_no, const char *def, char *val, size_t max_chars, ...)
va_end (ap);
}
void
msg_prompt_win(msg msg_no, WINDOW *win,
const char *def, char *val, size_t max_chars, ...)
{
va_list ap;
WINDOW *sv_win;
sv_win = msg_win;
msg_window(win);
msg_clear();
if (getmaxy(win) >= 3) {
box(win, 0, 0);
wmove(win, 1, 1);
}
va_start (ap, max_chars);
_msg_vprompt(msg_string(msg_no), 1, def, val, max_chars, ap);
va_end (ap);
msg_clear();
msg_window(sv_win);
}
void
msg_prompt_add(msg msg_no, const char *def, char *val, size_t max_chars, ...)
{

View File

@ -1,4 +1,4 @@
.\" $NetBSD: msgc.1,v 1.17 2002/09/26 01:26:53 wiz Exp $
.\" $NetBSD: msgc.1,v 1.18 2003/06/04 19:00:26 dsl Exp $
.\"
.\" Copyright 1997 Piermont Information Systems Inc.
.\" All rights reserved.
@ -47,6 +47,7 @@
.Nm msg_display_add ,
.Nm msg_prompt ,
.Nm msg_prompt_add ,
.Nm msg_prompt_win ,
.Nm msg_prompt_noecho ,
.Nm msg_table_add
.Nd simple message list compiler
@ -75,6 +76,8 @@ msgc
.Ft void
.Fn msg_prompt_add "msg msg_no" "const char *def" "char *val" "int max_chars" ...
.Ft void
.Fn msg_prompt_win "msg msg_no" "WINDOW *win" "const char *def" "char *val" "int max_chars" ...
.Ft void
.Fn msg_prompt_noecho "msg msg_no" "const char *def" "char *val" "int max_chars" ...
.Ft void
.Fn msg_table_add "msg msg_no" ...
@ -192,5 +195,8 @@ and
.Fn msg_noecho
control whether the prompt routine echo or don't echo the input that
is typed by the user.
.Pp
.Fn msg_prompt_win
uses the specified curses window instead of the default one.
.Sh AUTHORS
Philip A. Nelson for Piermont Information Systems Inc.

View File

@ -1,4 +1,4 @@
/* $NetBSD: msgdb.c,v 1.13 2003/01/10 20:01:12 christos Exp $ */
/* $NetBSD: msgdb.c,v 1.14 2003/06/04 19:00:26 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -159,6 +159,8 @@ write_msg_file ()
" char *val, size_t max_chars, ...);\n"
"void msg_prompt_noecho (msg msg_no, const char *def,"
" char *val, size_t max_chars, ...);\n"
"void msg_prompt_win (msg, WINDOW *,"
" const char *, char *, size_t, ...);\n"
"void msg_table_add(msg msg_no,...);\n"
"\n"
"/* Message names */\n"