Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/usr.bin/menuc pull up rev(s) 1.16-1.21 from trunk. (cgd)



details:   https://anonhg.NetBSD.org/src/rev/b4a7946963e4
branches:  netbsd-1-4
changeset: 468947:b4a7946963e4
user:      cgd <cgd%NetBSD.org@localhost>
date:      Thu Jun 24 00:52:17 1999 +0000

description:
pull up rev(s) 1.16-1.21 from trunk. (cgd)

diffstat:

 usr.bin/menuc/menu_sys.def |  122 ++++++++++++++++++++++++++++----------------
 1 files changed, 76 insertions(+), 46 deletions(-)

diffs (214 lines):

diff -r 7f723e0f189a -r b4a7946963e4 usr.bin/menuc/menu_sys.def
--- a/usr.bin/menuc/menu_sys.def        Thu Jun 24 00:52:09 1999 +0000
+++ b/usr.bin/menuc/menu_sys.def        Thu Jun 24 00:52:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menu_sys.def,v 1.15 1998/07/23 17:56:00 phil Exp $     */
+/*     $NetBSD: menu_sys.def,v 1.15.2.1 1999/06/24 00:52:17 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;
@@ -228,27 +228,31 @@
 
 static void init_menu (struct menudesc *m)
 {
-       int max;
-       int add, exitadd;
+       int wmax;
+       int hadd, wadd, exithadd;
        int i;
 
-       add = ((m->mopt & MC_NOBOX) ? 2 : 4);
-       exitadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
-       max = strlen(m->title);
+       hadd = ((m->mopt & MC_NOBOX) ? 0 : 2);
+       wadd = ((m->mopt & MC_NOBOX) ? 2 : 4);
+
+       hadd += strlen(m->title) != 0 ? 2 : 0;
+       exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
+
+       wmax = strlen(m->title);
 
        /* Calculate h? h == number of visible options. */
        if (m->h == 0) {
-               m->h = m->numopts + exitadd;
-               if (m->h + m->y + add >= max_lines && (m->mopt & MC_SCROLL))
-                       m->h = max_lines - m->y - add ;
+               m->h = m->numopts + exithadd;
+               if (m->h + m->y + hadd >= max_lines && (m->mopt & MC_SCROLL))
+                       m->h = max_lines - m->y - hadd ;
        }
 
        /* Check window heights and set scrolling */
-       if (m->h < m->numopts + exitadd) {
+       if (m->h < m->numopts + exithadd) {
                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);
                }
@@ -256,10 +260,10 @@
                m->mopt &= ~MC_SCROLL;
 
        /* check for screen fit */
-       if (m->y + m->h + add > max_lines) {
+       if (m->y + m->h + hadd > 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);
 
        }
@@ -267,20 +271,32 @@
        /* Calculate w? */
        if (m->w == 0) {
                if (m->mopt & MC_SCROLL)
-                       max = strlen(scrolltext);
+                       wmax = MAX(wmax,strlen(scrolltext));
                for (i=0; i < m->numopts; i++ )
-                       max = MAX(max,strlen(m->opts[i].opt_name)+3);
-               m->w = max;
+                       wmax = MAX(wmax,strlen(m->opts[i].opt_name)+3);
+               m->w = wmax;
        }
 
+       /* check and adjust for screen fit */
+       if (m->w + wadd > max_cols) {
+               endwin();
+               (void) fprintf (stderr,
+                       "Screen too narrow for menu \"%s\"\n", m->title);
+               exit(1);
+
+       }
+       if (m->x == -1)
+               m->x = (max_cols - (m->w + wadd)) / 2;  /* center */
+       else if (m->x + m->w + wadd > max_cols)
+               m->x = max_cols - (m->w + wadd);
+
        /* Get the windows. */
-       m->mw = newwin(m->h+add, m->w+add, m->y, m->x);
+       m->mw = newwin(m->h+hadd, m->w+wadd, m->y, m->x);
 
        if (m->mw == NULL) {
                endwin();
                (void) fprintf (stderr,
-                       "Could not create window for window with title "
-                       " \"%s\"\n", m->title);
+                       "Could not create window for menu \"%s\"\n", m->title);
                exit(1);
        } 
 }
@@ -319,7 +335,8 @@
        tadd = strlen(m->title) ? 2 : 0;
 
        if (tadd) {
-               mvwaddstr(m->mw, cury, cury, m->title);
+               mvwaddstr(m->mw, cury, cury, " ");
+               mvwaddstr(m->mw, cury, cury + 1, m->title);
                cury += 2;
                maxy += 2;
        }
@@ -354,7 +371,8 @@
                        selrow = cury;
                } else
                        mvwaddstr (m->mw, cury, hasbox, " ");
-               waddstr (m->mw, "x: Exit");
+               waddstr (m->mw, "x: ");
+               waddstr (m->mw, m->exitstr);
                if (m->cursel >= m->numopts)
                        wstandend(m->mw);
                cury++;
@@ -556,6 +574,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 +618,11 @@
        done = FALSE;
 
        /* Initialize? */
-       if (!__menu_init) {
-               if (initscr() == NULL) {
-                       __menu_initerror();
-                       return;
-               }
-               cbreak();
-               noecho();
-               max_lines = stdscr->maxy;
-               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);
@@ -719,6 +748,7 @@
        menus[ix].post_act = post_act;
        menus[ix].exit_act = exit_act;
        menus[ix].helpstr  = help;
+       menus[ix].exitstr  = "Exit";
 
        init_menu (&menus[ix]);
 



Home | Main Index | Thread Index | Old Index