From nobody Wed Nov 24 10:56:32 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 5260E189FA81; Wed, 24 Nov 2021 10:56:33 +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 4HzdH50Gvsz3pd9; Wed, 24 Nov 2021 10:56:33 +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 DBA23851; Wed, 24 Nov 2021 10:56:32 +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 1AOAuW1v075239; Wed, 24 Nov 2021 10:56:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AOAuWvw075238; Wed, 24 Nov 2021 10:56:32 GMT (envelope-from git) Date: Wed, 24 Nov 2021 10:56:32 GMT Message-Id: <202111241056.1AOAuWvw075238@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: 24b05d7a6190 - main - kbdmap: use libbsddialog instead of calling dialog(1) via system(3) 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: 24b05d7a6190292f62488aa4d7de86246a09467c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637751393; 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=Jtm57x6UCYPjoYVwFPA6MyR4tLNMa9/b6LvMnIT7euE=; b=AucyJd8bVA+ZpHcYCSThritUnrutzYP0/UZuTjKe3fFskDrZCgFmcTYWLMbxnlK4BCNPIc BfuvCsVf8/fBnqEuHCHRDxgqZrko17GUcebOKe2ENgW8FkLacUrBeF/fNhfXWswOnBaeID xLgytl4hQ/9ccBH0bZJSwDbP8IYPHLdgMkTzhwsJmX5NK/YdBdsU3md/cwXUOLYz9dy6xy iaIYZeZueja03OEvWE6mdcgJPSRGExTpigtnG7zqvSeb+KgjZCQX2flRLdEATqvebA0Byn EuKkxe18gS3K/+1Ulof+dCwndpJKAj1jcESkgyKL5/9vB9xkqyHVZm1k1iXF7A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637751393; a=rsa-sha256; cv=none; b=tBPn4yjNwR44gVjavc4A7y8d0NrvTzgjOm6FHpkxGiEpiydphDytupEK6BvzguEv8ea9J0 IIzBrfhU/dh1ngV0ViM7lLXF1aVUFDwWLu2sr/WHufPpjqjWmCA6VQK0Hi/JSIlm2kpxLw 5WYsOYFHNYoQZ88bJlhY9cmPrc2dBEgXysPKJFwjnCpMZWyqp4S7Ec8A1esZE24Zr5dfMF f5PzOMZPCnMEbAkOi7A/3sMxsVZLDUpg9MF/1vGuEnPF6TVpAiIg7IFPICGDtli1GXWFUF GHSuP3sNVbcXs15AO61dAeD/aQxr70w60xMbIwoWGeIwsCsQO/OWbGHta1CEew== 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=24b05d7a6190292f62488aa4d7de86246a09467c commit 24b05d7a6190292f62488aa4d7de86246a09467c Author: Baptiste Daroussin AuthorDate: 2021-11-24 10:55:26 +0000 Commit: Baptiste Daroussin CommitDate: 2021-11-24 10:55:26 +0000 kbdmap: use libbsddialog instead of calling dialog(1) via system(3) --- usr.sbin/kbdmap/Makefile | 2 + usr.sbin/kbdmap/kbdmap.c | 108 +++++++++++++++++++---------------------------- 2 files changed, 46 insertions(+), 64 deletions(-) diff --git a/usr.sbin/kbdmap/Makefile b/usr.sbin/kbdmap/Makefile index ec493416a573..22747e70720c 100644 --- a/usr.sbin/kbdmap/Makefile +++ b/usr.sbin/kbdmap/Makefile @@ -1,6 +1,8 @@ # $FreeBSD$ PROG= kbdmap +CFLAGS+= -I${SRCTOP}/contrib/bsddialog/lib +LIBADD= bsddialog LINKS= ${BINDIR}/kbdmap ${BINDIR}/vidfont MLINKS= kbdmap.1 vidfont.1 diff --git a/usr.sbin/kbdmap/kbdmap.c b/usr.sbin/kbdmap/kbdmap.c index 4f99ba03c2c8..2783d2368e0e 100644 --- a/usr.sbin/kbdmap/kbdmap.c +++ b/usr.sbin/kbdmap/kbdmap.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -350,19 +351,23 @@ do_vidfont(struct keymap *km) static void show_dialog(struct keymap **km_sorted, int num_keymaps) { - FILE *fp; - char *cmd, *dialog; - char tmp_name[] = "/tmp/_kbd_lang.XXXX"; - int fd, i, size; - - fd = mkstemp(tmp_name); - if (fd == -1) { - fprintf(stderr, "Could not open temporary file \"%s\"\n", - tmp_name); + struct bsddialog_conf conf; + struct bsddialog_menuitem *listitems; + int i, result; + + bsddialog_initconf(&conf); + conf.clear = true; + if (bsddialog_init() < 0) { + fprintf(stderr, "Failed to initialize bsddialog"); + exit(1); + } + conf.title = __DECONST(char *, title); + + listitems = calloc(num_keymaps + 1, sizeof(struct bsddialog_menuitem)); + if (listitems == NULL) { + fprintf(stderr, "Failed to allocate memory in show_dialog"); exit(1); } - asprintf(&dialog, "/usr/bin/dialog --clear --title \"%s\" " - "--menu \"%s\" 0 0 0", title, menu); /* start right font, assume that current font is equal * to default font in /etc/rc.conf @@ -374,63 +379,38 @@ show_dialog(struct keymap **km_sorted, int num_keymaps) if (font && strcmp(font, font_current)) vidcontrol(font); - /* Build up the command */ - size = 0; - for (i=0; idesc) + 6; - } - - /* Allow the space for '2> tmpfilename' redirection */ - size += strlen(tmp_name) + 3; - - cmd = (char *) malloc(strlen(dialog) + size + 1); - strcpy(cmd, dialog); - + /* Build up the menu */ for (i=0; idesc); - strcat(cmd, "\""); - strcat(cmd, " \"\""); + listitems[i].prefix = __DECONST(char *, ""); + listitems[i].depth = 0; + listitems[i].bottomdesc = __DECONST(char *, ""); + listitems[i].on = false; + listitems[i].name = km_sorted[i]->desc; + listitems[i].desc = __DECONST(char *, ""); } - - strcat(cmd, " 2>"); - strcat(cmd, tmp_name); - - /* Show the dialog.. */ - system(cmd); - - fp = fopen(tmp_name, "r"); - if (fp) { - char choice[64]; - if (fgets(choice, sizeof(choice), fp) != NULL) { - /* Find key for desc */ - for (i=0; idesc)) { - if (!strcmp(program, "kbdmap")) - do_kbdcontrol(km_sorted[i]); - else - do_vidfont(km_sorted[i]); - break; - } + result = bsddialog_menu(conf, __DECONST(char *, menu), 0, 0, 0, + num_keymaps, listitems, NULL); + bsddialog_end(); + switch (result) { + case BSDDIALOG_YESOK: + for (i = 0; i < num_keymaps; i++) { + if (listitems[i].on) { + printf("ici\n"); + if (!strcmp(program, "kdbmap")) + do_kbdcontrol(km_sorted[i]); + else + do_vidfont(km_sorted[i]); + break; } - } else { - if (font != NULL && strcmp(font, font_current)) - /* Cancelled, restore old font */ - vidcontrol(font_current); } - fclose(fp); - } else - fprintf(stderr, "Failed to open temporary file"); - - /* Tidy up */ - remove(tmp_name); - free(cmd); - free(dialog); - close(fd); + break; + default: + printf("la\n"); + if (font != NULL && strcmp(font, font_current)) + /* Cancelled, restore old font */ + vidcontrol(font_current); + break; + } } /*