From nobody Wed Nov 24 10:03:54 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B48BE18AB294; Wed, 24 Nov 2021 10:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hzc6M2CRcz3Fvx; Wed, 24 Nov 2021 10:03:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D6CFA35; Wed, 24 Nov 2021 10:03:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AOA3sS7008985; Wed, 24 Nov 2021 10:03:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AOA3ssV008984; Wed, 24 Nov 2021 10:03:54 GMT (envelope-from git) Date: Wed, 24 Nov 2021 10:03:54 GMT Message-Id: <202111241003.1AOA3ssV008984@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: f872dde34c6a - main - tzsetup: replace libdialog with libbsddialog List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f872dde34c6af8c27e16905ebfdb62cddb4c35ba Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637748235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lCeyB5DwgrXEjoFGd21mtRzryXPb9cUigSmuhBlnp0k=; b=WISVGccgjqPYoGwkd2HPGCS6rZB/6ZXCbHuxMIln/j6kiPSn9VMuD3LoymMhsOqiiujcoX 7TO9yPw1U61Zj1ljtzIYue4cSmCag0fniW0B84RLk0g5fB7/L4kqB0J294DQosp8dAANpC +drF7GblE8WsBx/4/3ucNKHXq9QX23U0Eyf4q6BUiAhhbir8T269qgFc4wnxelwIV9ofFV QA61zk38Bfl6aO6JRAkhP9iCkxBf7vE+kWBC8CcJlXc9YE+Ryz758RyWm5TH2LhofYt8Xs n81MAt6xGhHOpfr9AK09QavFNTKPZK23xFTH5PwPHsKAES2kxFl8rUo6R0LgvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637748235; a=rsa-sha256; cv=none; b=qoOZ4AtFJH0z0OpbSperlfdqk+/2KjPXAtrXJE40AeKaqh/eATGuihlnaHO+vS3O0sCKq+ cI57kpCPO9Td8QGEHc6O53hDpi/w1vMRCX0pRSTDnx8ZPFKUTAd2JK2cqXVRNWX40knU+E BMg7BVXlT2MUIpfmGc4DRZHIWp+3McVVFfMnOgElUEcK8qYnSRnwa13ygyOvBjnoqNz6L4 XdupwUqMu1a670NJN3gXoomDfUEDwxF/Ab96Q+nm1mS8e+K0QPf9frssj5kqIkNUOb5QfV eDDAtD3bMMPlcNcvmkW7q0K3dG1vi9/Zj5P0JuclDWqnuAjqEZRxLWQxK5JHpA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=f872dde34c6af8c27e16905ebfdb62cddb4c35ba commit f872dde34c6af8c27e16905ebfdb62cddb4c35ba Author: Baptiste Daroussin AuthorDate: 2021-11-15 15:38:34 +0000 Commit: Baptiste Daroussin CommitDate: 2021-11-24 10:03:33 +0000 tzsetup: replace libdialog with libbsddialog Reviewed by: alfix86_gmail.com (bsddialog author) Differential Revision: https://reviews.freebsd.org/D33077 --- usr.sbin/tzsetup/Makefile | 6 +- usr.sbin/tzsetup/tzsetup.c | 189 +++++++++++++++++++++++---------------------- 2 files changed, 99 insertions(+), 96 deletions(-) diff --git a/usr.sbin/tzsetup/Makefile b/usr.sbin/tzsetup/Makefile index 7274b7680ca9..adef619b6596 100644 --- a/usr.sbin/tzsetup/Makefile +++ b/usr.sbin/tzsetup/Makefile @@ -7,10 +7,10 @@ MAN= tzsetup.8 CFLAGS+= -I. -.if ${MK_DIALOG} != no && !defined(BOOTSTRAPPING) +.if !defined(BOOTSTRAPPING) WARNS?= 3 -CFLAGS+= -I${SRCTOP}/contrib/dialog -DHAVE_DIALOG -LIBADD= dialog tinfow +CFLAGS+= -I${SRCTOP}/contrib/bsddialog/lib -DHAVE_BSDDIALOG +LIBADD= bsddialog .endif .include diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c index 6446800ce519..93871e27fb7b 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -49,8 +49,8 @@ __FBSDID("$FreeBSD$"); #include #include -#ifdef HAVE_DIALOG -#include +#ifdef HAVE_BSDDIALOG +#include #endif #define _PATH_ZONETAB "/usr/share/zoneinfo/zone1970.tab" @@ -86,7 +86,9 @@ static void usage(void); static int install_zoneinfo(const char *zoneinfo); static int install_zoneinfo_file(const char *zoneinfo_file); -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG +static struct bsddialog_conf conf; + /* for use in describing more exotic behaviors */ typedef struct dialogMenuItem { char *prompt; @@ -128,28 +130,30 @@ xdialog_count_columns(const char *p) } static int -xdialog_menu(const char *title, const char *cprompt, int height, int width, +xdialog_menu(char *title, 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); + struct bsddialog_menuitem *listitems; /* initialize list items */ - listitems = dlg_calloc(DIALOG_LISTITEM, item_no + 1); - assert_ptr(listitems, "xdialog_menu"); + listitems = calloc(item_no + 1, sizeof(struct bsddialog_menuitem)); + if (listitems == NULL) + errx(1, "Failed to allocate memory in xdialog_menu"); for (i = 0; i < item_no; i++) { + listitems[i].prefix = ""; + listitems[i].depth = 0; + listitems[i].bottomdesc = ""; + listitems[i].on = false; listitems[i].name = ditems[i].prompt; - listitems[i].text = ditems[i].title; + listitems[i].desc = ditems[i].title; } /* calculate height */ if (height < 0) height = xdialog_count_rows(cprompt) + menu_height + 4 + 2; - if (height > LINES) - height = LINES; + if (height > bsddialog_terminalheight()) + height = bsddialog_terminalheight() - 2; /* calculate width */ if (width < 0) { @@ -160,7 +164,7 @@ xdialog_menu(const char *title, const char *cprompt, int height, int width, l = strlen(listitems[i].name); for (j = 0; j < item_no; j++) { - int k = strlen(listitems[j].text); + int k = strlen(listitems[j].desc); tag_x = MAX(tag_x, l + k + 2); } } @@ -169,37 +173,39 @@ xdialog_menu(const char *title, const char *cprompt, int height, int width, width = MAX(width, tag_x + 4) + 4; } width = MAX(width, 24); - if (width > COLS) - width = COLS; + if (width > bsddialog_terminalwidth()) + width = bsddialog_terminalwidth() - 3; again: - dialog_vars.default_item = listitems[choice].name; - result = dlg_menu(title, cprompt, height, width, - menu_height, item_no, listitems, &choice, NULL); + conf.menu.default_item = listitems[choice].name; + conf.title = title; + result = bsddialog_menu(conf, cprompt, height, width, + menu_height, item_no, listitems, NULL); + for (int i = 0; i < item_no; i++) + if (listitems[i].on) + choice = i; switch (result) { - case DLG_EXIT_ESC: + case BSDDIALOG_ESC: result = -1; break; - case DLG_EXIT_OK: + case BSDDIALOG_YESOK: if (ditems[choice].fire != NULL) { int status; status = ditems[choice].fire(ditems + choice); if (status & DITEM_RECREATE) { - dlg_clear(); goto again; } } result = 0; break; - case DLG_EXIT_CANCEL: + case BSDDIALOG_NOCANCEL: default: result = 1; break; } free(listitems); - dlg_restore_vars(&save_vars); return (result); } @@ -657,7 +663,7 @@ set_zone_utc(void) static int confirm_zone(const char *filename) { - char title[64], prompt[64]; + char prompt[64]; time_t t = time(0); struct tm *tm; int rv; @@ -666,10 +672,10 @@ confirm_zone(const char *filename) tzset(); tm = localtime(&t); - snprintf(title, sizeof(title), "Confirmation"); snprintf(prompt, sizeof(prompt), "Does the abbreviation `%s' look reasonable?", tm->tm_zone); - rv = !dialog_yesno(title, prompt, 5, 72); + conf.title = "Confirmation"; + rv = !bsddialog_yesno(conf, prompt, 5, 72); return (rv); } @@ -705,7 +711,7 @@ static int install_zoneinfo_file(const char *zoneinfo_file) { char buf[1024]; - char title[64], prompt[SILLY_BUFFER_SIZE]; + char prompt[SILLY_BUFFER_SIZE]; struct stat sb; ssize_t len; int fd1, fd2, copymode; @@ -719,7 +725,6 @@ install_zoneinfo_file(const char *zoneinfo_file) copymode = 1; #ifdef VERBOSE - snprintf(title, sizeof(title), "Info"); if (copymode) snprintf(prompt, sizeof(prompt), "Copying %s to %s", zoneinfo_file, path_localtime); @@ -727,9 +732,10 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Creating symbolic link %s to %s", path_localtime, zoneinfo_file); -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); + conf.title = "Info"; + bsddialog_msgbox(conf, prompt, 8, 72); else #endif fprintf(stderr, "%s\n", prompt); @@ -739,14 +745,14 @@ install_zoneinfo_file(const char *zoneinfo_file) if (copymode) { fd1 = open(zoneinfo_file, O_RDONLY, 0); if (fd1 < 0) { - snprintf(title, sizeof(title), "Error"); snprintf(prompt, sizeof(prompt), "Could not open %s: %s", zoneinfo_file, strerror(errno)); -#ifdef HAVE_DIALOG - if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); - else +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = "Error"; + bsddialog_msgbox(conf, prompt, 8, 72); + } else #endif fprintf(stderr, "%s\n", prompt); return (DITEM_FAILURE | DITEM_RECREATE); @@ -756,10 +762,10 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Could not delete %s: %s", path_localtime, strerror(errno)); -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG if (usedialog) { - snprintf(title, sizeof(title), "Error"); - dialog_msgbox(title, prompt, 8, 72, 1); + conf.title = "error"; + bsddialog_msgbox(conf, prompt, 8, 72); } else #endif fprintf(stderr, "%s\n", prompt); @@ -769,14 +775,14 @@ install_zoneinfo_file(const char *zoneinfo_file) fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IRGRP | S_IROTH); if (fd2 < 0) { - snprintf(title, sizeof(title), "Error"); snprintf(prompt, sizeof(prompt), "Could not open %s: %s", path_localtime, strerror(errno)); -#ifdef HAVE_DIALOG - if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); - else +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = "Error"; + bsddialog_msgbox(conf, prompt, 8, 72); + } else #endif fprintf(stderr, "%s\n", prompt); return (DITEM_FAILURE | DITEM_RECREATE); @@ -787,14 +793,14 @@ install_zoneinfo_file(const char *zoneinfo_file) break; if (len == -1) { - snprintf(title, sizeof(title), "Error"); snprintf(prompt, sizeof(prompt), "Error copying %s to %s %s", zoneinfo_file, path_localtime, strerror(errno)); -#ifdef HAVE_DIALOG - if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); - else +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = "Error"; + bsddialog_msgbox(conf, prompt, 8, 72); + } else #endif fprintf(stderr, "%s\n", prompt); /* Better to leave none than a corrupt one. */ @@ -805,14 +811,14 @@ install_zoneinfo_file(const char *zoneinfo_file) close(fd2); } else { if (access(zoneinfo_file, R_OK) != 0) { - snprintf(title, sizeof(title), "Error"); snprintf(prompt, sizeof(prompt), "Cannot access %s: %s", zoneinfo_file, strerror(errno)); -#ifdef HAVE_DIALOG - if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); - else +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = "Error"; + bsddialog_msgbox(conf, prompt, 8, 72); + } else #endif fprintf(stderr, "%s\n", prompt); return (DITEM_FAILURE | DITEM_RECREATE); @@ -821,25 +827,25 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Could not delete %s: %s", path_localtime, strerror(errno)); -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG if (usedialog) { - snprintf(title, sizeof(title), "Error"); - dialog_msgbox(title, prompt, 8, 72, 1); + conf.title = "Error"; + bsddialog_msgbox(conf, prompt, 8, 72); } else #endif fprintf(stderr, "%s\n", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } if (symlink(zoneinfo_file, path_localtime) < 0) { - snprintf(title, sizeof(title), "Error"); snprintf(prompt, sizeof(prompt), "Cannot create symbolic link %s to %s: %s", path_localtime, zoneinfo_file, strerror(errno)); -#ifdef HAVE_DIALOG - if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); - else +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = "Error"; + bsddialog_msgbox(conf, prompt, 8, 72); + } else #endif fprintf(stderr, "%s\n", prompt); return (DITEM_FAILURE | DITEM_RECREATE); @@ -847,7 +853,6 @@ install_zoneinfo_file(const char *zoneinfo_file) } #ifdef VERBOSE - snprintf(title, sizeof(title), "Done"); if (copymode) snprintf(prompt, sizeof(prompt), "Copied timezone file from %s to %s", @@ -856,10 +861,11 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Created symbolic link from %s to %s", zoneinfo_file, path_localtime); -#ifdef HAVE_DIALOG - if (usedialog) - dialog_msgbox(title, prompt, 8, 72, 1); - else +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = "Done"; + bsddialog_msgbox(conf, prompt, 8, 72); + } else #endif fprintf(stderr, "%s\n", prompt); #endif @@ -903,8 +909,8 @@ usage(void) int main(int argc, char **argv) { -#ifdef HAVE_DIALOG - char title[64], prompt[128]; +#ifdef HAVE_BSDDIALOG + char prompt[128]; int fd; #endif int c, rv, skiputc; @@ -928,7 +934,7 @@ main(int argc, char **argv) break; case 'r': reinstall = 1; -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG usedialog = 0; #endif break; @@ -993,7 +999,7 @@ main(int argc, char **argv) struct stat sb; if (stat(argv[optind], &sb) != 0) { -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG usedialog = 0; #endif rv = install_zoneinfo(argv[optind]); @@ -1001,28 +1007,31 @@ main(int argc, char **argv) } /* FALLTHROUGH */ } -#ifdef HAVE_DIALOG +#ifdef HAVE_BSDDIALOG read_iso3166_table(); read_zones(); sort_countries(); make_menus(); - init_dialog(stdin, stdout); + bsddialog_initconf(&conf); + conf.clear = true; + + if (bsddialog_init() < 0) + return (1); + if (skiputc == 0) { - DIALOG_VARS save_vars; int yesno; - snprintf(title, sizeof(title), - "Select local or UTC (Greenwich Mean Time) clock"); snprintf(prompt, sizeof(prompt), "Is this machine's CMOS clock set to UTC? " "If it is set to local time,\n" "or you don't know, please choose NO here!"); - dlg_save_vars(&save_vars); - dialog_vars.defaultno = TRUE; - yesno = dialog_yesno(title, prompt, 7, 73); - dlg_restore_vars(&save_vars); + + conf.button.defaultno = true; + conf.title = "Select local or UTC (Greenwich Mean Time) clock"; + yesno = bsddialog_yesno(conf, prompt, 7, 73); + conf.button.defaultno = false; if (!yesno) { if (reallydoit) unlink(path_wall_cmos_clock); @@ -1032,34 +1041,28 @@ main(int argc, char **argv) O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IRGRP | S_IROTH); if (fd < 0) { - end_dialog(); + bsddialog_end(); err(1, "create %s", path_wall_cmos_clock); } close(fd); } } - dlg_clear(); } if (optind == argc - 1) { - snprintf(title, sizeof(title), "Default timezone provided"); snprintf(prompt, sizeof(prompt), "\nUse the default `%s' zone?", argv[optind]); - if (!dialog_yesno(title, prompt, 7, 72)) { + conf.title = "Default timezone provided"; + if (!bsddialog_yesno(conf, prompt, 7, 72)) { rv = install_zoneinfo_file(argv[optind]); - dlg_clear(); - end_dialog(); + bsddialog_end(); exit(rv & ~DITEM_LEAVE_MENU); } - dlg_clear(); } - snprintf(title, sizeof(title), "Time Zone Selector"); - snprintf(prompt, sizeof(prompt), "Select a region"); - xdialog_menu(title, prompt, -1, -1, NCONTINENTS, NCONTINENTS, - continents); + xdialog_menu("Time Zone Selector", "Select a region", -1, -1, + NCONTINENTS, NCONTINENTS, continents); - dlg_clear(); - end_dialog(); + bsddialog_end(); #else usage(); #endif