4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * This file contains routines relating to running the menus.
38 /* Function prototypes for ANSI C Compilers */
39 static int (*find_enabled_menu_item())(struct menu_item
*menu
, int item
);
43 /* Function prototypes for non-ANSI C Compilers */
44 static int (*find_enabled_menu_item())();
48 static char cur_title
[MAXPATHLEN
];
51 * This routine takes a menu struct and concatenates the
52 * command names into an array of strings describing the menu.
53 * All menus have a 'quit' command at the bottom to exit the menu.
56 create_menu_list(menu
)
57 struct menu_item
*menu
;
59 register struct menu_item
*mptr
;
60 register char **cpptr
;
65 * A minimum list consists of the quit command, followed
66 * by a terminating null.
70 * Count the number of active commands in the menu and allocate
71 * space for the array of pointers.
73 for (mptr
= menu
; mptr
->menu_cmd
!= NULL
; mptr
++) {
74 if ((*mptr
->menu_state
)())
77 list
= (char **)zalloc(nitems
* sizeof (char *));
80 * Fill in the array with the names of the menu commands.
82 for (mptr
= menu
; mptr
->menu_cmd
!= NULL
; mptr
++) {
83 if ((*mptr
->menu_state
)()) {
84 *cpptr
++ = mptr
->menu_cmd
;
88 * Add the 'quit' command to the end.
95 * This routine takes a menu list created by the above routine and
96 * prints it nicely on the screen.
99 display_menu_list(list
)
104 for (str
= list
; *str
!= NULL
; str
++)
105 fmt_print(" %s\n", *str
);
109 * Find the "i"th enabled menu in a menu list. This depends
110 * on menu_state() returning the same status as when the
111 * original list of enabled commands was constructed.
114 find_enabled_menu_item(menu
, item
))()
115 struct menu_item
*menu
;
118 struct menu_item
*mp
;
120 for (mp
= menu
; mp
->menu_cmd
!= NULL
; mp
++) {
121 if ((*mp
->menu_state
)()) {
123 return (mp
->menu_func
);
132 * This routine 'runs' a menu. It repeatedly requests a command and
133 * executes the command chosen. It exits when the 'quit' command is
138 run_menu(menu
, title
, prompt
, display_flag
)
139 struct menu_item
*menu
;
152 * Create the menu list and display it.
154 list
= create_menu_list(menu
);
155 (void) strcpy(cur_title
, title
);
156 fmt_print("\n\n%s MENU:\n", title
);
157 display_menu_list(list
);
159 * Save the environment so a ctrl-C out of a command lands here.
164 * Ask the user which command they want to run.
166 ioparam
.io_charlist
= list
;
167 i
= input(FIO_MSTR
, prompt
, '>', &ioparam
,
168 (int *)NULL
, CMD_INPUT
);
170 * If they choose 'quit', the party's over.
172 if ((f
= find_enabled_menu_item(menu
, i
)) == NULL
)
176 * Mark the saved environment active so the user can now
177 * do a ctrl-C to get out of the command.
181 * Run the command. If it returns an error and we are
182 * running out of a command file, the party's really over.
184 if ((*f
)() && option_f
)
187 * Mark the saved environment inactive so ctrl-C doesn't
188 * work at the menu itself.
192 * Since menu items are dynamic, some commands
193 * cause changes to occur. Destroy the old menu,
194 * and rebuild it, so we're always up-to-date.
196 destroy_data((char *)list
);
197 list
= create_menu_list(menu
);
199 * Redisplay menu, if we're returning to this one.
201 if (cur_menu
!= last_menu
) {
202 last_menu
= cur_menu
;
203 (void) strcpy(cur_title
, title
);
204 fmt_print("\n\n%s MENU:\n", title
);
205 display_menu_list(list
);
209 * Clean up the environment stack and throw away the menu list.
212 destroy_data((char *)list
);
216 * re-display the screen after exiting from shell escape
220 redisplay_menu_list(list
)
223 fmt_print("\n\n%s MENU:\n", cur_title
);
224 display_menu_list(list
);
229 * Glue to always return true. Used for menu items which
230 * are always enabled.
239 * Note: The following functions are used to enable the inclusion
240 * of device specific options (see init_menus.c). But when we are
241 * running non interactively with commands taken from a script file,
242 * current disk (cur_disk, cur_type, cur_ctype) may not be defined.
243 * They get defined when the script selects a disk using "disk" option
244 * in the main menu. However, in the normal interactive mode, the disk
245 * selection happens before entering the main menu.
248 * Return true for menu items enabled only for embedded SCSI controllers
253 if (cur_ctype
== NULL
&& option_f
)
255 return (EMBEDDED_SCSI
);
259 * Return false for menu items disabled only for embedded SCSI controllers
264 if (cur_ctype
== NULL
&& option_f
)
266 return (!EMBEDDED_SCSI
);
270 * Return false for menu items disabled for scsi controllers
275 if (cur_ctype
== NULL
&& option_f
)
281 * Return false for menu items disabled for efi labels
286 if ((cur_disk
== NULL
) && option_f
)
288 if (cur_disk
->label_type
== L_TYPE_EFI
)
294 disp_expert_change_expert_efi()
296 if ((cur_disk
== NULL
) && option_f
)
298 if ((cur_disk
->label_type
== L_TYPE_EFI
) && expert_mode
)
300 if (cur_disk
->label_type
!= L_TYPE_EFI
)
308 if ((cur_disk
== NULL
) && option_f
)
310 if (cur_disk
->label_type
!= L_TYPE_EFI
)
312 if (cur_parts
== NULL
)
318 disp_all_change_expert_efi()
320 if ((cur_disk
== NULL
) && option_f
)
322 if ((cur_disk
->label_type
!= L_TYPE_EFI
) || (!expert_mode
))
328 * Return true for menu items enabled scsi controllers
333 if (cur_ctype
== NULL
&& option_f
)
340 * Return true for menu items enabled if expert mode is enabled
345 if (cur_ctype
== NULL
&& option_f
)
347 return (SCSI
&& expert_mode
);
352 * Return true for menu items enabled if expert mode is enabled
357 return (expert_mode
);
359 #endif /* defined(i386) */
362 * Return true for menu items enabled if developer mode is enabled
371 * For x86, always return true for menu items enabled
372 * since fdisk is already supported on these two platforms.
373 * For Sparc, only return true for menu items enabled
374 * if a PCATA disk is selected.
377 support_fdisk_on_sparc()
381 * If it's a SCSI disk then we don't support fdisk and we
382 * don't need to know the type cause we can ask the disk,
383 * therefore we return true only if we *KNOW* it's an ATA
386 if (cur_ctype
&& cur_ctype
->ctype_ctype
== DKC_PCMCIA_ATA
) {
394 #error No Platform defined
395 #endif /* defined(sparc) */