Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.bin/menuc Pull up to netbsd-1-5 branch, OK'd by tho...



details:   https://anonhg.NetBSD.org/src/rev/517543d0f3eb
branches:  netbsd-1-5
changeset: 489114:517543d0f3eb
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Tue Aug 15 02:09:29 2000 +0000

description:
Pull up to netbsd-1-5 branch, OK'd by thorpej:

Revisions:
 > cvs rdiff -r1.15 -r1.16 basesrc/usr.bin/menuc/mdb.c
 > cvs rdiff -r1.22 -r1.23 basesrc/usr.bin/menuc/menu_sys.def

Log Message:
 >  * bring closer to KNF
 >  * when selecting a item in a menu, call the opt_action() callback with
 >    a pointer to the struct menudesc, so the callback has a chance to find
 >    out which item was selected. Having a seperate callback for each
 >    item is ok for small menus, but not for ones with many objects.
 >  * Add menu-option MC_NOSHORTCUT to not print letters ("a: ", ...)
 >    in front of list items. Again, this is for menues with lots of entries
 >    as e.g. the upcoming sysinst set_timezone() function composes.
 >  * Fix a long-standing bug WRT pagewise scrolling - the cursor is now
 >    properly placed one page up/down

diffstat:

 usr.bin/menuc/mdb.c        |  10 +++--
 usr.bin/menuc/menu_sys.def |  90 ++++++++++++++++++++++++++++-----------------
 2 files changed, 62 insertions(+), 38 deletions(-)

diffs (291 lines):

diff -r bb16da1868c2 -r 517543d0f3eb usr.bin/menuc/mdb.c
--- a/usr.bin/menuc/mdb.c       Mon Aug 14 21:24:15 2000 +0000
+++ b/usr.bin/menuc/mdb.c       Tue Aug 15 02:09:29 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mdb.c,v 1.14 1999/06/20 02:07:18 cgd Exp $     */
+/*     $NetBSD: mdb.c,v 1.14.8.1 2000/08/15 02:09:29 hubertf Exp $     */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -161,12 +161,13 @@
                (void) fprintf (out_file, "#define DYNAMIC_MENUS\n\n");
 
        (void) fprintf (out_file,
+               "struct menudesc;\n"
                "typedef\n"
                "struct menu_ent {\n"
                "       char   *opt_name;\n"
                "       int     opt_menu;\n"
                "       int     opt_flags;\n"
-               "       int     (*opt_action)(void);\n"
+               "       int     (*opt_action)(struct menudesc *);\n"
                "} menu_ent ;\n\n"
                "#define OPT_SUB    1\n"
                "#define OPT_ENDWIN 2\n"
@@ -193,6 +194,7 @@
                "#define MC_NOEXITOPT 1\n"
                "#define MC_NOBOX 2\n"
                "#define MC_SCROLL 4\n"
+               "#define MC_NOSHORTCUT 16      /* don't display letter shortkeys */\n"
                );
 
        if (do_dynamic)
@@ -275,8 +277,8 @@
                while (toptn != NULL) {
                        if (strlen(toptn->optact.code)) {
                                (void) fprintf (out_file,
-                                       "int opt_act_%d_%d(void);\n"
-                                       "int opt_act_%d_%d(void)\n"
+                                       "int opt_act_%d_%d(menudesc *m);\n"
+                                       "int opt_act_%d_%d(menudesc *m)\n"
                                        "{\t%s\n\treturn %s;\n}\n\n",
                                        i, j, i, j, toptn->optact.code,
                                        (toptn->doexit ? "1" : "0"));
diff -r bb16da1868c2 -r 517543d0f3eb usr.bin/menuc/menu_sys.def
--- a/usr.bin/menuc/menu_sys.def        Mon Aug 14 21:24:15 2000 +0000
+++ b/usr.bin/menuc/menu_sys.def        Tue Aug 15 02:09:29 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menu_sys.def,v 1.22 2000/04/22 21:34:25 thorpej Exp $  */
+/*     $NetBSD: menu_sys.def,v 1.22.4.1 2000/08/15 02:09:29 hubertf Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -127,12 +127,14 @@
 
 /* menu system processing routines */
 
-static void mbeep (void)
+static void
+mbeep (void)
 {
        fprintf (stderr,"\a");
 }
 
-static void ins_keyseq (struct keyseq **seq, struct keyseq *ins)
+static void
+ins_keyseq (struct keyseq **seq, struct keyseq *ins)
 {
        if (*seq == NULL) {
                ins->next = NULL;
@@ -144,7 +146,8 @@
                ins_keyseq (&(*seq)->next, ins);
 }
 
-static void init_keyseq (void)
+static void
+init_keyseq (void)
 {
        /*
         * XXX XXX XXX THIS SHOULD BE NUKED FROM ORBIT!  DO THIS
@@ -167,7 +170,8 @@
        }
 }
 
-static int mgetch(WINDOW *w)
+static int
+mgetch(WINDOW *w)
 {
        static char buf[20];
        static int  num = 0;
@@ -196,7 +200,8 @@
        return ret;
 }
 
-static int menucmd (WINDOW *w)
+static int
+menucmd (WINDOW *w)
 {
        int ch;
 
@@ -234,7 +239,8 @@
        }
 }
 
-static void init_menu (struct menudesc *m)
+static void
+init_menu (struct menudesc *m)
 {
        int wmax;
        int hadd, wadd, exithadd;
@@ -309,7 +315,8 @@
        } 
 }
 
-static char opt_ch (int op_no)
+static char
+opt_ch (int op_no)
 {
        char c;
        if (op_no < 25) {
@@ -320,7 +327,8 @@
        return (char) c;
 }
 
-static void post_menu (struct menudesc *m)
+static void
+post_menu (struct menudesc *m)
 {
        int i;
        int hasbox, cury, maxy, selrow, lastopt;
@@ -364,8 +372,10 @@
                        selrow = cury;
                } else
                        mvwaddstr (m->mw, cury, hasbox, " ");
-               (void) sprintf (optstr, "%c: ", opt_ch(i));
-               waddstr (m->mw, optstr);
+               if (! (m->mopt & MC_NOSHORTCUT)) {
+                       (void) sprintf (optstr, "%c: ", opt_ch(i));
+                       waddstr (m->mw, optstr);
+               }
                waddstr (m->mw, m->opts[i].opt_name);
                if (m->cursel == i)
                        wstandend(m->mw);
@@ -379,7 +389,8 @@
                        selrow = cury;
                } else
                        mvwaddstr (m->mw, cury, hasbox, " ");
-               waddstr (m->mw, "x: ");
+               if (! (m->mopt & MC_NOSHORTCUT))
+                       waddstr (m->mw, "x: ");
                waddstr (m->mw, m->exitstr);
                if (m->cursel >= m->numopts)
                        wstandend(m->mw);
@@ -400,7 +411,8 @@
        wmove(m->mw, selrow, hasbox);
 }
 
-static void process_help (struct menudesc *m, int num)
+static void
+process_help (struct menudesc *m, int num)
 {
        char *help = m->helpstr;
        int lineoff = 0;
@@ -479,7 +491,8 @@
                (*m->post_act)();
 }
 
-static void process_req (struct menudesc *m, int num, int req)
+static void
+process_req (struct menudesc *m, int num, int req)
 {
        int ch;
        int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1 );
@@ -528,6 +541,7 @@
                        mbeep();
                else {
                        m->topline = MAX(0,m->topline-m->h+1);
+                       m->cursel = MAX(0, m->cursel-m->h+1);
                        wclear (m->mw);
                        refresh = 1;
                }
@@ -540,6 +554,7 @@
                else {
                        m->topline = MIN(m->topline+m->h-1,
                                         m->numopts+hasexit-m->h+1);
+                       m->cursel = MIN(m->numopts-1, m->cursel+m->h-1);
                        wclear (m->mw);
                        refresh = 1;
                }
@@ -551,19 +566,21 @@
                        scroll_sel = 1;
                        refresh = 1;
                } else {
-                       if (ch > 'z')
-                               ch = 255;
-                       if (ch >= 'a') {
-                               if (ch > 'x') ch--;
-                               ch = ch - 'a';
-                       } else
-                               ch = 25 + ch - 'A';
-                       if (ch < 0 || ch >= m->numopts)
-                               mbeep();
-                       else {
-                               m->cursel = ch;
-                               scroll_sel = 1;
-                               refresh = 1;
+                       if (! (m->mopt & MC_NOSHORTCUT)) {
+                               if (ch > 'z')
+                                       ch = 255;
+                               if (ch >= 'a') {
+                                       if (ch > 'x') ch--;
+                                       ch = ch - 'a';
+                               } else
+                                       ch = 25 + ch - 'A';
+                               if (ch < 0 || ch >= m->numopts)
+                                       mbeep();
+                               else {
+                                       m->cursel = ch;
+                                       scroll_sel = 1;
+                                       refresh = 1;
+                               }
                        }
                }
        }
@@ -582,7 +599,8 @@
        }
 }
 
-int menu_init (void)
+int
+menu_init (void)
 {
 
        if (__menu_init)
@@ -613,7 +631,8 @@
        return (0);
 }
 
-void process_menu (int num)
+void
+process_menu (int num)
 {
        int sel = 0;
        int req, done;
@@ -670,7 +689,7 @@
                                __m_endwin = 1;
                        }
                        if (m->opts[sel].opt_action)
-                               done = (*m->opts[sel].opt_action)();
+                               done = (*m->opts[sel].opt_action)(m);
                        if (m->opts[sel].opt_menu != -1) {
                                if (m->opts[sel].opt_flags & OPT_SUB)
                                        process_menu (m->opts[sel].opt_menu);
@@ -708,7 +727,8 @@
 /* local prototypes */
 static int double_menus (void);
 
-static int double_menus (void)
+static int
+double_menus (void)
 {
        menudesc *temp;
 
@@ -727,7 +747,8 @@
        return 1;
 }
 
-int new_menu (char * title, menu_ent * opts, int numopts, 
+int
+new_menu (char * title, menu_ent * opts, int numopts, 
         int x, int y, int h, int w, int mopt,
         void (*post_act)(void), void (*exit_act), char * help)
 {
@@ -745,7 +766,7 @@
        /* if ix == num_menus ... panic */
 
        /* Set Entries */
-       menus[ix].title = title;
+       menus[ix].title = title?title:"";
        menus[ix].opts = opts;
        menus[ix].numopts = numopts;
        menus[ix].x = x;
@@ -763,7 +784,8 @@
        return ix;
 }
 
-void free_menu (int menu_no)
+void
+free_menu (int menu_no)
 {
        if (menu_no < num_menus) {
                menus[menu_no].mopt &= ~MC_VALID;



Home | Main Index | Thread Index | Old Index