Path: blob/main/usr.sbin/bsdinstall/partedit/diskmenu.c
101914 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2022 Alfonso Sabato Siciliano4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <bsddialog.h>28#include <libutil.h>29#include <stdio.h>30#include <stdlib.h>31#include <string.h>3233#include "diskmenu.h"3435int36diskmenu_show(const char *title, const char *text, struct partedit_item *items,37int nitems, int *focusitem)38{39int i, output;40char size[16], *mp;41struct bsddialog_menuitem *bsditems;42struct bsddialog_conf conf;4344bsditems = malloc(nitems * sizeof(struct bsddialog_menuitem));45if (bsditems == NULL)46return BSDDIALOG_ERROR;47for (i = 0; i < nitems; i++) {48bsditems[i].prefix = "";49bsditems[i].on = false;50bsditems[i].depth = 2 * items[i].indentation;51/* old menu sets max namelen to 10 */52bsditems[i].name = items[i].name;53humanize_number(size, 7, items[i].size, "B",54HN_AUTOSCALE, HN_DECIMAL);55mp = items[i].mountpoint != NULL ? items[i].mountpoint : "";56asprintf(__DECONST(char**, &bsditems[i].desc),57" %-9s %-15s %s", size, items[i].type, mp);58bsditems[i].bottomdesc = "";59}6061bsddialog_initconf(&conf);62conf.title = title;63conf.menu.align_left = true;64conf.text.escape = true;65conf.key.f1_message="[\\Z1\\ZbC\\Znreate]: a new partition.\n"66"[\\Z1\\ZbD\\Znelete]: selected partition(s).\n"67"[\\Z1\\ZbM\\Znodify]: partition type or mountpoint.\n"68"[\\Z1\\ZbR\\Znevert]: changes to disk setup.\n"69"[\\Z1\\ZbA\\Znuto]: guided partitioning tool.\n"70"[\\Z1\\ZbF\\Zninish]: will ask to apply changes.";71conf.menu.shortcut_buttons = true;72conf.button.ok_label = "Create";73conf.button.with_extra = true;74conf.button.extra_label = "Delete";75conf.button.cancel_label = "Modify";76conf.button.with_help = true;77conf.button.help_label = "Revert";78conf.button.right1_label = "Auto";79conf.button.right2_label = "Finish";80conf.button.default_label = "Finish";81output = bsddialog_menu(&conf, text, 20, 0, 10, nitems, bsditems,82focusitem);8384for (i = 0; i < nitems; i++)85free((char *)bsditems[i].desc);86free(bsditems);8788return (output);89}909192