Module Name:    src
Committed By:   martin
Date:           Wed Aug  6 10:03:49 UTC 2014

Modified Files:
        src/usr.sbin/sysinst: defs.h menus.mi partman.c

Log Message:
Remove a few menu entries if raid/lvm/cgd/gpt are not available.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/sysinst/defs.h \
    src/usr.sbin/sysinst/partman.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/sysinst/menus.mi

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

Modified files:

Index: src/usr.sbin/sysinst/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.2 src/usr.sbin/sysinst/defs.h:1.3
--- src/usr.sbin/sysinst/defs.h:1.2	Sun Aug  3 16:09:38 2014
+++ src/usr.sbin/sysinst/defs.h	Wed Aug  6 10:03:49 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: defs.h,v 1.2 2014/08/03 16:09:38 martin Exp $	*/
+/*	$NetBSD: defs.h,v 1.3 2014/08/06 10:03:49 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -412,6 +412,10 @@ char dist_postfix[SSTRSIZE];
 /* needed prototypes */
 void set_menu_numopts(int, int);
 void remove_color_options(void);
+void remove_raid_options(void);
+void remove_lvm_options(void);
+void remove_cgd_options(void);
+void remove_gpt_options(void);
 
 /* Machine dependent functions .... */
 void	md_init(void);
Index: src/usr.sbin/sysinst/partman.c
diff -u src/usr.sbin/sysinst/partman.c:1.2 src/usr.sbin/sysinst/partman.c:1.3
--- src/usr.sbin/sysinst/partman.c:1.2	Tue Aug  5 08:39:39 2014
+++ src/usr.sbin/sysinst/partman.c	Wed Aug  6 10:03:49 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: partman.c,v 1.2 2014/08/05 08:39:39 martin Exp $ */
+/*	$NetBSD: partman.c,v 1.3 2014/08/06 10:03:49 martin Exp $ */
 
 /*
  * Copyright 2012 Eugene Lozovoy
@@ -2707,6 +2707,15 @@ partman(void)
 		have_gpt = binary_available("gpt");
 		have_dk = binary_available("dkctl");
 
+		if (!have_raid)
+			remove_raid_options();
+		if (!have_lvm)
+			remove_lvm_options();
+		if (!have_gpt)
+			remove_gpt_options();
+		if (!have_cgd)
+			remove_cgd_options();
+
 		raids_t_info = (structinfo_t) {
 			.max = MAX_RAID,
 			.entry_size = sizeof raids[0],

Index: src/usr.sbin/sysinst/menus.mi
diff -u src/usr.sbin/sysinst/menus.mi:1.3 src/usr.sbin/sysinst/menus.mi:1.4
--- src/usr.sbin/sysinst/menus.mi:1.3	Mon Aug  4 08:50:13 2014
+++ src/usr.sbin/sysinst/menus.mi	Wed Aug  6 10:03:49 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: menus.mi,v 1.3 2014/08/04 08:50:13 martin Exp $	*/
+/*	$NetBSD: menus.mi,v 1.4 2014/08/06 10:03:49 martin Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,19 +62,14 @@ src_prompt(const char *prompt, char *buf
 	msg_prompt_win(prompt, -1, 12, 0, 0, buf, buf, size);
 }
 
-void
-remove_color_options()
+static void
+remove_sub_menu(int menuID)
 {
-	/*
-	 * Current terminal type does not support colors, so remove all
-	 * menu entries (actually that is: Utils/Color Scheme) that do not
-	 * make any sense in this case.
-	 */
 
 	for (size_t i = 0; i < DYN_MENU_START; i++) {
 		for (int j = 0; j < menu_def[i].numopts; j++) {
 			if ((menu_def[i].opts[j].opt_flags & OPT_SUB)
-			    && menu_def[i].opts[j].opt_menu == MENU_colors) {
+			    && menu_def[i].opts[j].opt_menu == menuID) {
 
 				for (int k = j + 1; k < menu_def[i].numopts;
 				    k++) {
@@ -89,6 +84,75 @@ remove_color_options()
 	}
 }
 
+static void
+remove_menu_option(int menuID, const char *option)
+{
+
+	for (int j = 0; j < menu_def[menuID].numopts; j++) {
+		if (menu_def[menuID].opts[j].opt_name == option) {
+			for (int k = j + 1; k < menu_def[menuID].numopts;
+			    k++) {
+				menu_def[menuID].opts[k-1] =
+				    menu_def[menuID].opts[k];
+			}
+			menu_def[menuID].numopts--;
+			return;
+
+		}
+	}
+}
+
+void
+remove_color_options()
+{
+	/*
+	 * Current terminal type does not support colors, so remove all
+	 * menu entries (actually that is: Utils/Color Scheme) that do not
+	 * make any sense in this case.
+	 */
+	remove_sub_menu(MENU_colors);
+}
+
+void
+remove_raid_options()
+{
+	/*
+	 * No raidframe available, remove the following menu entries:
+	 */
+	remove_menu_option(MENU_pmdiskentry, MSG_fmtasraid);
+	remove_menu_option(MENU_pmpartentry, MSG_fmtasraid);
+}
+
+void
+remove_lvm_options()
+{
+	/*
+	 * No LVM available, remove the following menu entries:
+	 */
+	remove_menu_option(MENU_pmdiskentry, MSG_fmtaslvm);
+	remove_menu_option(MENU_pmpartentry, MSG_fmtaslvm);
+}
+
+void
+remove_gpt_options()
+{
+	/*
+	 * No GPT available, remove the following menu entries:
+	 */
+	remove_menu_option(MENU_pmdiskentry, MSG_switchgpt);
+	remove_menu_option(MENU_pmpartentry, MSG_switchgpt);
+}
+
+void
+remove_cgd_options()
+{
+	/*
+	 * No CGD available, remove the following menu entries:
+	 */
+	remove_menu_option(MENU_pmdiskentry, MSG_encrypt);
+	remove_menu_option(MENU_pmpartentry, MSG_encrypt);
+}
+
 }
 
 default y=12, no exit, scrollable;

Reply via email to