diff --git a/usr.sbin/sade/Makefile b/usr.sbin/sade/Makefile index f61473ab463a..f78859fe5cc6 100644 --- a/usr.sbin/sade/Makefile +++ b/usr.sbin/sade/Makefile @@ -19,9 +19,10 @@ WARNS?= 3 .if ${MACHINE} == "pc98" CFLAGS+= -DPC98 .endif -CFLAGS+= -I${.CURDIR}/../../gnu/lib/libodialog -I. +CFLAGS+= -I${.CURDIR}/../../contrib/dialog -I. +DEBUG_FLAGS= -O0 -g -DPADD= ${LIBODIALOG} ${LIBNCURSES} ${LIBUTIL} ${LIBDISK} -LDADD= -lodialog -lncurses -lutil -ldisk +DPADD= ${LIBDIALOG} ${LIBNCURSESW} ${LIBM} ${LIBUTIL} ${LIBDISK} +LDADD= -ldialog -lncursesw -lm -lutil -ldisk .include <bsd.prog.mk> diff --git a/usr.sbin/sade/devices.c b/usr.sbin/sade/devices.c index 12581e4c87eb..fd7ca07b8a9d 100644 --- a/usr.sbin/sade/devices.c +++ b/usr.sbin/sade/devices.c @@ -29,7 +29,6 @@ * */ -#include "sade.h" #include <sys/fcntl.h> #include <sys/param.h> #include <sys/socket.h> @@ -40,6 +39,8 @@ #include <ctype.h> #include <libdisk.h> +#include "sade.h" + /* how much to bias minor number for a given /dev/<ct#><un#>s<s#> slice */ #define SLICE_DELTA (0x10000) @@ -247,7 +248,7 @@ deviceGetAll(void) } free(names); } - dialog_clear_norefresh(); + dlg_clear(); } /* Rescan all devices, after closing previous set - convenience function */ diff --git a/usr.sbin/sade/disks.c b/usr.sbin/sade/disks.c index bf091d44b715..513643bb8eb0 100644 --- a/usr.sbin/sade/disks.c +++ b/usr.sbin/sade/disks.c @@ -113,7 +113,7 @@ check_geometry(Disk *d) if (d->bios_cyl > 65536 || d->bios_hd > 256 || d->bios_sect >= 64) #endif { - dialog_clear_norefresh(); + dlg_clear(); sg = msgYesNo("WARNING: It is safe to use a geometry of %lu/%lu/%lu for %s on\n" "computers with modern BIOS versions. If this disk is to be used\n" "on an old machine it is recommended that it does not have more\n" @@ -223,21 +223,21 @@ getBootMgr(char *dname, u_char **bootipl, size_t *bootipl_size, char *cp; int i = 0; + dlg_clr_result(); cp = variable_get(VAR_BOOTMGR); if (!cp) { /* Figure out what kind of IPL the user wants */ sprintf(str, "Install Boot Manager for drive %s?", dname); MenuIPLType.title = str; - i = dmenuOpenSimple(&MenuIPLType, FALSE); + i = dmenuOpen(&MenuIPLType); } else { if (!strncmp(cp, "boot", 4)) - BootMgr = 0; + dlg_add_result(MenuIPLType.items[0].prompt); else - BootMgr = 1; + dlg_add_result(MenuIPLType.items[1].prompt); } if (cp || i) { - switch (BootMgr) { - case 0: + if (!strcmp(dialog_vars.input_result, MenuIPLType.items[0].prompt)) { if (!boot0) boot0 = bootalloc("boot0", &boot0_size); *bootipl = boot0; *bootipl_size = boot0_size; @@ -245,10 +245,7 @@ getBootMgr(char *dname, u_char **bootipl, size_t *bootipl_size, *bootmenu = boot05; *bootmenu_size = boot05_size; return; - case 1: - default: - break; - } + } } *bootipl = NULL; *bootipl_size = 0; @@ -266,36 +263,33 @@ getBootMgr(char *dname, u_char **bootCode, size_t *bootCodeSize) char *cp; int i = 0; + dlg_clr_result(); cp = variable_get(VAR_BOOTMGR); if (!cp) { /* Figure out what kind of MBR the user wants */ sprintf(str, "Install Boot Manager for drive %s?", dname); MenuMBRType.title = str; - i = dmenuOpenSimple(&MenuMBRType, FALSE); + i = dmenuOpen(&MenuMBRType); } else { + if (!strcmp(cp, "standard")) + dlg_add_result(MenuMBRType.items[0].prompt); if (!strncmp(cp, "boot", 4)) - BootMgr = 0; - else if (!strcmp(cp, "standard")) - BootMgr = 1; + dlg_add_result(MenuMBRType.items[1].prompt); else - BootMgr = 2; + dlg_add_result(MenuMBRType.items[2].prompt); } if (cp || i) { - switch (BootMgr) { - case 0: - if (!boot0) boot0 = bootalloc("boot0", &boot0_size); - *bootCode = boot0; - *bootCodeSize = boot0_size; - return; - case 1: + if (!strcmp(dialog_vars.input_result, MenuMBRType.items[0].prompt)) { if (!mbr) mbr = bootalloc("mbr", &mbr_size); *bootCode = mbr; *bootCodeSize = mbr_size; return; - case 2: - default: - break; + } else if (!strcmp(dialog_vars.input_result, MenuMBRType.items[1].prompt)) { + if (!boot0) boot0 = bootalloc("boot0", &boot0_size); + *bootCode = boot0; + *bootCodeSize = boot0_size; + return; } } #endif @@ -333,7 +327,7 @@ diskPartition(Device *dev) /* Flush both the dialog and curses library views of the screen since we don't always know who called us */ - dialog_clear_norefresh(), clear(); + dlg_clear(), clear(); current_chunk = 0; /* Set up the chunk array */ @@ -705,12 +699,15 @@ diskPartition(Device *dev) p = CheckRules(d); if (p) { char buf[FILENAME_MAX]; - - use_helpline("Press F1 to read more about disk slices."); - use_helpfile(systemHelpFile("partition", buf)); + DIALOG_VARS save_vars; + + dlg_save_vars(&save_vars); + dialog_vars.help_line = "Press F1 to read more about disk slices."; + dialog_vars.help_file = systemHelpFile("partition", buf); if (!variable_get(VAR_NO_WARN)) - dialog_mesgbox("Disk slicing warning:", p, -1, -1); + xdialog_msgbox("Disk slicing warning:", p, -1, -1, 1); free(p); + dlg_restore_vars(&save_vars); } restorescr(w); } @@ -751,7 +748,7 @@ bootalloc(char *name, size_t *size) } #endif /* !__ia64__ */ -#ifdef WITH_SLICES +#ifdef WITH_SLICES static int partitionHook(dialogMenuItem *selected) { @@ -804,7 +801,7 @@ diskPartitionEditor(dialogMenuItem *self) return DITEM_FAILURE; } - result = dmenuOpenSimple(menu, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE; + result = dmenuOpen(menu) ? DITEM_SUCCESS : DITEM_FAILURE; free(menu); return result; } diff --git a/usr.sbin/sade/dmenu.c b/usr.sbin/sade/dmenu.c index 139f999e6ae1..186c1e95f8a7 100644 --- a/usr.sbin/sade/dmenu.c +++ b/usr.sbin/sade/dmenu.c @@ -34,196 +34,6 @@ #define MAX_MENU 15 -static Boolean exited; - -int -dmenuDisplayFile(dialogMenuItem *tmp) -{ - systemDisplayHelp((char *)tmp->data); - return DITEM_SUCCESS; -} - -int -dmenuSubmenu(dialogMenuItem *tmp) -{ - return (dmenuOpenSimple((DMenu *)(tmp->data), FALSE) ? DITEM_SUCCESS : DITEM_FAILURE); -} - -int -dmenuSystemCommand(dialogMenuItem *self) -{ - WINDOW *w = NULL; /* Keep lint happy */ - - /* If aux is set, the command is known not to produce any screen-spoiling output */ - if (!self->aux) - w = savescr(); - systemExecute((char *)self->data); - if (!self->aux) - restorescr(w); - return DITEM_SUCCESS; -} - -int -dmenuSystemCommandBox(dialogMenuItem *tmp) -{ - WINDOW *w = savescr(); - - use_helpfile(NULL); - use_helpline("Select OK to dismiss this dialog"); - dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1); - restorescr(w); - return DITEM_SUCCESS; -} - -int -dmenuExit(dialogMenuItem *tmp) -{ - exited = TRUE; - return DITEM_LEAVE_MENU; -} - -int -dmenuSetVariable(dialogMenuItem *tmp) -{ - variable_set((char *)tmp->data, *((char *)tmp->data) != '_'); - return DITEM_SUCCESS; -} - -int -dmenuSetVariables(dialogMenuItem *tmp) -{ - char *cp1, *cp2; - char *copy = strdup((char *)tmp->data); - - for (cp1 = copy; cp1 != NULL;) { - cp2 = index(cp1, ','); - if (cp2 != NULL) *cp2++ = '\0'; - variable_set(cp1, *cp1 != '_'); - cp1 = cp2; - } - free(copy); - return DITEM_SUCCESS; -} - -int -dmenuToggleVariable(dialogMenuItem *tmp) -{ - char *var, *cp; - int status; - - if (!(var = strdup((char *)tmp->data))) { - msgConfirm("Incorrect data field for `%s'!", tmp->title); - return DITEM_FAILURE; - } - if (!(cp = index(var, '='))) { - msgConfirm("Data field for %s is not in var=value format!", tmp->title); - return DITEM_FAILURE; - } - status = variable_check(var); - *cp = '\0'; - variable_set2(var, status ? "NO" : "YES", *var != '_'); - free(var); - return DITEM_SUCCESS; -} - -int -dmenuISetVariable(dialogMenuItem *tmp) -{ - char *ans, *var; - - if (!(var = (char *)tmp->data)) { - msgConfirm("Incorrect data field for `%s'!", tmp->title); - return DITEM_FAILURE; - } - ans = msgGetInput(variable_get(var), tmp->title, 1); - if (!ans) - return DITEM_FAILURE; - else if (!*ans) - variable_unset(var); - else - variable_set2(var, ans, *var != '_'); - return DITEM_SUCCESS; -} - -int -dmenuSetFlag(dialogMenuItem *tmp) -{ - if (*((unsigned int *)tmp->data) & tmp->aux) - *((unsigned int *)tmp->data) &= ~tmp->aux; - else - *((unsigned int *)tmp->data) |= tmp->aux; - return DITEM_SUCCESS; -} - -int -dmenuSetValue(dialogMenuItem *tmp) -{ - *((unsigned int *)tmp->data) = tmp->aux; - return DITEM_SUCCESS; -} - -/* Traverse menu but give user no control over positioning */ -Boolean -dmenuOpenSimple(DMenu *menu, Boolean buttons) -{ - int choice, scroll, curr, max; - - choice = scroll = curr = max = 0; - return dmenuOpen(menu, &choice, &scroll, &curr, &max, buttons); -} - -/* Work functions for the state hook */ -int -dmenuFlagCheck(dialogMenuItem *item) -{ - return (*((unsigned int *)item->data) & item->aux); -} - -int -dmenuVarCheck(dialogMenuItem *item) -{ - char *w; - - w = (char *)item->aux; - if (!w) - w = (char *)item->data; - return variable_check(w); -} - -int -dmenuVarsCheck(dialogMenuItem *item) -{ - int res, init; - char *w, *cp1, *cp2; - char *copy; - - w = (char *)item->aux; - if (!w) - w = (char *)item->data; - if (!w) - return FALSE; - - copy = strdup(w); - res = TRUE; - init = FALSE; - for (cp1 = copy; cp1 != NULL;) { - init = TRUE; - cp2 = index(cp1, ','); - if (cp2 != NULL) - *cp2++ = '\0'; - res = res && variable_check(cp1); - cp1 = cp2; - } - free(copy); - return res && init; -} - -int -dmenuRadioCheck(dialogMenuItem *item) -{ - return (*((long *)item->data) == item->aux); -} - static int menu_height(DMenu *menu, int n) { @@ -242,54 +52,42 @@ menu_height(DMenu *menu, int n) /* Traverse over an internal menu */ Boolean -dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons) +dmenuOpen(DMenu *menu) { int n, rval = 0; - dialogMenuItem *items; - items = menu->items; - if (buttons) - items += 2; /* Count up all the items */ - for (n = 0; items[n].title; n++); + for (n = 0; menu->items[n].title; n++) + ; while (1) { char buf[FILENAME_MAX]; + DIALOG_VARS save_vars; WINDOW *w = savescr(); /* Any helpful hints, put 'em up! */ - use_helpline(menu->helpline); - use_helpfile(systemHelpFile(menu->helpfile, buf)); - dialog_clear_norefresh(); + dlg_save_vars(&save_vars); + dialog_vars.help_line = menu->helpline; + dialog_vars.help_file = systemHelpFile(menu->helpfile, buf); + dlg_clear(); /* Pop up that dialog! */ - if (menu->type & DMENU_NORMAL_TYPE) - rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt, - -1, -1, menu_height(menu, n), -n, items, - (char *)(uintptr_t)buttons, choice, scroll); - - else if (menu->type & DMENU_RADIO_TYPE) - rval = dialog_radiolist((u_char *)menu->title, - (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n, - items, (char *)(uintptr_t)buttons); - - else if (menu->type & DMENU_CHECKLIST_TYPE) - rval = dialog_checklist((u_char *)menu->title, - (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n, - items, (char *)(uintptr_t)buttons); - else + if (menu->type & DMENU_NORMAL_TYPE) { + rval = xdialog_menu(menu->title, menu->prompt, + -1, -1, menu_height(menu, n), n, menu->items); + } else if (menu->type & DMENU_RADIO_TYPE) { + rval = xdialog_radiolist(menu->title, menu->prompt, + -1, -1, menu_height(menu, n), n, menu->items); + } else { msgFatal("Menu: `%s' is of an unknown type\n", menu->title); - if (exited) { - exited = FALSE; - restorescr(w); - return TRUE; } - else if (rval) { + dlg_restore_vars(&save_vars); + if (rval) { restorescr(w); return FALSE; - } - else if (menu->type & DMENU_SELECTION_RETURNS) { + } else if (menu->type & DMENU_SELECTION_RETURNS) { restorescr(w); return TRUE; - } + } else + delwin(w); } } diff --git a/usr.sbin/sade/install.c b/usr.sbin/sade/install.c index fb95998c4275..9ae08cb87723 100644 --- a/usr.sbin/sade/install.c +++ b/usr.sbin/sade/install.c @@ -29,7 +29,6 @@ * */ -#include "sade.h" #include <ctype.h> #include <sys/consio.h> #include <sys/disklabel.h> @@ -51,6 +50,8 @@ #include <unistd.h> #include <termios.h> +#include "sade.h" + #define TERMCAP_FILE "/usr/share/misc/termcap" Boolean @@ -177,7 +178,7 @@ installFilesystems(Device *dev) sprintf(fname, "/dev/%s", c2->name); i = (Fake || swapon(fname)); if (!i) { - dialog_clear_norefresh(); + dlg_clear(); msgNotify("Added %s as an additional swap device", fname); } else { @@ -209,7 +210,7 @@ installFilesystems(Device *dev) command_sort(); command_execute(); - dialog_clear_norefresh(); + dlg_clear(); return DITEM_SUCCESS | DITEM_RESTORE; } diff --git a/usr.sbin/sade/label.c b/usr.sbin/sade/label.c index ad6216422081..8ae5fe2f289f 100644 --- a/usr.sbin/sade/label.c +++ b/usr.sbin/sade/label.c @@ -29,7 +29,7 @@ * */ -#include "sade.h" +#include <sys/types.h> #include <ctype.h> #include <inttypes.h> #include <libdisk.h> @@ -37,6 +37,8 @@ #include <sys/param.h> #include <sys/sysctl.h> +#include "sade.h" + #define AUTO_HOME 0 /* do not create /home automatically */ /* @@ -161,7 +163,7 @@ diskLabelEditor(dialogMenuItem *self) result = DITEM_FAILURE; } else { - result = dmenuOpenSimple(menu, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE; + result = dmenuOpen(menu) ? DITEM_SUCCESS : DITEM_FAILURE; free(menu); } } @@ -417,9 +419,8 @@ get_mountpoint(PartType type, struct chunk *old) static PartType get_partition_type(void) { - char selection[20]; int i; - static unsigned char *fs_types[] = { + static char *fs_types[] = { #ifdef __ia64__ "EFI", "An EFI system partition", #endif @@ -428,6 +429,7 @@ get_partition_type(void) }; WINDOW *w = savescr(); + dlg_clr_result(); i = dialog_menu("Please choose a partition type", "If you want to use this partition for swap space, select Swap.\n" "If you want to put a filesystem on it, choose FS.", @@ -437,16 +439,16 @@ get_partition_type(void) #else 2, 2, #endif - fs_types, selection, NULL, NULL); + fs_types); restorescr(w); if (!i) { #ifdef __ia64__ - if (!strcmp(selection, "EFI")) + if (!strcmp(dialog_vars.input_result, "EFI")) return PART_EFI; #endif - if (!strcmp(selection, "FS")) + if (!strcmp(dialog_vars.input_result, "FS")) return PART_FILESYSTEM; - else if (!strcmp(selection, "Swap")) + else if (!strcmp(dialog_vars.input_result, "Swap")) return PART_SWAP; } return PART_NONE; @@ -1251,7 +1253,7 @@ diskLabel(Device *dev) if (!msgNoYes("Are you sure you want to go into Wizard mode?\n\n" "This is an entirely undocumented feature which you are not\n" "expected to understand!")) { - dialog_clear(); + dlg_clear(); end_dialog(); DialogActive = FALSE; if (dev->private) { diff --git a/usr.sbin/sade/main.c b/usr.sbin/sade/main.c index 22d940110638..cb493f3f2a01 100644 --- a/usr.sbin/sade/main.c +++ b/usr.sbin/sade/main.c @@ -39,8 +39,8 @@ const char *ProgName = "sade"; int main(int argc, char **argv) { - int choice, scroll, curr, max, status; - + int status; + /* Record name to be able to restart */ StartName = argv[0]; @@ -77,7 +77,9 @@ main(int argc, char **argv) /* Try to preserve our scroll-back buffer */ if (OnVTY) { - for (curr = 0; curr < 25; curr++) + int i; + + for (i = 0; i < 25; i++) putchar('\n'); } /* Move stderr aside */ @@ -105,10 +107,9 @@ main(int argc, char **argv) } /* Begin user dialog at outer menu */ - dialog_clear(); + dlg_clear(); while (1) { - choice = scroll = curr = max = 0; - dmenuOpen(&MenuMain, &choice, &scroll, &curr, &max, FALSE); + dmenuOpen(&MenuMain); if (getpid() != 1 || !msgNoYes("Are you sure you wish to exit?") ) diff --git a/usr.sbin/sade/menus.c b/usr.sbin/sade/menus.c index b25796b1526b..886f80cdd76f 100644 --- a/usr.sbin/sade/menus.c +++ b/usr.sbin/sade/menus.c @@ -53,7 +53,7 @@ DMenu MenuDiskDevices = { "Use [TAB] to get to the buttons and leave this menu.", "Press F1 for important information regarding disk geometry!", "drives", - { { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0 } }, + { { NULL, NULL, NULL } }, }; DMenu MenuMain = { @@ -62,12 +62,12 @@ DMenu MenuMain = { "This is a utility for partitioning and/or labelling your disks.", "DISKUTIL", "main", - { + { #ifdef WITH_SLICES - { "1 Partition", "Managing disk partitions", NULL, diskPartitionEditor, NULL, NULL, 0, 0, 0, 0 }, + { "1 Partition", "Managing disk partitions", diskPartitionEditor }, #endif - { "2 Label", "Label allocated disk partitions", NULL, diskLabelEditor, NULL, NULL, 0, 0, 0, 0 }, - { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0 } + { "2 Label", "Label allocated disk partitions", diskLabelEditor }, + { NULL, NULL, NULL } }, }; @@ -75,22 +75,20 @@ DMenu MenuMain = { #ifdef PC98 /* IPL type menu */ DMenu MenuIPLType = { - DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS, + DMENU_RADIO_TYPE | DMENU_SELECTION_RETURNS, "overwrite me", /* will be disk specific label */ "If you want a FreeBSD Boot Manager, select \"BootMgr\". If you would\n" "prefer your Boot Manager to remain untouched then select \"None\".\n\n", "Press F1 to read about drive setup", "drives", - { { "BootMgr", "Install the FreeBSD Boot Manager", - dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, 0, 0, 0, 0 }, - { "None", "Leave the IPL untouched", - dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 1 }, - { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0 } }, + { { "BootMgr", "Install the FreeBSD Boot Manager", NULL }, + { "None", "Leave the IPL untouched", NULL }, + { NULL, NULL, NULL } }, }; #else /* MBR type menu */ DMenu MenuMBRType = { - DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS, + DMENU_RADIO_TYPE | DMENU_SELECTION_RETURNS, "overwrite me", /* will be disk specific label */ "FreeBSD comes with a boot manager that allows you to easily\n" "select between FreeBSD and any other operating systems on your machine\n" @@ -99,18 +97,13 @@ DMenu MenuMBRType = { "to do so (limitations in the PC BIOS usually prevent this otherwise).\n" "If you have other operating systems installed and would like a choice when\n" "booting, choose \"BootMgr\". If you would prefer to keep your existing\n" - "boot manager, select \"None\".\n\n", + "boot manager, select \"None\".\n", "", "drives", - { { "Standard", "Install a standard MBR (non-interactive boot manager)", - dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 1 }, - { "BootMgr", "Install the FreeBSD boot manager", - dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 0 }, - { "None", "Do not install a boot manager", - dmenuRadioCheck, dmenuSetValue, NULL, &BootMgr, '(', '*', ')', 2 }, - { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0 } } + { { "Standard", "Install a standard MBR (non-interactive boot manager)", NULL }, + { "BootMgr", "Install the FreeBSD boot manager", NULL }, + { "None", "Do not install a boot manager", NULL }, + { NULL, NULL, NULL } } }; #endif /* PC98 */ #endif /* __i386__ */ - - diff --git a/usr.sbin/sade/misc.c b/usr.sbin/sade/misc.c index 6f0abacc0e3b..0e52f6985724 100644 --- a/usr.sbin/sade/misc.c +++ b/usr.sbin/sade/misc.c @@ -31,7 +31,6 @@ * */ -#include "sade.h" #include <ctype.h> #include <unistd.h> #include <sys/stat.h> @@ -47,6 +46,8 @@ #include <sys/disklabel.h> #include <fs/msdosfs/msdosfsmount.h> +#include "sade.h" + /* Quick check to see if a file is readable */ Boolean file_readable(char *fname) @@ -217,3 +218,192 @@ restorescr(WINDOW *w) delwin(w); } +static int +xdialog_count_rows(const char *p) +{ + int rows = 0; + + while ((p = strchr(p, '\n')) != NULL) { + p++; + if (*p == '\0') + break; + rows++; + } + + return rows ? rows : 1; +} + +int +xdialog_menu(const char *title, const char *cprompt, int height, int width, + int menu_height, int item_no, dialogMenuItem *ditems) +{ + int i, result, choice = 0; + DIALOG_LISTITEM *listitems; + DIALOG_VARS save_vars; + + dlg_save_vars(&save_vars); + + /* initialize list items */ + listitems = dlg_calloc(DIALOG_LISTITEM, item_no + 1); + assert_ptr(listitems, "xdialog_menu"); + for (i = 0; i < item_no; i++) { + listitems[i].name = ditems[i].prompt; + listitems[i].text = ditems[i].title; + } + + /* calculate height */ + if (height < 0) + height = xdialog_count_rows(cprompt) + menu_height + 4 + 2; + if (height > LINES) + height = LINES; + + /* calculate width */ + if (width < 0) { + int tag_x = 0; + + for (i = 0; i < item_no; i++) { + int j, l; + + l = strlen(listitems[i].name); + for (j = 0; j < item_no; j++) { + int k = strlen(listitems[j].text); + tag_x = MAX(tag_x, l + k + 2); + } + } + width = MAX(dlg_count_columns(cprompt), title != NULL ? dlg_count_columns(title) : 0); + width = MAX(width, tag_x + 4) + 4; + } + width = MAX(width, 24); + if (width > COLS) + width = COLS; + + /* show menu */ + dialog_vars.default_item = listitems[choice].name; + result = dlg_menu(title, cprompt, height, width, + menu_height, item_no, listitems, &choice, NULL); + switch (result) { + case DLG_EXIT_ESC: + result = -1; + break; + case DLG_EXIT_OK: + if (ditems[choice].fire != NULL) { + int status; + WINDOW *save; + + save = savescr(); + status = ditems[choice].fire(ditems + choice); + restorescr(save); + } + result = 0; + break; + case DLG_EXIT_CANCEL: + default: + result = 1; + break; + } + + free(listitems); + dlg_restore_vars(&save_vars); + return result; +} + +int +xdialog_radiolist(const char *title, const char *cprompt, int height, int width, + int menu_height, int item_no, dialogMenuItem *ditems) +{ + int i, result, choice = 0; + DIALOG_LISTITEM *listitems; + DIALOG_VARS save_vars; + + dlg_save_vars(&save_vars); + + /* initialize list items */ + listitems = dlg_calloc(DIALOG_LISTITEM, item_no + 1); + assert_ptr(listitems, "xdialog_menu"); + for (i = 0; i < item_no; i++) { + listitems[i].name = ditems[i].prompt; + listitems[i].text = ditems[i].title; + listitems[i].state = i == choice; + } + + /* calculate height */ + if (height < 0) + height = xdialog_count_rows(cprompt) + menu_height + 4 + 2; + if (height > LINES) + height = LINES; + + /* calculate width */ + if (width < 0) { + int check_x = 0; + + for (i = 0; i < item_no; i++) { + int j, l; + + l = strlen(listitems[i].name); + for (j = 0; j < item_no; j++) { + int k = strlen(listitems[j].text); + check_x = MAX(check_x, l + k + 6); + } + } + width = MAX(dlg_count_columns(cprompt), title != NULL ? dlg_count_columns(title) : 0); + width = MAX(width, check_x + 4) + 4; + } + width = MAX(width, 24); + if (width > COLS) + width = COLS; + + /* show menu */ + dialog_vars.default_item = listitems[choice].name; + result = dlg_checklist(title, cprompt, height, width, + menu_height, item_no, listitems, NULL, FLAG_RADIO, &choice); + switch (result) { + case DLG_EXIT_ESC: + result = -1; + break; + case DLG_EXIT_OK: + if (ditems[choice].fire != NULL) { + int status; + WINDOW *save; + + save = savescr(); + status = ditems[choice].fire(ditems + choice); + restorescr(save); + } + result = 0; + break; + case DLG_EXIT_CANCEL: + default: + result = 1; + break; + } + + /* save result */ + if (result == 0) + dlg_add_result(listitems[choice].name); + free(listitems); + dlg_restore_vars(&save_vars); + return result; +} + +int +xdialog_msgbox(const char *title, const char *cprompt, + int height, int width, int pauseopt) +{ + /* calculate height */ + if (height < 0) + height = 2 + xdialog_count_rows(cprompt) + 2 + !!pauseopt; + if (height > LINES) + height = LINES; + + /* calculate width */ + if (width < 0) { + width = title != NULL ? dlg_count_columns(title) : 0; + width = MAX(width, dlg_count_columns(cprompt)) + 4; + } + if (pauseopt) + width = MAX(width, 10); + if (width > COLS) + width = COLS; + + return dialog_msgbox(title, cprompt, height, width, pauseopt); +} diff --git a/usr.sbin/sade/msg.c b/usr.sbin/sade/msg.c index 4003b20abc43..fb3368e795b4 100644 --- a/usr.sbin/sade/msg.c +++ b/usr.sbin/sade/msg.c @@ -184,13 +184,16 @@ msgConfirm(const char *fmt, ...) va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; if (OnVTY) { ioctl(0, VT_ACTIVATE, 1); msgInfo(NULL); } - dialog_notify(errstr); + dialog_vars.help_line = "Press Enter or Space"; + xdialog_msgbox("Message", errstr, -1, -1, 1); + dialog_vars.help_line = NULL; + restorescr(w); } @@ -205,11 +208,11 @@ msgNotify(const char *fmt, ...) va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; if (isDebug()) msgDebug("Notify: %s\n", errstr); - dialog_msgbox(NULL, errstr, -1, -1, 0); + xdialog_msgbox(NULL, errstr, -1, -1, 0); } /* Put up a message in a popup yes/no box and return 0 for YES, 1 for NO */ @@ -225,8 +228,8 @@ msgYesNo(const char *fmt, ...) va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; if (OnVTY) { ioctl(0, VT_ACTIVATE, 1); /* Switch back */ msgInfo(NULL); @@ -246,20 +249,24 @@ msgNoYes(const char *fmt, ...) char *errstr; int ret; WINDOW *w = savescr(); - + DIALOG_VARS save_vars; + errstr = (char *)alloca(FILENAME_MAX); va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; if (OnVTY) { ioctl(0, VT_ACTIVATE, 1); /* Switch back */ msgInfo(NULL); } if (variable_get(VAR_NONINTERACTIVE)) return 1; /* If non-interactive, return NO all the time */ - ret = dialog_noyes("User Confirmation Requested", errstr, -1, -1); + dlg_save_vars(&save_vars); + dialog_vars.defaultno = TRUE; + ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1); + dlg_restore_vars(&save_vars); restorescr(w); return ret; } @@ -278,8 +285,8 @@ msgGetInput(char *buf, const char *fmt, ...) va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; if (buf) SAFE_STRCPY(input_buffer, buf); else @@ -288,10 +295,10 @@ msgGetInput(char *buf, const char *fmt, ...) ioctl(0, VT_ACTIVATE, 1); /* Switch back */ msgInfo(NULL); } - rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer); + rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer, 0); restorescr(w); if (!rval) - return input_buffer; + return dialog_vars.input_result; else return NULL; } @@ -325,12 +332,12 @@ msgWeHaveOutput(const char *fmt, ...) va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; msgDebug("Notify: %s\n", errstr); - dialog_clear_norefresh(); + dlg_clear(); sleep(2); - dialog_msgbox(NULL, errstr, -1, -1, 0); + xdialog_msgbox(NULL, errstr, -1, -1, 0); restorescr(w); } diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h index 3c587905fa63..3e163ad5a141 100644 --- a/usr.sbin/sade/sade.h +++ b/usr.sbin/sade/sade.h @@ -130,10 +130,25 @@ typedef int Boolean; typedef struct disk Disk; typedef struct chunk Chunk; +/* special return codes for `fire' actions */ +#define DITEM_STATUS(flag) ((flag) & 0x0000FFFF) +#define DITEM_SUCCESS 0 +#define DITEM_FAILURE 1 + +/* flags - returned in upper 16 bits of return status */ +#define DITEM_LEAVE_MENU (1 << 16) +#define DITEM_RESTORE (1 << 19) + +/* for use in describing more exotic behaviors */ +typedef struct _dmenu_item { + char *prompt; + char *title; + int (*fire)(struct _dmenu_item *self); +} dialogMenuItem; + /* Bitfields for menu options */ #define DMENU_NORMAL_TYPE 0x1 /* Normal dialog menu */ #define DMENU_RADIO_TYPE 0x2 /* Radio dialog menu */ -#define DMENU_CHECKLIST_TYPE 0x4 /* Multiple choice menu */ #define DMENU_SELECTION_RETURNS 0x8 /* Immediate return on item selection */ typedef struct _dmenu { @@ -332,22 +347,8 @@ extern int dispatch_load_file_int(int); extern int dispatch_load_file(dialogMenuItem *self); /* dmenu.c */ -extern int dmenuDisplayFile(dialogMenuItem *tmp); -extern int dmenuSubmenu(dialogMenuItem *tmp); -extern int dmenuSystemCommand(dialogMenuItem *tmp); -extern int dmenuSystemCommandBox(dialogMenuItem *tmp); -extern int dmenuExit(dialogMenuItem *tmp); -extern int dmenuISetVariable(dialogMenuItem *tmp); -extern int dmenuSetVariable(dialogMenuItem *tmp); -extern int dmenuSetVariables(dialogMenuItem *tmp); -extern int dmenuToggleVariable(dialogMenuItem *tmp); -extern int dmenuSetFlag(dialogMenuItem *tmp); extern int dmenuSetValue(dialogMenuItem *tmp); -extern Boolean dmenuOpen(DMenu *menu, int *choice, int *bscroll, int *curr, int *max, Boolean buttons); -extern Boolean dmenuOpenSimple(DMenu *menu, Boolean buttons); -extern int dmenuVarCheck(dialogMenuItem *item); -extern int dmenuVarsCheck(dialogMenuItem *item); -extern int dmenuFlagCheck(dialogMenuItem *item); +extern Boolean dmenuOpen(DMenu *menu); extern int dmenuRadioCheck(dialogMenuItem *item); /* dos.c */ @@ -389,6 +390,15 @@ extern WINDOW *savescr(void); extern void restorescr(WINDOW *w); extern char *sstrncpy(char *dst, const char *src, int size); +extern int xdialog_menu(const char *title, const char *cprompt, + int height, int width, int menu_height, + int item_no, dialogMenuItem *ditems); +extern int xdialog_radiolist(const char *title, const char *cprompt, + int height, int width, int menu_height, + int item_no, dialogMenuItem *ditems); +extern int xdialog_msgbox(const char *title, const char *cprompt, + int height, int width, int pauseopt); + /* msg.c */ extern Boolean isDebug(void); extern void msgInfo(const char *fmt, ...) __printf0like(1, 2); diff --git a/usr.sbin/sade/system.c b/usr.sbin/sade/system.c index 149bbeb63adc..1e0e52f98636 100644 --- a/usr.sbin/sade/system.c +++ b/usr.sbin/sade/system.c @@ -11,7 +11,6 @@ * Heck, get him completely drunk and send me pictures! :-) */ -#include "sade.h" #include <signal.h> #include <termios.h> #include <sys/param.h> @@ -24,6 +23,7 @@ #include <sys/sysctl.h> #include <ufs/ufs/ufsmount.h> +#include "sade.h" /* Where we stick our temporary expanded doc file */ #define DOC_TMP_DIR "/tmp/.doc" @@ -56,8 +56,8 @@ intr_restart(dialogMenuItem *self) } static dialogMenuItem intrmenu[] = { - { "Restart", "Restart the program", NULL, intr_restart, NULL, NULL, 0, 0, 0, 0 }, - { "Continue", "Continue without restarting", NULL, intr_continue, NULL, NULL, 0, 0, 0, 0 }, + { "Restart", "Restart the program", intr_restart }, + { "Continue", "Continue without restarting", intr_continue }, }; @@ -66,15 +66,15 @@ handle_intr(int sig) { WINDOW *save = savescr(); - use_helpline(NULL); - use_helpfile(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; if (OnVTY) { ioctl(0, VT_ACTIVATE, 1); /* Switch back */ msgInfo(NULL); } - (void)dialog_menu("Installation interrupt", + (void)xdialog_menu("Installation interrupt", "Do you want to abort the installation?", - -1, -1, 2, -2, intrmenu, NULL, NULL, NULL); + -1, -1, 2, 2, intrmenu); restorescr(save); } @@ -120,7 +120,7 @@ systemInitialize(int argc, char **argv) } /* XXX - libdialog has particularly bad return value checking */ - init_dialog(); + init_dialog(stdin, stdout); /* If we haven't crashed I guess dialog is running ! */ DialogActive = TRUE; @@ -146,8 +146,7 @@ systemExecute(char *command) struct termios foo; WINDOW *w = savescr(); - dialog_clear(); - dialog_update(); + dlg_clear(); end_dialog(); DialogActive = FALSE; if (tcgetattr(0, &foo) != -1) { @@ -173,8 +172,7 @@ systemSuspendDialog(void) { oldW = savescr(); - dialog_clear(); - dialog_update(); + dlg_clear(); end_dialog(); DialogActive = FALSE; } @@ -195,19 +193,18 @@ systemDisplayHelp(char *file) char buf[FILENAME_MAX]; int ret = 0; WINDOW *w = savescr(); - - printf("zzz"); + fname = systemHelpFile(file, buf); if (!fname) { snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file); - use_helpfile(NULL); - use_helpline(NULL); - dialog_mesgbox("Sorry!", buf, -1, -1); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; + xdialog_msgbox("Sorry!", buf, -1, -1, 1); ret = 1; } else { - use_helpfile(NULL); - use_helpline(NULL); + dialog_vars.help_line = NULL; + dialog_vars.help_file = NULL; dialog_textbox(file, fname, LINES, COLS); } restorescr(w);