git: 61ba55bcf70f - main - bsddialog: import version 1.0
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 04 Oct 2023 16:12:14 UTC
The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=61ba55bcf70f2340f9c943c9571113b3fd8eda69 commit 61ba55bcf70f2340f9c943c9571113b3fd8eda69 Merge: 4b38c532efb9 e56a937c3e11 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2023-10-04 16:11:36 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2023-10-04 16:12:03 +0000 bsddialog: import version 1.0 contrib/bsddialog/.gitignore | 2 + contrib/bsddialog/CHANGELOG | 194 ++- contrib/bsddialog/GNUMakefile | 28 - contrib/bsddialog/LICENSE | 2 +- contrib/bsddialog/Makefile | 62 +- contrib/bsddialog/README.md | 35 +- contrib/bsddialog/bsddialog.c | 1687 -------------------- contrib/bsddialog/examples_library/calendar.c | 22 +- contrib/bsddialog/examples_library/checklist.c | 11 +- contrib/bsddialog/examples_library/compile | 2 +- contrib/bsddialog/examples_library/datebox.c | 21 +- contrib/bsddialog/examples_library/form.c | 11 +- contrib/bsddialog/examples_library/gauge.c | 57 + contrib/bsddialog/examples_library/infobox.c | 6 +- contrib/bsddialog/examples_library/menu.c | 11 +- contrib/bsddialog/examples_library/mixedgauge.c | 79 + contrib/bsddialog/examples_library/mixedlist.c | 21 +- contrib/bsddialog/examples_library/msgbox.c | 9 +- contrib/bsddialog/examples_library/pause.c | 21 +- contrib/bsddialog/examples_library/radiolist.c | 14 +- contrib/bsddialog/examples_library/rangebox.c | 7 +- contrib/bsddialog/examples_library/theme.c | 46 +- contrib/bsddialog/examples_library/timebox.c | 18 +- contrib/bsddialog/examples_library/yesno.c | 11 +- contrib/bsddialog/examples_utility/checklist.sh | 16 +- contrib/bsddialog/examples_utility/datebox.sh | 34 + contrib/bsddialog/examples_utility/form.sh | 4 +- contrib/bsddialog/examples_utility/infobox.sh | 2 +- contrib/bsddialog/examples_utility/inputbox.sh | 5 +- contrib/bsddialog/examples_utility/menu.sh | 13 +- contrib/bsddialog/examples_utility/mixedform.sh | 4 +- contrib/bsddialog/examples_utility/mixedgauge.sh | 10 +- contrib/bsddialog/examples_utility/passwordbox.sh | 4 +- contrib/bsddialog/examples_utility/passwordform.sh | 4 +- contrib/bsddialog/examples_utility/radiolist.sh | 18 +- contrib/bsddialog/examples_utility/rangebox.sh | 33 + contrib/bsddialog/lib/{GNUMakefile => GNUmakefile} | 15 +- contrib/bsddialog/lib/Makefile | 49 +- contrib/bsddialog/lib/barbox.c | 705 ++++---- contrib/bsddialog/lib/bsddialog.3 | 626 +++++--- contrib/bsddialog/lib/bsddialog.h | 44 +- contrib/bsddialog/lib/bsddialog_progressview.h | 8 +- contrib/bsddialog/lib/bsddialog_theme.h | 28 +- contrib/bsddialog/lib/calendarbox.c | 520 ------ contrib/bsddialog/lib/datebox.c | 715 +++++++++ contrib/bsddialog/lib/formbox.c | 940 ++++++----- contrib/bsddialog/lib/infobox.c | 96 -- contrib/bsddialog/lib/lib_util.c | 1157 ++++++++------ contrib/bsddialog/lib/lib_util.h | 169 +- contrib/bsddialog/lib/libbsddialog.c | 38 +- contrib/bsddialog/lib/menubox.c | 837 +++++----- contrib/bsddialog/lib/messagebox.c | 250 ++- contrib/bsddialog/lib/textbox.c | 268 ++-- contrib/bsddialog/lib/theme.c | 254 ++- contrib/bsddialog/lib/timebox.c | 479 +----- contrib/bsddialog/util_theme.c | 353 ---- contrib/bsddialog/util_theme.h | 36 - contrib/bsddialog/utility/GNUmakefile | 33 + contrib/bsddialog/utility/Makefile | 33 + contrib/bsddialog/{ => utility}/bsddialog.1 | 345 ++-- contrib/bsddialog/utility/bsddialog.c | 338 ++++ contrib/bsddialog/utility/util.h | 125 ++ contrib/bsddialog/utility/util_builders.c | 768 +++++++++ contrib/bsddialog/utility/util_cli.c | 841 ++++++++++ contrib/bsddialog/utility/util_theme.c | 451 ++++++ lib/libbsddialog/Makefile | 3 +- usr.bin/bsddialog/Makefile | 9 +- usr.sbin/bsdinstall/partedit/diskmenu.c | 6 +- usr.sbin/bsdinstall/partedit/diskmenu.h | 4 +- usr.sbin/bsdinstall/partedit/gpart_ops.c | 7 +- usr.sbin/bsdinstall/partedit/part_wizard.c | 4 +- usr.sbin/bsdinstall/partedit/partedit.c | 2 +- 72 files changed, 6891 insertions(+), 6189 deletions(-) diff --cc contrib/bsddialog/.gitignore index 8b8ec9d4ae0b,000000000000..c8fc68ed8a0e mode 100644,000000..100644 --- a/contrib/bsddialog/.gitignore +++ b/contrib/bsddialog/.gitignore @@@ -1,24 -1,0 +1,26 @@@ +bsddialog +.depend* +*.o +*.so* +*.a +*.gz +*.core +*~ +BSDDIALOG.geany +BSDDIALOG.tags +examples_library/calendar +examples_library/checklist +examples_library/datebox +examples_library/form ++examples_library/gauge +examples_library/infobox +examples_library/menu ++examples_library/mixedgauge +examples_library/mixedlist +examples_library/msgbox +examples_library/pause +examples_library/radiolist +examples_library/rangebox +examples_library/theme +examples_library/timebox +examples_library/yesno diff --cc contrib/bsddialog/Makefile index 28162c5e90b3,000000000000..884cfa1b3e60 mode 100644,000000..100644 --- a/contrib/bsddialog/Makefile +++ b/contrib/bsddialog/Makefile @@@ -1,50 -1,0 +1,38 @@@ +# PUBLIC DOMAIN - NO WARRANTY, see: +# <http://creativecommons.org/publicdomain/zero/1.0/> +# - # Written in 2021 by Alfonso Sabato Siciliano ++# Written in 2023 by Alfonso Sabato Siciliano + - OUTPUT= bsddialog - SOURCES= bsddialog.c util_theme.c - OBJECTS= ${SOURCES:.c=.o} - LIBPATH= ${.CURDIR}/lib - LIBBSDDIALOG= ${LIBPATH}/libbsddialog.so ++OUTPUT = bsddialog ++export VERSION=1.0 ++.CURDIR ?= ${CURDIR} ++LIBPATH = ${.CURDIR}/lib ++LIBBSDDIALOG = ${LIBPATH}/libbsddialog.so ++UTILITYPATH = ${.CURDIR}/utility + - CFLAGS+= -I${LIBPATH} -std=gnu99 -Wall -Wextra -Werror - # `make -DDEBUG` - .if defined(DEBUG) - CFLAGS= -g -Wall -I${LIBPATH} - LIBDEBUG= -DDEBUG - .endif - LDFLAGS+= -ltinfow -Wl,-rpath=${LIBPATH} -L${LIBPATH} -lbsddialog - - BINDIR= /usr/local/bin - MAN= ${OUTPUT}.1 - GZIP= gzip -cn - MANDIR= /usr/local/share/man/man1 - - INSTALL= install +RM= rm -f ++LN = ln -s -f ++ ++### cli options ### ++# port/pkg Makefile: 'MAKE_ARGS = -DNORPATH' ++NORPATH ?= ++export DISABLERPATH=${NORPATH} ++# `make -DDEBUG` ++# `gmake DEBUG=1` ++DEBUG ?= ++export ENABLEDEBUG=${DEBUG} + +all : ${OUTPUT} + - ${OUTPUT}: ${LIBBSDDIALOG} ${OBJECTS} - ${CC} ${LDFLAGS} ${OBJECTS} -o ${.PREFIX} ++${OUTPUT}: ${LIBBSDDIALOG} ++ ${MAKE} -C ${UTILITYPATH} LIBPATH=${LIBPATH} ++ ${LN} ${UTILITYPATH}/${OUTPUT} ${.CURDIR}/${OUTPUT} + +${LIBBSDDIALOG}: - make -C ${LIBPATH} ${LIBDEBUG} - - .c.o: - ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} - - install: - ${INSTALL} -s -m 555 ${OUTPUT} ${BINDIR} - ${GZIP} ${MAN} > ${MAN}.gz - ${INSTALL} -m 444 ${MAN}.gz ${MANDIR} - - unistall: - ${RM} ${BINDIR}/${OUTPUT} - ${RM} ${MANDIR}/${MAN}.gz ++ ${MAKE} -C ${LIBPATH} + +clean: - make -C ${LIBPATH} clean - ${RM} ${OUTPUT} *.o *~ *.core ${MAN}.gz ++ ${MAKE} -C ${LIBPATH} clean ++ ${MAKE} -C ${UTILITYPATH} clean ++ ${RM} ${OUTPUT} *.core ++ diff --cc contrib/bsddialog/README.md index 59af7072e7f5,000000000000..f4846ec07745 mode 100644,000000..100644 --- a/contrib/bsddialog/README.md +++ b/contrib/bsddialog/README.md @@@ -1,120 -1,0 +1,131 @@@ - # BSDDialog 0.4 ++# BSDDialog 1.0 + +This project provides **bsddialog** and **libbsddialog**, an utility +and a library to build scripts and tools with TUI dialogs and widgets. ++ ++ ++## Demo ++ +[Screenshots](https://www.flickr.com/photos/alfonsosiciliano/albums/72157720215006074). + + +## Getting Started + - FreeBSD: ++FreeBSD and Linux: + +``` +% git clone https://gitlab.com/alfix/bsddialog.git +% cd bsddialog +% make +% ./bsddialog --msgbox "Hello World!" 8 20 +``` + - Linux: - - ``` - % git clone https://gitlab.com/alfix/bsddialog.git - % cd bsddialog - % make -f GNUMakefile - % ./bsddialog --msgbox "Hello World!" 8 20 - ``` - +Output: + +![screenshot](screenshot.png) + + +## Utility + +**Dialogs:** + +--calendar, --checklist, --datebox, --form, --gauge, --infobox, --inputbox, +--menu, --mixedform, --mixedgauge, --msgbox, --passwordbox, --passwordform, +--pause, --radiolist, --rangebox, --textbox, --timebox, --treeview, --yesno. + +**Manual** + + - [bsddialog(1)](https://alfonsosiciliano.gitlab.io/posts/2022-01-26-manual-bsddialog.html) + + +**Examples**: + +``` +% ./bsddialog --backtitle "TITLE" --title msgbox --msgbox "Hello World!" 5 30 +% ./bsddialog --theme blackwhite --title msgbox --msgbox "Hello World!" 5 30 +% ./bsddialog --begin-y 2 --default-no --title yesno --yesno "Hello World!" 5 30 +% ./bsddialog --ascii-lines --pause "Hello World!" 8 50 10 +% ./bsddialog --checklist "Space to select" 0 0 0 Name1 Desc1 off Name2 Desc2 on +% ./bsddialog --title yesno --hline "bsddialog" --yesno "Hello World!" 5 25 +% ./bsddialog --extra-button --help-button --yesno "Hello World!" 0 0 +``` + +and [Examples](https://gitlab.com/alfix/bsddialog/-/tree/main/examples_utility) +in the _Public Domain_ to build new projects: +``` +% sh ./examples_utility/calendar.sh +% sh ./examples_utility/checklist.sh ++% sh ./examples_utility/datebox.sh +% sh ./examples_utility/form.sh +% sh ./examples_utility/gauge.sh +% sh ./examples_utility/infobox.sh +% sh ./examples_utility/inputbox.sh +% sh ./examples_utility/menu.sh +% sh ./examples_utility/mixedform.sh +% sh ./examples_utility/mixedgauge.sh +% sh ./examples_utility/msgbox.sh +% sh ./examples_utility/passwordbox.sh +% sh ./examples_utility/passwordform.sh +% sh ./examples_utility/pause.sh +% sh ./examples_utility/radiolist.sh ++% sh ./examples_utility/rangebox.sh +% sh ./examples_utility/timebox.sh +% sh ./examples_utility/yesno.sh +``` + +## Library + +**API** + + - [bsddialog.h](https://gitlab.com/alfix/bsddialog/-/blob/main/lib/bsddialog.h) + - [bsddialog\_theme.h](https://gitlab.com/alfix/bsddialog/-/blob/main/lib/bsddialog_theme.h) + + +**Manual** + + - [bsddialog(3)](https://alfonsosiciliano.gitlab.io/posts/2022-01-15-manual-libbsddialog.html) + + +**Examples**: + +[Examples](https://gitlab.com/alfix/bsddialog/-/tree/main/examples_library) +in the _Public Domain_ to build new projects: +``` +% cd examples_library +% sh compile +% ./calendar +% ./checklist +% ./datebox +% ./form ++% ./gauge +% ./infobox +% ./menu ++% ./mixedgauge +% ./mixedlist +% ./msgbox +% ./pause +% ./radiolist +% ./rangebox +% ./theme +% ./timebox +% ./yesno +``` + + +## TODO and Ideas - ++ + - menubar feature + - key callback + - Right-To-Left text ++ - some terminal does not hide the cursor, move it bottom-right before to getch. ++ - refactor backtitle: multiline, conf.backtitle, WINDOW \*dialog.backtitle. ++ - refactor bottomdesc: WINDOW \*dialog.bottomdesc -> fix expandig screen. ++ - accessibility https://wiki.freebsd.org/Accessibility/Wishlist/Base ++ - add bool conf.menu.depthlines. ++ - implement custom getopt\_long(). ++ - refactor/redesign gauge(). ++ - improve grey lines expanding terminal (maybe redrawwin() in hide\_dialog()). ++ - more restrictive strtol() and strtoul(). ++ - implement global buttons handler. ++ - add/move external tutorial. ++ - implement menutype.min_on. diff --cc contrib/bsddialog/examples_library/gauge.c index 000000000000,3b38a80f3f2c..3b38a80f3f2c mode 000000,100644..100644 --- a/contrib/bsddialog/examples_library/gauge.c +++ b/contrib/bsddialog/examples_library/gauge.c diff --cc contrib/bsddialog/examples_library/mixedgauge.c index 000000000000,7666867902fb..7666867902fb mode 000000,100644..100644 --- a/contrib/bsddialog/examples_library/mixedgauge.c +++ b/contrib/bsddialog/examples_library/mixedgauge.c diff --cc contrib/bsddialog/examples_utility/datebox.sh index 000000000000,bea4559dfbec..bea4559dfbec mode 000000,100755..100755 --- a/contrib/bsddialog/examples_utility/datebox.sh +++ b/contrib/bsddialog/examples_utility/datebox.sh diff --cc contrib/bsddialog/examples_utility/rangebox.sh index 000000000000,9b3213d8acad..9b3213d8acad mode 000000,100644..100644 --- a/contrib/bsddialog/examples_utility/rangebox.sh +++ b/contrib/bsddialog/examples_utility/rangebox.sh diff --cc contrib/bsddialog/lib/Makefile index 0f536fb38743,000000000000..252b33f79848 mode 100644,000000..100644 --- a/contrib/bsddialog/lib/Makefile +++ b/contrib/bsddialog/lib/Makefile @@@ -1,75 -1,0 +1,44 @@@ +# PUBLIC DOMAIN - NO WARRANTY, see: +# <http://creativecommons.org/publicdomain/zero/1.0/> +# +# Written in 2021 by Alfonso Sabato Siciliano + - VERSION = 0.4 +LIBRARY = bsddialog +LIBRARY_SO = lib${LIBRARY:=.so} +LIBRARY_A = lib${LIBRARY:=.a} +HEADERS = bsddialog.h bsddialog_theme.h bsddialog_progressview.h - SOURCES = barbox.c calendarbox.c formbox.c infobox.c libbsddialog.c \ - lib_util.c menubox.c messagebox.c textbox.c theme.c timebox.c ++SOURCES = barbox.c datebox.c formbox.c libbsddialog.c lib_util.c \ ++ menubox.c messagebox.c textbox.c theme.c timebox.c +OBJECTS = ${SOURCES:.c=.o} - CFLAGS += -D_XOPEN_SOURCE_EXTENDED -fPIC -Wall -Wextra - LDFLAGS += -fstack-protector-strong -shared -Wl,-x -Wl,--fatal-warnings \ - -Wl,--warn-shared-textrel -Wl,-soname,${LIBRARY_SO}.${VERSION} \ - -L/usr/lib -lncursesw -ltinfow + +.if defined(DEBUG) - # `make -DDEBUG` - CFLAGS = -g -D_XOPEN_SOURCE_EXTENDED -fPIC -Wall -Wextra - .else - CFLAGS += -std=gnu99 -fstack-protector-strong ++CFLAGS += -g +.endif ++CFLAGS += -D_XOPEN_SOURCE_EXTENDED -fPIC -Wall -Wextra -std=gnu99 \ ++ -fstack-protector-strong ++LDFLAGS += -fstack-protector-strong -shared -Wl,-x -Wl,--fatal-warnings \ ++ -Wl,--warn-shared-textrel -Wl,-soname,${LIBRARY_SO}.${VERSION} \ ++ -L/usr/lib -lncursesw -ltinfow + - LOCALBASE = /usr/local +LN = ln -s -f +RM = rm -f - CP = cp - GZIP = gzip -cn - LDCONFIG = /sbin/ldconfig -m - MAN = ${OUTPUT}.3 - GZIP = gzip -cn - MANDIR = ${LOCALBASE}/share/man/man3 - INSTALL = install - RM = rm -f + - all : man ${LIBRARY} ++all : ${LIBRARY} + +${LIBRARY}: ${LIBRARY_SO} ${LIBRARY_A} + +${LIBRARY_SO}.${VERSION}: ${OBJECTS} + ${CC} ${LDFLAGS} ${.ALLSRC} -o ${LIBRARY_SO}.${VERSION} + +${LIBRARY_SO}: ${LIBRARY_SO}.${VERSION} + ${LN} ${LIBRARY_SO}.${VERSION} ${LIBRARY_SO} + +${LIBRARY_A}: ${OBJECTS} + ${AR} cr ${.TARGET} ${OBJECTS} + ${RANLIB} ${.TARGET} + +.c.o: + ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + - man: - ${GZIP} ${LIBRARY}.3 > ${LIBRARY}.3.gz - +clean: + ${RM} ${LIBRARY_SO}* *.o *~ *.gz ${LIBRARY_A} - - - install: - ${INSTALL} -m 644 ${HEADERS} ${LOCALBASE}/include - ${INSTALL} -m 644 -s ${LIBRARY_SO}.${VERSION} ${LOCALBASE}/lib/ - ${INSTALL} -l rs ${LOCALBASE}/lib/${LIBRARY_SO}.${VERSION} ${LOCALBASE}/lib/${LIBRARY_SO} - ${INSTALL} -m 644 ${LIBRARY_A} ${LOCALBASE}/lib - ${LDCONFIG} ${LOCALBASE}/lib - ${INSTALL} -m 644 ${LIBRARY}.3.gz ${MANDIR} - - unistall: - ${RM} ${LOCALBASE}/include/${LIBRARY}*.h - ${RM} ${LOCALBASE}/lib/${LIBRARY_SO} - ${RM} ${LOCALBASE}/lib/${LIBRARY_SO}.${VERSION} - ${LDCONFIG} ${LOCALBASE}/lib - ${RM} ${MANDIR}/${LIBRARY}.3.gz diff --cc contrib/bsddialog/lib/datebox.c index 000000000000,9f26b2d08093..9f26b2d08093 mode 000000,100644..100644 --- a/contrib/bsddialog/lib/datebox.c +++ b/contrib/bsddialog/lib/datebox.c diff --cc contrib/bsddialog/utility/GNUmakefile index 000000000000,518ec0d912d6..518ec0d912d6 mode 000000,100644..100644 --- a/contrib/bsddialog/utility/GNUmakefile +++ b/contrib/bsddialog/utility/GNUmakefile diff --cc contrib/bsddialog/utility/Makefile index 000000000000,ab51b46a25be..ab51b46a25be mode 000000,100644..100644 --- a/contrib/bsddialog/utility/Makefile +++ b/contrib/bsddialog/utility/Makefile diff --cc contrib/bsddialog/utility/bsddialog.c index 000000000000,d4d1fc3e0f3a..d4d1fc3e0f3a mode 000000,100644..100644 --- a/contrib/bsddialog/utility/bsddialog.c +++ b/contrib/bsddialog/utility/bsddialog.c diff --cc contrib/bsddialog/utility/util.h index 000000000000,2750c2ee6951..2750c2ee6951 mode 000000,100644..100644 --- a/contrib/bsddialog/utility/util.h +++ b/contrib/bsddialog/utility/util.h diff --cc contrib/bsddialog/utility/util_builders.c index 000000000000,2dfa20cb0f86..2dfa20cb0f86 mode 000000,100644..100644 --- a/contrib/bsddialog/utility/util_builders.c +++ b/contrib/bsddialog/utility/util_builders.c diff --cc contrib/bsddialog/utility/util_cli.c index 000000000000,22bed6550fb5..22bed6550fb5 mode 000000,100644..100644 --- a/contrib/bsddialog/utility/util_cli.c +++ b/contrib/bsddialog/utility/util_cli.c diff --cc contrib/bsddialog/utility/util_theme.c index 000000000000,c313d743252b..c313d743252b mode 000000,100644..100644 --- a/contrib/bsddialog/utility/util_theme.c +++ b/contrib/bsddialog/utility/util_theme.c diff --cc lib/libbsddialog/Makefile index ddb7e08f71ba,000000000000..8b02205a0d23 mode 100644,000000..100644 --- a/lib/libbsddialog/Makefile +++ b/lib/libbsddialog/Makefile @@@ -1,28 -1,0 +1,27 @@@ +BSDDIALOG= ${SRCTOP}/contrib/bsddialog + +.PATH: ${BSDDIALOG}/lib + +LIB= bsddialog +PRIVATELIB= yes +SHLIB_MAJOR= 0 +SRCS= barbox.c \ - calendarbox.c \ ++ datebox.c \ + formbox.c \ - infobox.c \ + lib_util.c \ + lib_util.h \ + libbsddialog.c \ + menubox.c \ + messagebox.c \ + textbox.c \ + theme.c \ + timebox.c +INCS= bsddialog.h \ + bsddialog_theme.h \ + bsddialog_progressview.h +MAN= bsddialog.3 + +LIBADD= ncursesw tinfow formw +CFLAGS+= -D_XOPEN_SOURCE_EXTENDED + +.include <bsd.lib.mk> diff --cc usr.bin/bsddialog/Makefile index 1c2f9d697e97,000000000000..24a75aaf2f96 mode 100644,000000..100644 --- a/usr.bin/bsddialog/Makefile +++ b/usr.bin/bsddialog/Makefile @@@ -1,10 -1,0 +1,13 @@@ - BSDDIALOG= ${SRCTOP}/contrib/bsddialog ++BSDDIALOG= ${SRCTOP}/contrib/bsddialog/utility +.PATH: ${BSDDIALOG} + +PROG= bsddialog - SRCS= bsddialog.c util_theme.c ++SRCS= bsddialog.c \ ++ util_builders.c \ ++ util_cli.c \ ++ util_theme.c +MAN= bsddialog.1 - CFLAGS+= -I${BSDDIALOG}/lib ++CFLAGS+= -I${BSDDIALOG}/../lib +LIBADD= bsddialog tinfow + +.include <bsd.prog.mk> diff --cc usr.sbin/bsdinstall/partedit/diskmenu.c index 9e16ef96171a,000000000000..6a14ee831e18 mode 100644,000000..100644 --- a/usr.sbin/bsdinstall/partedit/diskmenu.c +++ b/usr.sbin/bsdinstall/partedit/diskmenu.c @@@ -1,90 -1,0 +1,90 @@@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 Alfonso Sabato Siciliano + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <bsddialog.h> +#include <libutil.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "diskmenu.h" + +int +diskmenu_show(const char *title, const char *text, struct partedit_item *items, + int nitems, int *focusitem) +{ + int i, output; + char size[16], *mp; + struct bsddialog_menuitem *bsditems; + struct bsddialog_conf conf; + + bsditems = malloc(nitems * sizeof(struct bsddialog_menuitem)); + if (bsditems == NULL) + return BSDDIALOG_ERROR; + for (i = 0; i < nitems; i++) { + bsditems[i].prefix = ""; + bsditems[i].on = false; + bsditems[i].depth = items[i].indentation; + /* old menu sets max namelen to 10 */ + bsditems[i].name = items[i].name; + humanize_number(size, 7, items[i].size, "B", + HN_AUTOSCALE, HN_DECIMAL); + mp = items[i].mountpoint != NULL ? items[i].mountpoint : ""; + asprintf(__DECONST(char**, &bsditems[i].desc), "%s %-15s %-10s", + size, items[i].type, mp); + bsditems[i].bottomdesc = ""; + } + + bsddialog_initconf(&conf); + conf.title = title; + conf.menu.align_left = true; - conf.text.highlight = true; ++ conf.text.escape = true; + conf.key.f1_message="[\\Z1\\ZbC\\Znreate]: a new partition.\n" + "[\\Z1\\ZbD\\Znelete]: selected partition(s).\n" + "[\\Z1\\ZbC\\Znhange]: partition type or mountpoint.\n" + "[\\Z1\\ZbR\\Znevert]: changes to disk setup.\n" + "[\\Z1\\ZbA\\Znuto]: guided partitioning tool.\n" + "[\\Z1\\ZbF\\Zninish]: will ask to apply changes."; + conf.menu.shortcut_buttons = true; + conf.button.ok_label = "Create"; + conf.button.with_extra = true; + conf.button.extra_label = "Delete"; + conf.button.cancel_label = "Modify"; + conf.button.with_help = true; + conf.button.help_label = "Revert"; - conf.button.generic1_label = "Auto"; - conf.button.generic2_label = "Finish"; ++ conf.button.right1_label = "Auto"; ++ conf.button.right2_label = "Finish"; + conf.button.default_label = "Finish"; + output = bsddialog_menu(&conf, text, 20, 0, 10, nitems, bsditems, + focusitem); + + for (i = 0; i < nitems; i++) + free((char *)bsditems[i].desc); + free(bsditems); + + return output; +} diff --cc usr.sbin/bsdinstall/partedit/diskmenu.h index 7c0e3c505f9e,000000000000..9fce2e813214 mode 100644,000000..100644 --- a/usr.sbin/bsdinstall/partedit/diskmenu.h +++ b/usr.sbin/bsdinstall/partedit/diskmenu.h @@@ -1,52 -1,0 +1,52 @@@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2011 Nathan Whitehorn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _PARTEDIT_DISKMENU_H +#define _PARTEDIT_DISKMENU_H + +#define BUTTON_CREATE BSDDIALOG_OK +#define BUTTON_DELETE BSDDIALOG_EXTRA +#define BUTTON_MODIFY BSDDIALOG_CANCEL +#define BUTTON_REVERT BSDDIALOG_HELP - #define BUTTON_AUTO BSDDIALOG_GENERIC1 - #define BUTTON_FINISH BSDDIALOG_GENERIC2 ++#define BUTTON_AUTO BSDDIALOG_RIGHT1 ++#define BUTTON_FINISH BSDDIALOG_RIGHT2 + +struct partedit_item { + int indentation; + const char *name; + intmax_t size; + const char *type; + char *mountpoint; + + void *cookie; +}; + +int diskmenu_show(const char *title, const char *text, + struct partedit_item *items, int nitems, int *selected); + +#endif diff --cc usr.sbin/bsdinstall/partedit/gpart_ops.c index 8b75d2d6d859,000000000000..92d1a367890c mode 100644,000000..100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@@ -1,1542 -1,0 +1,1539 @@@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2011 Nathan Whitehorn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/stat.h> + +#include <bsddialog.h> +#include <ctype.h> +#include <errno.h> +#include <fcntl.h> +#include <libutil.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <libgeom.h> + +#include "partedit.h" + +#define GPART_FLAGS "x" /* Do not commit changes by default */ + +static void +gpart_show_error(const char *title, const char *explanation, const char *errstr) +{ + char *errmsg; + char message[512]; + int error; + struct bsddialog_conf conf; + + if (explanation == NULL) + explanation = ""; + + error = strtol(errstr, &errmsg, 0); + if (errmsg != errstr) { + while (errmsg[0] == ' ') + errmsg++; + if (errmsg[0] != '\0') + sprintf(message, "%s%s. %s", explanation, + strerror(error), errmsg); + else + sprintf(message, "%s%s", explanation, strerror(error)); + } else { + sprintf(message, "%s%s", explanation, errmsg); + } + + bsddialog_initconf(&conf); + conf.title = title; + bsddialog_msgbox(&conf, message, 0, 0); +} + +static int +scheme_supports_labels(const char *scheme) +{ + if (strcmp(scheme, "APM") == 0) + return (1); + if (strcmp(scheme, "GPT") == 0) + return (1); + + return (0); +} + +static void +newfs_command(const char *fstype, char *command, int use_default) +{ + struct bsddialog_conf conf; + + bsddialog_initconf(&conf); + + if (strcmp(fstype, "freebsd-ufs") == 0) { + int i; + struct bsddialog_menuitem items[] = { + {"", false, 0, "UFS1", "UFS Version 1", + "Use version 1 of the UFS file system instead " + "of version 2 (not recommended)"}, + {"", true, 0, "SU", "Softupdates", + "Enable softupdates (default)"}, + {"", true, 0, "SUJ", "Softupdates journaling", + "Enable file system journaling (default - " + "turn off for SSDs)"}, + {"", false, 0, "TRIM", "Enable SSD TRIM support", + "Enable TRIM support, useful on solid-state " + "drives" }, + }; + + if (!use_default) { + int choice; + conf.title = "UFS Options"; + choice = bsddialog_checklist(&conf, "", 0, 0, 0, + nitems(items), items, NULL); + if (choice == BSDDIALOG_CANCEL) + return; + } + + strcpy(command, "newfs "); + for (i = 0; i < (int)nitems(items); i++) { + if (items[i].on == false) + 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, "freebsd-zfs") == 0) { + int i; + struct bsddialog_menuitem items[] = { + {"", 0, true, "fletcher4", "checksum algorithm: fletcher4", + "Use fletcher4 for data integrity checking. " + "(default)"}, + {"", 0, false, "fletcher2", "checksum algorithm: fletcher2", + "Use fletcher2 for data integrity checking. " + "(not recommended)"}, + {"", 0, false, "sha256", "checksum algorithm: sha256", + "Use sha256 for data integrity checking. " + "(not recommended)"}, + {"", 0, false, "atime", "Update atimes for files", + "Disable atime update"}, + }; + + if (!use_default) { + int choice; + conf.title = "ZFS Options"; + choice = bsddialog_checklist(&conf, "", 0, 0, 0, + nitems(items), items, NULL); + if (choice == BSDDIALOG_CANCEL) + return; + } + + strcpy(command, "zpool create -f -m none "); + if (getenv("BSDINSTALL_TMPBOOT") != NULL) { + char zfsboot_path[MAXPATHLEN]; + snprintf(zfsboot_path, sizeof(zfsboot_path), "%s/zfs", + getenv("BSDINSTALL_TMPBOOT")); + mkdir(zfsboot_path, S_IRWXU | S_IRGRP | S_IXGRP | + S_IROTH | S_IXOTH); + sprintf(command, "%s -o cachefile=%s/zpool.cache ", + command, zfsboot_path); + } + for (i = 0; i < (int)nitems(items); i++) { + if (items[i].on == false) + continue; + if (strcmp(items[i].name, "fletcher4") == 0) + strcat(command, "-O checksum=fletcher4 "); + else if (strcmp(items[i].name, "fletcher2") == 0) + strcat(command, "-O checksum=fletcher2 "); + else if (strcmp(items[i].name, "sha256") == 0) + strcat(command, "-O checksum=sha256 "); + else if (strcmp(items[i].name, "atime") == 0) + strcat(command, "-O atime=off "); + } + } else if (strcmp(fstype, "fat32") == 0 || strcmp(fstype, "efi") == 0 || + strcmp(fstype, "ms-basic-data") == 0) { + int i; + struct bsddialog_menuitem items[] = { + {"", 0, true, "FAT32", "FAT Type 32", + "Create a FAT32 filesystem (default)"}, + {"", 0, false, "FAT16", "FAT Type 16", + "Create a FAT16 filesystem"}, + {"", 0, false, "FAT12", "FAT Type 12", + "Create a FAT12 filesystem"}, + }; + + if (!use_default) { + int choice; + conf.title = "FAT Options"; + choice = bsddialog_radiolist(&conf, "", 0, 0, 0, + nitems(items), items, NULL); + if (choice == BSDDIALOG_CANCEL) + return; + } + + strcpy(command, "newfs_msdos "); + for (i = 0; i < (int)nitems(items); i++) { + if (items[i].on == false) + continue; + if (strcmp(items[i].name, "FAT32") == 0) + strcat(command, "-F 32 -c 1"); + else if (strcmp(items[i].name, "FAT16") == 0) + strcat(command, "-F 16 "); + else if (strcmp(items[i].name, "FAT12") == 0) + strcat(command, "-F 12 "); + } + } else { + if (!use_default) { + conf.title = "Error"; + bsddialog_msgbox(&conf, "No configurable options exist " + "for this filesystem.", 0, 0); + } + command[0] = '\0'; + } +} + +const char * +choose_part_type(const char *def_scheme) +{ + int button, choice, i; + const char *scheme = NULL; + struct bsddialog_conf conf; + + struct bsddialog_menuitem items[] = { + {"", false, 0, "APM", "Apple Partition Map", + "Bootable on PowerPC Apple Hardware" }, + {"", false, 0, "BSD", "BSD Labels", + "Bootable on most x86 systems" }, + {"", false, 0, "GPT", "GUID Partition Table", + "Bootable on most x86 systems and EFI aware ARM64" }, + {"", false, 0, "MBR", "DOS Partitions", + "Bootable on most x86 systems" }, + }; + + for (i = 0; i < (int)nitems(items); i++) + if (strcmp(items[i].name, def_scheme) == 0) + choice = i; + + bsddialog_initconf(&conf); + +parttypemenu: + conf.title = "Partition Scheme"; + button = bsddialog_menu(&conf, + "Select a partition scheme for this volume:", 0, 0, 0, + nitems(items), items, &choice); + + if (button == BSDDIALOG_CANCEL) + return NULL; + + if (!is_scheme_bootable(items[choice].name)) { + char message[512]; + sprintf(message, "This partition scheme (%s) is not " + "bootable on this platform. Are you sure you want " + "to proceed?", items[choice].name); + conf.button.default_cancel = true; + conf.title = "Warning"; + button = bsddialog_yesno(&conf, message, 0, 0); + conf.button.default_cancel = false; + if (button == BSDDIALOG_NO) + goto parttypemenu; *** 2323 LINES SKIPPED ***