Subject: Menu for disk selection
To: None <tech-install@netbsd.org>
From: Julio Merino <jmmv@menta.net>
List: tech-install
Date: 01/22/2003 15:18:46
Hello,

we are currently using menus in sysinst to allow the selection of almost
every tunnable option. One thing that does not use menus is the disk
selection (the second question shown if multiple disks are present).

What about changing this to use menus? The following patch should do it
(tested with two disks). How does it look?

Index: disks.c
===================================================================
RCS file: /cvsroot/src/distrib/utils/sysinst/disks.c,v
retrieving revision 1.49
diff -u -u -r1.49 disks.c
--- disks.c	2003/01/12 21:49:50	1.49
+++ disks.c	2003/01/22 14:04:28
@@ -75,7 +75,16 @@
 static int target_mount_with_error_menu(const char *opt, char *diskpart,
 					const char *mntpt);
 
+static menu_ent dsk_menu[MAX_DISKS];
 
+static int
+set_dsk_select(menudesc *m)
+{
+	if (m)
+		strcpy(diskdev, m->opts[m->cursel].opt_name);
+	return 0;
+}
+
 static void
 get_disks(void)
 {
@@ -99,6 +108,12 @@
 				disks[numdisks].dd_sec = l.d_nsectors;
 				disks[numdisks].dd_secsize = l.d_secsize;
 				disks[numdisks].dd_totsec = l.d_secperunit;
+				dsk_menu[numdisks].opt_name = strdup(d_name);
+				if (dsk_menu[numdisks].opt_name == NULL)
+					dsk_menu[numdisks].opt_name = "*";
+				dsk_menu[numdisks].opt_menu = OPT_NOMENU;
+				dsk_menu[numdisks].opt_flags = OPT_EXIT;
+				dsk_menu[numdisks].opt_action = set_dsk_select;
 				numdisks++;
 			}
 		}
@@ -110,9 +125,8 @@
 int
 find_disks(void)
 {
-	char *tp;
-	char defname[STRSIZE];
 	int  i;
+	int  menu_no;
 
 	/* initialize */
 	disknames[0] = 0;
@@ -140,26 +154,19 @@
 		strcpy(diskdev, disknames);
 	} else {
 		/* Multiple disks found! */
-		strcpy(defname, disknames);
-		tp = defname;
-		strsep(&tp, " ");
-		msg_prompt(MSG_askdisk, defname,  diskdev, 10, disknames);
-		tp = diskdev;
-		strsep(&tp, " ");
-		diskdev[strlen(diskdev)+1] = 0;
-		diskdev[strlen(diskdev)] = ' ';
-		while (!ISDISKSTART(*diskdev) ||
-		       strstr(disknames, diskdev) == NULL) {
-			msg_prompt(MSG_badname, defname,  diskdev, 10,
-				    disknames);
-			tp = diskdev;
-			strsep(&tp, " ");
-			diskdev[strlen(diskdev)+1] = 0;
-			diskdev[strlen(diskdev)] = ' ';
-		}
-
-		/* Remove that space we added. */
-		diskdev[strlen(diskdev)-1] = 0;
+		menu_no = new_menu("Available disks",
+		                   dsk_menu, numdisks, 32, 9, 6, 15,
+		                   MC_SCROLL | MC_NOSHORTCUT | MC_NOEXITOPT,
+		                   NULL, NULL,
+		                   "\nPlease consult the install documents.");
+		if (menu_no < 0)
+			return -1;
+		msg_display(MSG_askdisk);
+		process_menu(menu_no);
+		free_menu(menu_no);
+		for (i = 0; i < numdisks; i++)
+			free(dsk_menu[i].opt_name);
+		free(dsk_menu);
 	}
 	
 	/* Set disk. */
Index: msg.mi.en
===================================================================
RCS file: /cvsroot/src/distrib/utils/sysinst/msg.mi.en,v
retrieving revision 1.95
diff -u -u -r1.95 msg.mi.en
--- msg.mi.en	2003/01/22 05:59:07	1.95
+++ msg.mi.en	2003/01/22 14:05:18
@@ -118,13 +118,7 @@
 }
 
 message askdisk
-{I have found the following disks: %s
-\nOn which disk do you want to install NetBSD? }
-
-message badname
-{You did not choose one of the listed disks.  Please try again.
-The following disks are available: %s
-\nOn which disk do you want to install NetBSD? }
+{On which disk do you want to install NetBSD?}
 
 message disktoosmall
 {Your hard disk is too small for a standard install. You will have to enter


Thanks!

-- 
Julio M. Merino Vidal <jmmv@menta.net>
The NetBSD Project - http://www.NetBSD.org/