static int display_menu(void) { int ret=0; int maxx,maxy; int curr; do_init_dialog(); getmaxyx(stdscr, maxy, maxx); dialog_vars.help_button=1; dialog_vars.item_help=1; loop: switch(ret=dlg_checklist("Welcome to pkg_cleanup.", "These are the leaf packages installed on your system\nChose the packages to deinstall. Help will display the package description.", maxy-1, maxx, maxy-9, menulen, menu, " X", FLAG_CHECK, &curr)) { case DLG_EXIT_HELP: { char *p = read_desc(menu[curr].ITEM_PROMPT); if(p) { dialog_vars.help_button=0; dialog_msgbox(menu[curr].ITEM_DATA, p, maxy-4, maxx-4, TRUE); dialog_vars.help_button=1; free(p); } goto loop; } case 0: ret=0; break; default: ret=-1; break; } dialog_vars.help_button=0; dialog_vars.item_help=0; end_dialog(); return(ret); }
/* * Display a dialog box with a list of options that can be turned on or off * The `flag' parameter is used to select between radiolist and checklist. */ int dialog_checklist(const char *title, const char *cprompt, int height, int width, int list_height, int item_no, char **items, int flag) { int result; int i, j; DIALOG_LISTITEM *listitems; bool separate_output = ((flag == FLAG_CHECK) && (dialog_vars.separate_output)); bool show_status = FALSE; int current = 0; char *help_result; listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1); assert_ptr(listitems, "dialog_checklist"); for (i = j = 0; i < item_no; ++i) { listitems[i].name = items[j++]; listitems[i].text = (dialog_vars.no_items ? dlg_strempty() : items[j++]); listitems[i].state = !dlg_strcmp(items[j++], "on"); listitems[i].help = ((dialog_vars.item_help) ? items[j++] : dlg_strempty()); } dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); result = dlg_checklist(title, cprompt, height, width, list_height, item_no, listitems, NULL, flag, ¤t); switch (result) { case DLG_EXIT_OK: /* FALLTHRU */ case DLG_EXIT_EXTRA: show_status = TRUE; break; case DLG_EXIT_HELP: dlg_add_help_listitem(&result, &help_result, &listitems[current]); if ((show_status = dialog_vars.help_status)) { if (separate_output) { dlg_add_string(help_result); dlg_add_separator(); } else { dlg_add_quoted(help_result); } } else { dlg_add_string(help_result); } break; } if (show_status) { for (i = 0; i < item_no; i++) { if (listitems[i].state) { if (separate_output) { dlg_add_string(listitems[i].name); dlg_add_separator(); } else { if (dlg_need_separator()) dlg_add_separator(); if (flag == FLAG_CHECK) dlg_add_quoted(listitems[i].name); else dlg_add_string(listitems[i].name); } } } dlg_add_last_key(separate_output); } dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); free(listitems); return result; }
/* * Display a dialog box with a list of options that can be turned on or off * The `flag' parameter is used to select between radiolist and checklist. */ int dialog_checklist(const char *title, const char *cprompt, int height, int width, int list_height, int item_no, char **items, int flag) { int result; int i; DIALOG_LISTITEM *listitems; bool separate_output = ((flag == FLAG_CHECK) && (dialog_vars.separate_output)); bool show_status = FALSE; int current = 0; listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1); assert_ptr(listitems, "dialog_checklist"); for (i = 0; i < item_no; ++i) { listitems[i].name = ItemName(i); listitems[i].text = ItemText(i); listitems[i].help = ((dialog_vars.item_help) ? ItemHelp(i) : dlg_strempty()); listitems[i].state = !dlg_strcmp(ItemStatus(i), "on"); } dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); result = dlg_checklist(title, cprompt, height, width, list_height, item_no, listitems, NULL, flag, ¤t); switch (result) { case DLG_EXIT_OK: /* FALLTHRU */ case DLG_EXIT_EXTRA: show_status = TRUE; break; case DLG_EXIT_HELP: dlg_add_result("HELP "); show_status = dialog_vars.help_status; if (USE_ITEM_HELP(listitems[current].help)) { if (show_status) { if (separate_output) { dlg_add_string(listitems[current].help); dlg_add_separator(); } else { dlg_add_quoted(listitems[current].help); } } else { dlg_add_string(listitems[current].help); } result = DLG_EXIT_ITEM_HELP; } else { if (show_status) { if (separate_output) { dlg_add_string(listitems[current].name); dlg_add_separator(); } else { dlg_add_quoted(listitems[current].name); } } else { dlg_add_string(listitems[current].name); } } break; } if (show_status) { for (i = 0; i < item_no; i++) { if (listitems[i].state) { if (separate_output) { dlg_add_string(listitems[i].name); dlg_add_separator(); } else { if (dlg_need_separator()) dlg_add_separator(); dlg_add_string(listitems[i].name); } } } } dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); free(listitems); return result; }
static void newfs_command(const char *fstype, char *command, int use_default) { if (strcmp(fstype, "freebsd-ufs") == 0) { int i; DIALOG_LISTITEM items[] = { {"UFS1", "UFS Version 1", "Use version 1 of the UFS file system instead " "of version 2 (not recommended)", 0 }, {"SU", "Softupdates", "Enable softupdates (default)", 1 }, {"SUJ", "Softupdates journaling", "Enable file system journaling (default - " "turn off for SSDs)", 1 }, {"TRIM", "Enable SSD TRIM support", "Enable TRIM support, useful on solid-state drives", 0 }, }; if (!use_default) { int choice; choice = dlg_checklist("UFS Options", "", 0, 0, 0, sizeof(items)/sizeof(items[0]), items, NULL, FLAG_CHECK, &i); if (choice == 1) /* Cancel */ return; } strcpy(command, "newfs "); for (i = 0; i < (int)(sizeof(items)/sizeof(items[0])); i++) { if (items[i].state == 0) continue; if (strcmp(items[i].name, "UFS1") == 0) strcat(command, "-O1 "); else if (strcmp(items[i].name, "SU") == 0) strcat(command, "-U "); else if (strcmp(items[i].name, "SUJ") == 0) strcat(command, "-j "); else if (strcmp(items[i].name, "TRIM") == 0) strcat(command, "-t "); } } else if (strcmp(fstype, "fat32") == 0 || strcmp(fstype, "efi") == 0) { int i; DIALOG_LISTITEM items[] = { {"FAT32", "FAT Type 32", "Create a FAT32 filesystem (default)", 1 }, {"FAT16", "FAT Type 16", "Create a FAT16 filesystem", 0 }, {"FAT12", "FAT Type 12", "Create a FAT12 filesystem", 0 }, }; if (!use_default) { int choice; choice = dlg_checklist("FAT Options", "", 0, 0, 0, sizeof(items)/sizeof(items[0]), items, NULL, FLAG_RADIO, &i); if (choice == 1) /* Cancel */ return; } strcpy(command, "newfs_msdos "); for (i = 0; i < (int)(sizeof(items)/sizeof(items[0])); i++) { if (items[i].state == 0) continue; if (strcmp(items[i].name, "FAT32") == 0) strcat(command, "-F 32 "); else if (strcmp(items[i].name, "FAT16") == 0) strcat(command, "-F 16 "); else if (strcmp(items[i].name, "SUJ") == 0) strcat(command, "-F 12 "); } } else { if (!use_default) dialog_msgbox("Error", "No configurable options exist " "for this filesystem.", 0, 0, TRUE); command[0] = '\0'; } }