Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/menuc Allow argument expansion in menu titles as well.



details:   https://anonhg.NetBSD.org/src/rev/71819bc36c3a
branches:  trunk
changeset: 447402:71819bc36c3a
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Jan 09 19:43:37 2019 +0000

description:
Allow argument expansion in menu titles as well.

diffstat:

 usr.bin/menuc/mdb.c        |  33 +++++++++++++++++++++++----------
 usr.bin/menuc/menu_sys.def |  28 ++++++++++++++++++++++++----
 2 files changed, 47 insertions(+), 14 deletions(-)

diffs (145 lines):

diff -r 94373b9e2a75 -r 71819bc36c3a usr.bin/menuc/mdb.c
--- a/usr.bin/menuc/mdb.c       Wed Jan 09 19:01:24 2019 +0000
+++ b/usr.bin/menuc/mdb.c       Wed Jan 09 19:43:37 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mdb.c,v 1.48 2019/01/04 15:27:19 martin Exp $  */
+/*     $NetBSD: mdb.c,v 1.49 2019/01/09 19:43:37 martin Exp $  */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -41,7 +41,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mdb.c,v 1.48 2019/01/04 15:27:19 martin Exp $");
+__RCSID("$NetBSD: mdb.c,v 1.49 2019/01/09 19:43:37 martin Exp $");
 #endif
 
 
@@ -172,10 +172,11 @@
                "typedef struct menudesc menudesc;\n"   
                "typedef struct menu_ent menu_ent;\n"   
                "struct menu_ent {\n"
-               "       const char      *opt_name;\n"
-               "#ifdef MENU_EXPANDS\n"
-               "       const char      *opt_exp_name;\n"
-               "#endif\n"
+               "       const char      *opt_name;\n");
+       if (do_expands)
+               (void)fprintf(out_file,
+               "       const char      *opt_exp_name;\n");
+       (void)fprintf(out_file,
                "       int             opt_menu;\n"
                "       int             opt_flags;\n"
                "       int             (*opt_action)(menudesc *, void *);\n"
@@ -187,7 +188,11 @@
                "#define OPT_NOSHORT    16\n"
                "#define OPT_NOMENU     -1\n\n"
                "struct menudesc {\n"
-               "       const char      *title;\n"
+               "       const char      *title;\n");
+       if (do_expands)
+               (void)fprintf(out_file,
+               "       const char      *exp_title;\n");
+       (void)fprintf(out_file,
                "       int             y, x;\n"
                "       int             h, w;\n"
                "       int             mopt;\n"
@@ -367,8 +372,13 @@
        (void)fprintf(out_file, "static struct menudesc menu_def[] = {\n");
        for (i = 0; i < menu_no; i++) {
                (void)fprintf(out_file,
-                       "\t{%s,%d,%d,%d,%d,%d,%d,0,0,optent%d,NULL,NULL,",
-                       menus[i]->info->title,  menus[i]->info->y,
+                       "\t{%s,", menus[i]->info->title);
+               if (do_expands)
+                       (void)fprintf(out_file,
+                               "NULL,");
+               (void)fprintf(out_file,
+                       "%d,%d,%d,%d,%d,%d,0,0,optent%d,NULL,NULL,",
+                       menus[i]->info->y,
                        menus[i]->info->x, menus[i]->info->h,
                        menus[i]->info->w, menus[i]->info->mopt,
                        menus[i]->info->numopt, i);
@@ -422,7 +432,10 @@
                (void)fprintf(out_file, "},\n");
 
        }
-       (void)fprintf(out_file, "{NULL, 0, 0, 0, 0, 0, 0, 0, 0, "
+       (void)fprintf(out_file, "{NULL");
+       if (do_expands)
+               (void)fprintf(out_file, ", NULL");
+       (void)fprintf(out_file, ", 0, 0, 0, 0, 0, 0, 0, 0, "
                "NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL");
        if (do_expands)
                (void)fprintf(out_file, ", NULL");
diff -r 94373b9e2a75 -r 71819bc36c3a usr.bin/menuc/menu_sys.def
--- a/usr.bin/menuc/menu_sys.def        Wed Jan 09 19:01:24 2019 +0000
+++ b/usr.bin/menuc/menu_sys.def        Wed Jan 09 19:43:37 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menu_sys.def,v 1.63 2019/01/06 11:08:34 martin Exp $   */
+/*     $NetBSD: menu_sys.def,v 1.64 2019/01/09 19:43:37 martin Exp $   */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -146,7 +146,14 @@
        if (!(m->mopt & MC_NOSHORTCUT))
                wadd += 3;
 
-       if (m->title && *(title = MSG_XLAT(m->title)) != 0) {
+       title = m->title;
+#ifdef MENU_EXPANDS
+       if (m->exp_title)
+               title = m->exp_title;
+#endif
+       if (title)
+               title = MSG_XLAT(title);
+       if (title && title[0] != 0) {
                /* Allow multiple line titles */
                for (tp = title; (ep = strchr(tp, '\n')); tp = ep + 1) {
                        i = ep - tp;
@@ -330,6 +337,7 @@
        int tadd;
        int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
        const char *tp, *ep;
+       const char *title;
        
        hasbox = (m->mopt & MC_NOBOX ? 0 : 1);
 
@@ -337,8 +345,13 @@
        wclear(m->mw);
 
        tadd = hasbox;
-       if (m->title) {
-               for (tp = MSG_XLAT(m->title); ; tp = ep + 1) {
+       title = m->title;
+#ifdef MENU_EXPANDS
+       if (m->exp_title)
+               title = m->exp_title;
+#endif
+       if (title) {
+               for (tp = MSG_XLAT(title); ; tp = ep + 1) {
                        ep = strchr(tp , '\n');
                        mvwaddnstr(m->mw, tadd++, hasbox + 1, tp,
                            ep ? ep - tp : -1);
@@ -505,6 +518,10 @@
 {
        int i;
 
+       if (m->exp_title != NULL) {
+               free(__UNCONST(m->exp_title));
+               m->exp_title = NULL;
+       }
        for (i = 0; i < m->numopts; i++) {
                if (m->opts[i].opt_exp_name != NULL) {
                        free(__UNCONST(m->opts[i].opt_exp_name));
@@ -841,6 +858,9 @@
 
        /* Set Entries */
        m->title = title;
+#ifdef MENU_EXPANDS
+       m->exp_title = NULL;
+#endif
        m->opts = opts;
        m->numopts = numopts;
        m->x = x;



Home | Main Index | Thread Index | Old Index