Module Name:    src
Committed By:   martin
Date:           Wed Jan  9 19:43:37 UTC 2019

Modified Files:
        src/usr.bin/menuc: mdb.c menu_sys.def

Log Message:
Allow argument expansion in menu titles as well.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/menuc/mdb.c
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/menuc/menu_sys.def

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/menuc/mdb.c
diff -u src/usr.bin/menuc/mdb.c:1.48 src/usr.bin/menuc/mdb.c:1.49
--- src/usr.bin/menuc/mdb.c:1.48	Fri Jan  4 15:27:19 2019
+++ src/usr.bin/menuc/mdb.c	Wed Jan  9 19:43:37 2019
@@ -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 @@ write_menu_file(char *initcode)
 		"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 @@ write_menu_file(char *initcode)
 		"#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 @@ write_menu_file(char *initcode)
 	(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 @@ write_menu_file(char *initcode)
 		(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");

Index: src/usr.bin/menuc/menu_sys.def
diff -u src/usr.bin/menuc/menu_sys.def:1.63 src/usr.bin/menuc/menu_sys.def:1.64
--- src/usr.bin/menuc/menu_sys.def:1.63	Sun Jan  6 11:08:34 2019
+++ src/usr.bin/menuc/menu_sys.def	Wed Jan  9 19:43:37 2019
@@ -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 @@ init_menu(menudesc *m)
 	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 @@ draw_menu(menudesc *m, void *arg)
 	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 @@ draw_menu(menudesc *m, void *arg)
 	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 @@ free_exp_menu_items(menudesc *m)
 {
 	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 @@ new_menu(const char *title, menu_ent *op
 
 	/* Set Entries */
 	m->title = title;
+#ifdef MENU_EXPANDS
+	m->exp_title = NULL;
+#endif
 	m->opts = opts;
 	m->numopts = numopts;
 	m->x = x;

Reply via email to