From nobody Mon Apr 11 22:39:13 2022 X-Original-To: dev-commits-src-all@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 9AFD711E550B; Mon, 11 Apr 2022 22:39:13 +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 4KckL93yH3z4ZG8; Mon, 11 Apr 2022 22:39:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649716753; 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=RFmcX1kqvj+7W+CCmBfKUtbuVft3VDBcaJuarlSkZUE=; b=rIQZZWkA/hEZUi/ZBLeKf7U9o3xYvXJcJYR8zKwiaRiDegfY2UOb/oAvlo1bphXAUybhy3 joLTB0fkw1p3Hmvy1+rbNmR8BWx0eszkgKi5DtCEjtnDtcYrrPnYaTGqLA+PEogTlV1QS+ SQyfcKqWFH+2oTjNK65m8KJR41mIptg5zLAYgdQpsHjwYP8xOC3owiU+0D7d6aZy0Jz2ow 9ULCZFAC3SKany4wa69OIV4PTeT2RXBaPMzVYf3nmpd0l24x5DEWiZt532ifLwIweV9kgs +RHFvL69AepifaEmUx8QQlbgNnsOjk5geTkc0Ysa/bxPd4NNGz6EB39OIo2RTA== 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 6411833CB; Mon, 11 Apr 2022 22:39:13 +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 23BMdDd8045436; Mon, 11 Apr 2022 22:39:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23BMdDSL045435; Mon, 11 Apr 2022 22:39:13 GMT (envelope-from git) Date: Mon, 11 Apr 2022 22:39:13 GMT Message-Id: <202204112239.23BMdDSL045435@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alfonso S. Siciliano" Subject: git: 94cb21cda66b - main - tzsetup(8): Refactoring to delete dialog(3) code List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asiciliano X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 94cb21cda66b33851a0eb82a7df8b64047a31c3f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649716753; 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=RFmcX1kqvj+7W+CCmBfKUtbuVft3VDBcaJuarlSkZUE=; b=NESXCWJ1HKj7NH9fOVlmpPAPjuWj3y5Tg0vXnT8aHGD6kwdjfzxvDI9KUiQqcaqVlfW5wT HWrfijqcZaFZvnMu7f/Y+QueIJvX96Qa4IdSjDw5LwK6nAAbQmR+VGwBeNG8KwyVPbFyLT y1stKPCz4IZn8bW1WJef5x0LbwAQ2vBmkUlWgjqhtObfgi/KoobZKwpuk9FDWLjbrpTkzi vGZwCnifS1EAPZLNKf7T+8m/Ai1La4YwmNUi0kYedCYhOr7Wn+C/tMr8+6xrhy3aGrB4tQ zTExJhKF6u/pTbuvS9lhUwefPZARrMZIA69qPkGwdZVjKGd+wEKlPzfBHEdFfA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649716753; a=rsa-sha256; cv=none; b=CbeijeXKZMWxW9JQ10icR7QOjdATnUKwbMg9IHjC5yy4Clfq+vZvbIMvtcNPfOuB5f2kEJ hTcOXxxBA2TbAZ4G28aIeKDmrFpmFRdGL+E5gQhgtlJpTHPdE4y7+3YvXt4Sm9MdCX1hwi FhW9jpcIbR6gJDp0VN8L62x5EAA/Hbg9Udkt/22QfM5h8a7ziYKQKqM0VSrY0HGtsb6dmI AwkDUV1JC86MYeOj4brNX9ICnOvj4oFISFsC/LXDXQhbGVSXFKYbL6Q94RGwHwpoA9H4p+ Ocdom7sBa+UhfBfuLLjEAAUwuU8X5+r4gMwBXd04U3Rhlpku0Rit40mADAXkFg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asiciliano: URL: https://cgit.FreeBSD.org/src/commit/?id=94cb21cda66b33851a0eb82a7df8b64047a31c3f commit 94cb21cda66b33851a0eb82a7df8b64047a31c3f Author: Alfonso S. Siciliano AuthorDate: 2022-04-11 22:27:29 +0000 Commit: Alfonso S. Siciliano CommitDate: 2022-04-11 22:38:40 +0000 tzsetup(8): Refactoring to delete dialog(3) code Little refactoring to complete the conversion to bsddialog(3), not functional changes: * Delete: remaining code for autosizing using BSDDIALOG_AUTOSIZE. * Add: constants to delete magical numbers and to avoid unclear returned values. * Delete: redundant 'conf.button.default_cancel=false', performed by bsddialog_initconf(). * Add: a new function message_zoneinfo_file() to merge features. Approved by: bapt (mentor) Differential Revision: https://reviews.freebsd.org/D34862 --- usr.sbin/tzsetup/tzsetup.c | 141 ++++++++++++--------------------------------- 1 file changed, 38 insertions(+), 103 deletions(-) diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c index 7dffb236af18..310414e69975 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -85,6 +85,7 @@ static char *chrootenv = NULL; static void usage(void); static int install_zoneinfo(const char *zoneinfo); +static void message_zoneinfo_file(const char *title, char *prompt); static int install_zoneinfo_file(const char *zoneinfo_file); #ifdef HAVE_BSDDIALOG @@ -99,10 +100,9 @@ typedef struct dialogMenuItem { } dialogMenuItem; static int -xdialog_menu(char *title, char *cprompt, int height, int width, - int menu_height, int item_no, dialogMenuItem *ditems) +xdialog_menu(char *title, char *cprompt, int item_no, dialogMenuItem *ditems) { - int i, result, choice = 0; + int i, result, menurows, choice = 0; struct bsddialog_menuitem *listitems; /* initialize list items */ @@ -118,18 +118,11 @@ xdialog_menu(char *title, char *cprompt, int height, int width, listitems[i].desc = ditems[i].title; } - if (height < 0) - height = BSDDIALOG_AUTOSIZE; - - if (width < 0) { - width = BSDDIALOG_AUTOSIZE; - conf.auto_minwidth = 24; - } - again: conf.title = title; - result = bsddialog_menu(&conf, cprompt, height, width, - menu_height, item_no, listitems, &choice); + menurows = item_no < 16 ? item_no : 16; + result = bsddialog_menu(&conf, cprompt, BSDDIALOG_AUTOSIZE, + BSDDIALOG_AUTOSIZE, menurows, item_no, listitems, &choice); switch (result) { case BSDDIALOG_ESC: result = -1; @@ -216,7 +209,6 @@ continent_country_menu(dialogMenuItem *continent) char title[64], prompt[64]; struct continent *contp = continent->data; int isocean = OCEANP(continent - continents); - int menulen; int rv; if (strcmp(continent->title, "UTC") == 0) @@ -237,12 +229,8 @@ continent_country_menu(dialogMenuItem *continent) snprintf(prompt, sizeof(prompt), "Select an island or group"); } - menulen = contp->nitems < 16 ? contp->nitems : 16; - rv = xdialog_menu(title, prompt, -1, -1, menulen, contp->nitems, - contp->menu); - if (rv == 0) - return (DITEM_LEAVE_MENU); - return (DITEM_RECREATE); + rv = xdialog_menu(title, prompt, contp->nitems, contp->menu); + return (rv == 0 ? DITEM_LEAVE_MENU : DITEM_RECREATE); } static struct continent * @@ -583,18 +571,13 @@ set_zone_menu(dialogMenuItem *dmi) { char title[64], prompt[64]; struct country *cp = dmi->data; - int menulen; int rv; snprintf(title, sizeof(title), "%s Time Zones", cp->name); snprintf(prompt, sizeof(prompt), "Select a zone which observes the same time as your locality."); - menulen = cp->nzones < 16 ? cp->nzones : 16; - rv = xdialog_menu(title, prompt, -1, -1, menulen, cp->nzones, - cp->submenu); - if (rv != 0) - return (DITEM_RECREATE); - return (DITEM_LEAVE_MENU); + rv = xdialog_menu(title, prompt, cp->nzones, cp->submenu); + return (rv != 0 ? DITEM_RECREATE : DITEM_LEAVE_MENU); } static int @@ -621,7 +604,7 @@ confirm_zone(const char *filename) snprintf(prompt, sizeof(prompt), "Does the abbreviation `%s' look reasonable?", tm->tm_zone); conf.title = "Confirmation"; - rv = !bsddialog_yesno(&conf, prompt, 5, 72); + rv = (bsddialog_yesno(&conf, prompt, 5, 72) == BSDDIALOG_YES); return (rv); } @@ -653,6 +636,17 @@ set_zone_whole_country(dialogMenuItem *dmi) #endif +static void message_zoneinfo_file(const char *title, char *prompt) +{ +#ifdef HAVE_BSDDIALOG + if (usedialog) { + conf.title = title; + bsddialog_msgbox(&conf, prompt, 8, 72); + } else +#endif + fprintf(stderr, "%s: %s\n", title, prompt); +} + static int install_zoneinfo_file(const char *zoneinfo_file) { @@ -678,13 +672,7 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Creating symbolic link %s to %s", path_localtime, zoneinfo_file); -#ifdef HAVE_BSDDIALOG - if (usedialog) - conf.title = "Info"; - bsddialog_msgbox(&conf, prompt, 8, 72); - else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Info", prompt); #endif if (reallydoit) { @@ -694,13 +682,7 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Could not open %s: %s", zoneinfo_file, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } @@ -708,13 +690,7 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Could not delete %s: %s", path_localtime, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } @@ -724,13 +700,7 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Could not open %s: %s", path_localtime, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } @@ -742,13 +712,7 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Error copying %s to %s %s", zoneinfo_file, path_localtime, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); /* Better to leave none than a corrupt one. */ unlink(path_localtime); return (DITEM_FAILURE | DITEM_RECREATE); @@ -760,26 +724,14 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Cannot access %s: %s", zoneinfo_file, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } if (unlink(path_localtime) < 0 && errno != ENOENT) { snprintf(prompt, sizeof(prompt), "Could not delete %s: %s", path_localtime, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } if (symlink(zoneinfo_file, path_localtime) < 0) { @@ -787,13 +739,7 @@ install_zoneinfo_file(const char *zoneinfo_file) "Cannot create symbolic link %s to %s: %s", path_localtime, zoneinfo_file, strerror(errno)); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Error"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Error", prompt); return (DITEM_FAILURE | DITEM_RECREATE); } } @@ -807,13 +753,7 @@ install_zoneinfo_file(const char *zoneinfo_file) snprintf(prompt, sizeof(prompt), "Created symbolic link from %s to %s", zoneinfo_file, path_localtime); -#ifdef HAVE_BSDDIALOG - if (usedialog) { - conf.title = "Done"; - bsddialog_msgbox(&conf, prompt, 8, 72); - } else -#endif - fprintf(stderr, "%s\n", prompt); + message_zoneinfo_file("Done", prompt); #endif } /* reallydoit */ @@ -966,25 +906,20 @@ main(int argc, char **argv) bsddialog_initconf(&conf); conf.clear = true; + conf.auto_minwidth = 24; conf.key.enable_esc = true; - if (bsddialog_init() == BSDDIALOG_ERROR) { - printf("Error bsddialog: %s\n", bsddialog_geterror()); - return (1); - } + if (bsddialog_init() == BSDDIALOG_ERROR) + errx(1, "Error bsddialog: %s\n", bsddialog_geterror()); if (skiputc == 0) { - int yesno; - 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!"); - conf.button.default_cancel = false; conf.title = "Select local or UTC (Greenwich Mean Time) clock"; - yesno = bsddialog_yesno(&conf, prompt, 7, 73); - if (!yesno) { + if (bsddialog_yesno(&conf, prompt, 7, 73) == BSDDIALOG_YES) { if (reallydoit) unlink(path_wall_cmos_clock); } else { @@ -1005,14 +940,14 @@ main(int argc, char **argv) snprintf(prompt, sizeof(prompt), "\nUse the default `%s' zone?", argv[optind]); conf.title = "Default timezone provided"; - if (!bsddialog_yesno(&conf, prompt, 7, 72)) { + if (bsddialog_yesno(&conf, prompt, 7, 72) == BSDDIALOG_YES) { rv = install_zoneinfo_file(argv[optind]); bsddialog_end(); exit(rv & ~DITEM_LEAVE_MENU); } } - xdialog_menu("Time Zone Selector", "Select a region", -1, -1, - NCONTINENTS, NCONTINENTS, continents); + xdialog_menu("Time Zone Selector", "Select a region", NCONTINENTS, + continents); bsddialog_end(); #else