Change msg_window() to return old window (temp buffer size isn't too important)

Change msg_promt_win() to create the window.
Number MSG_xxx from 1 (because 0 is NULL)
This commit is contained in:
dsl 2003-06-10 17:24:17 +00:00
parent 19605a628c
commit 62a063f96b
2 changed files with 72 additions and 27 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_sys.def,v 1.19 2003/06/04 19:00:26 dsl Exp $ */
/* $NetBSD: msg_sys.def,v 1.20 2003/06/10 17:24:17 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -56,24 +56,35 @@ _msg_beep(void)
fprintf(stderr, "\a");
}
int msg_window(WINDOW *window)
WINDOW *
msg_window(WINDOW *window)
{
size_t ncbuffersize;
char *ncbuffer;
WINDOW *old;
old = msg_win;
if (!window)
return old;
msg_win = window;
ncbuffersize = getmaxx(window) * getmaxy(window) + 1;
if (ncbuffersize > cbuffersize) {
while (ncbuffersize > cbuffersize) {
ncbuffer = malloc(ncbuffersize);
if (ncbuffer == NULL)
return 1;
if (ncbuffer == NULL) {
/* we might get truncated messages... */
ncbuffersize <<= 1;
continue;
}
if (cbuffer != NULL)
free(cbuffer);
cbuffer = ncbuffer;
cbuffersize = ncbuffersize;
break;
}
return 0;
last_o_was_punct = 0;
last_o_was_space = 1;
return old;
}
const char *msg_string (msg msg_no)
@ -346,29 +357,63 @@ msg_prompt(msg msg_no, const char *def, char *val, size_t max_chars, ...)
}
void
msg_prompt_win(msg msg_no, WINDOW *win,
msg_prompt_win(msg msg_no, int x, int y, int w, int h,
const char *def, char *val, size_t max_chars, ...)
{
va_list ap;
WINDOW *sv_win;
WINDOW *win, *svwin;
int maxx, maxy;
sv_win = msg_win;
msg_window(win);
msg_clear();
if (getmaxy(win) >= 3) {
box(win, 0, 0);
wmove(win, 1, 1);
maxx = getmaxx(stdscr);
maxy = getmaxy(stdscr);
if (w == 0) {
va_start(ap, max_chars);
w = vsnprintf(NULL, 0, msg_string(msg_no), ap);
va_end(ap);
if (def != NULL && *def != 0)
w += 2 + strlen(def);
w += 1 + 2 + max_chars + 1;
if (w > maxx)
w = maxx;
}
va_start (ap, max_chars);
_msg_vprompt(msg_string(msg_no), 1, def, val, max_chars, ap);
va_end (ap);
if (x == -1)
x = (maxx - w) / 2;
if (h < 3)
h = 3;
if (y < 3)
y = (maxy - h) / 2;
if (y + h > maxy)
y = maxy - h;
msg_clear();
msg_window(sv_win);
win = newwin(h, w, y, x);
if (win == NULL)
wprintw(msg_win, "msg_prompt_win: "
"newwin(%d, %d, %d, %d) failed\n",
h, w, y, x);
else {
wbkgd(win, getbkgd(msg_win));
wattrset(win, getattrs(msg_win));
box(win, 0, 0);
wrefresh(win);
svwin = msg_window(derwin(win, -1, -1, 1, 1));
wbkgd(msg_win, getbkgd(win));
wattrset(msg_win, getattrs(win));
msg_clear();
}
va_start(ap, max_chars);
_msg_vprompt(msg_string(msg_no), 1, def, val, max_chars, ap);
va_end(ap);
if (win != NULL) {
wclear(win);
wrefresh(win);
delwin(msg_window(svwin));
delwin(win);
}
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: msgdb.c,v 1.14 2003/06/04 19:00:26 dsl Exp $ */
/* $NetBSD: msgdb.c,v 1.15 2003/06/10 17:24:17 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -46,7 +46,7 @@
#include "pathnames.h"
static struct id_rec *head = NULL, *tail = NULL;
static int msg_no = 0;
static int msg_no = 1;
void define_msg (char *name, char *value)
{
@ -146,7 +146,7 @@ write_msg_file ()
"typedef const char *msg;\n"
"\n"
"/* Prototypes */\n"
"int msg_window(WINDOW *window);\n"
"WINDOW *msg_window(WINDOW *window);\n"
"const char *msg_string (msg msg_no);\n"
"void msg_clear(void);\n"
"void msg_standout(void);\n"
@ -159,7 +159,7 @@ 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 *,"
"void msg_prompt_win (msg, int, int, int, int,"
" const char *, char *, size_t, ...);\n"
"void msg_table_add(msg msg_no,...);\n"
"\n"
@ -186,7 +186,7 @@ write_msg_file ()
(void)fprintf (out_file, "#include \"%s\"\n", hname);
/* msg_list */
(void)fprintf (out_file, "const char *msg_list[] = {\n");
(void)fprintf (out_file, "const char *msg_list[] = {\nNULL,\n");
for (t=head ; t != NULL; t = t->next)
write_str (out_file, t->msg);
(void)fprintf (out_file, "NULL};\n");