Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/menuc * be more descriptive with the windor/screen t...
details: https://anonhg.NetBSD.org/src/rev/22379b0ba160
branches: trunk
changeset: 473788:22379b0ba160
user: cgd <cgd%NetBSD.org@localhost>
date: Sat Jun 19 06:38:49 1999 +0000
description:
* be more descriptive with the windor/screen too small for menu messages
(say width or height).
* work harder to make menu fit width-wise. (if necessary, move the menu
further left, and if that's not good enough exit with an error.)
* move menu system initialization out of process_menu() so that it can
be called earlier (e.g. by the sysinst main()), since it initializes
curses and other code might want to access the curses data structures
before process_menu() is invoked.
diffstat:
usr.bin/menuc/mdb.c | 3 +-
usr.bin/menuc/menu_sys.def | 78 +++++++++++++++++++++++++++++----------------
2 files changed, 52 insertions(+), 29 deletions(-)
diffs (145 lines):
diff -r a2dae0bda218 -r 22379b0ba160 usr.bin/menuc/mdb.c
--- a/usr.bin/menuc/mdb.c Sat Jun 19 05:35:14 1999 +0000
+++ b/usr.bin/menuc/mdb.c Sat Jun 19 06:38:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mdb.c,v 1.12 1998/07/23 17:56:00 phil Exp $ */
+/* $NetBSD: mdb.c,v 1.13 1999/06/19 06:38:49 cgd Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -203,6 +203,7 @@
"extern int __m_endwin;\n"
"\n"
"/* Prototypes */\n"
+ "int menu_init (void);\n"
"void process_menu (int num);\n"
"void __menu_initerror (void);\n"
);
diff -r a2dae0bda218 -r 22379b0ba160 usr.bin/menuc/menu_sys.def
--- a/usr.bin/menuc/menu_sys.def Sat Jun 19 05:35:14 1999 +0000
+++ b/usr.bin/menuc/menu_sys.def Sat Jun 19 06:38:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: menu_sys.def,v 1.16 1999/04/18 03:29:18 simonb Exp $ */
+/* $NetBSD: menu_sys.def,v 1.17 1999/06/19 06:38:49 cgd Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -99,7 +99,7 @@
/* Initialization state. */
static int __menu_init = 0;
int __m_endwin = 0;
-static int max_lines = 0;
+static int max_lines = 0, max_cols = 0;
static char *scrolltext = " <: page up, >: page down";
static menudesc *menus = menu_def;
@@ -248,7 +248,7 @@
if (!(m->mopt & MC_SCROLL) || m->h < 3) {
endwin();
(void) fprintf (stderr,
- "Window too small for menu \"%s\"\n",
+ "Window too short for menu \"%s\"\n",
m->title);
exit(1);
}
@@ -259,7 +259,7 @@
if (m->y + m->h + add > max_lines) {
endwin();
(void) fprintf (stderr,
- "Screen too small for menu \"%s\"\n", m->title);
+ "Screen too short for menu \"%s\"\n", m->title);
exit(1);
}
@@ -273,6 +273,17 @@
m->w = max;
}
+ /* check and adjust for screen fit */
+ if (m->w + add > max_cols) {
+ endwin();
+ (void) fprintf (stderr,
+ "Screen too narrow for menu \"%s\"\n", m->title);
+ exit(1);
+
+ }
+ if (m->x + m->w + add > max_cols)
+ m->x = max_cols - (m->w + add);
+
/* Get the windows. */
m->mw = newwin(m->h+add, m->w+add, m->y, m->x);
@@ -556,6 +567,37 @@
}
}
+int menu_init (void)
+{
+
+ if (__menu_init)
+ return 0;
+
+ if (initscr() == NULL)
+ return 1;
+
+ cbreak();
+ noecho();
+ max_lines = getmaxy(stdscr);
+ max_cols = getmaxx(stdscr);
+ init_keyseq();
+#ifdef DYNAMIC_MENUS
+ num_menus = DYN_INIT_NUM;
+ while (num_menus < DYN_MENU_START)
+ num_menus *= 2;
+ menus = (menudesc *) malloc(sizeof(menudesc)*num_menus);
+ if (menus == NULL)
+ return 2;
+ (void) memset ((void *)menus, 0, sizeof(menudesc)*num_menus);
+ (void) memcpy ((void *)menus, (void *)menu_def,
+ sizeof(menudesc)*DYN_MENU_START);
+ num_avail = num_menus - DYN_MENU_START;
+#endif
+
+ __menu_init = 1;
+ return (0);
+}
+
void process_menu (int num)
{
int sel = 0;
@@ -569,31 +611,11 @@
done = FALSE;
/* Initialize? */
- if (!__menu_init) {
- if (initscr() == NULL) {
- __menu_initerror();
- return;
- }
- cbreak();
- noecho();
- max_lines = getmaxy(stdscr);
- init_keyseq();
-#ifdef DYNAMIC_MENUS
- num_menus = DYN_INIT_NUM;
- while (num_menus < DYN_MENU_START)
- num_menus *= 2;
- menus = (menudesc *) malloc(sizeof(menudesc)*num_menus);
- if (menus == NULL) {
- __menu_initerror();
- return ;
- }
- (void) memset ((void *)menus, 0, sizeof(menudesc)*num_menus);
- (void) memcpy ((void *)menus, (void *)menu_def,
- sizeof(menudesc)*DYN_MENU_START);
- num_avail = num_menus - DYN_MENU_START;
-#endif
- __menu_init = 1;
+ if (menu_init()) {
+ __menu_initerror();
+ return;
}
+
if (__m_endwin) {
wclear(stdscr);
wrefresh(stdscr);
Home |
Main Index |
Thread Index |
Old Index