From patchwork Sat Oct 15 19:53:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 9377925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EEF9B60865 for ; Sat, 15 Oct 2016 20:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E07EF2932D for ; Sat, 15 Oct 2016 20:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4AB229422; Sat, 15 Oct 2016 20:19:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 403A02947C for ; Sat, 15 Oct 2016 20:19:28 +0000 (UTC) Received: from localhost ([::1]:53101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvVQV-0001DE-CE for patchwork-qemu-devel@patchwork.kernel.org; Sat, 15 Oct 2016 16:19:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvVQ1-0001BY-Gg for qemu-devel@nongnu.org; Sat, 15 Oct 2016 16:18:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvVQ0-0004Rf-0O for qemu-devel@nongnu.org; Sat, 15 Oct 2016 16:18:57 -0400 Received: from hera.aquilenet.fr ([141.255.128.1]:35850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvVPz-0004RR-Ml for qemu-devel@nongnu.org; Sat, 15 Oct 2016 16:18:55 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 6D5269A4B; Sat, 15 Oct 2016 22:18:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9WJpSbQq0QS9; Sat, 15 Oct 2016 22:18:54 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 41A989CFB; Sat, 15 Oct 2016 22:18:54 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1bvV13-0005L4-TZ; Sat, 15 Oct 2016 21:53:09 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org, kraxel@redhat.com, pbonzini@redhat.com, berrange@redhat.com, peter.maydell@linaro.org, mjt@tls.msk.ru Date: Sat, 15 Oct 2016 21:53:07 +0200 Message-Id: <20161015195308.20473-5-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161015195308.20473-1-samuel.thibault@ens-lyon.org> References: <20161015195308.20473-1-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 141.255.128.1 Subject: [Qemu-devel] [PATCH 4/5] curses: add option to specify VGA font encoding X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Thibault Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This detects and uses iconv to convert glyphs from the specified VGA font encoding to unicode. Signed-off-by: Samuel Thibault --- configure | 37 +++++++++++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 1 + qemu-options.hx | 5 ++++- ui/curses.c | 41 +++++++++++++++++++++++++++++++++++++++++ vl.c | 21 ++++++++++++++++++++- 5 files changed, 103 insertions(+), 2 deletions(-) diff --git a/configure b/configure index ebe0599..2ecd03a 100755 --- a/configure +++ b/configure @@ -203,6 +203,7 @@ bluez="" brlapi="" curl="" curses="" +cursesw="" docs="" fdt="" netmap="no" @@ -984,6 +985,10 @@ for opt do ;; --enable-curses) curses="yes" ;; + --disable-iconv) iconv="no" + ;; + --enable-iconv) iconv="yes" + ;; --disable-curl) curl="no" ;; --enable-curl) curl="yes" @@ -1351,6 +1356,7 @@ disabled with --disable-FEATURE, default is enabled if available: --with-gtkabi select preferred GTK ABI 2.0 or 3.0 vte vte support for the gtk UI curses curses UI + iconv font glyph conversion support vnc VNC UI support vnc-sasl SASL encryption for VNC server vnc-jpeg JPEG lossy compression for VNC server @@ -2938,6 +2944,33 @@ EOF fi ########################################## +# iconv probe +if test "$iconv" != "no" ; then + cat > $TMPC << EOF +#include +int main(void) { + iconv_t conv = iconv_open("ISO-8859-1", "ISO-8859-1"); + return conv != (iconv_t) -1; +} +EOF + for iconv_lib in '' -liconv; do + if compile_prog "" "$iconv_lib" ; then + iconv_found=yes + libs_softmmu="$iconv_lib $libs_softmmu" + break + fi + done + if test "$iconv_found" = "yes" ; then + iconv=yes + else + if test "$iconv" = "yes" ; then + feature_not_found "iconv" "Install iconv devel" + fi + iconv=no + fi +fi + +########################################## # curl probe if test "$curl" != "no" ; then if $pkg_config libcurl --exists; then @@ -4860,6 +4893,7 @@ echo "nettle $nettle $(echo_version $nettle $nettle_version)" echo "nettle kdf $nettle_kdf" echo "libtasn1 $tasn1" echo "curses support $curses" +echo "iconv support $iconv" echo "virgl support $virglrenderer" echo "curl support $curl" echo "mingw32 support $mingw32" @@ -5120,6 +5154,9 @@ fi if test "$curses" = "yes" ; then echo "CONFIG_CURSES=y" >> $config_host_mak fi +if test "$iconv" = "yes" ; then + echo "CONFIG_ICONV=y" >> $config_host_mak +fi if test "$utimens" = "yes" ; then echo "CONFIG_UTIMENSAT=y" >> $config_host_mak fi diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index ee7c760..b90b9b1 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -148,6 +148,7 @@ extern int graphic_height; extern int graphic_depth; extern int display_opengl; extern const char *keyboard_layout; +extern const char *font_charset; extern int win2k_install_hack; extern int alt_grab; extern int ctrl_grab; diff --git a/qemu-options.hx b/qemu-options.hx index 0b621bb..c82a26e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -930,7 +930,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, " [,window_close=on|off][,gl=on|off]|curses|none|\n" "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n" "-display vnc=[,]\n" - "-display curses\n" + "-display curses[,charset=]\n" "-display none" " select display type\n" "The default display is equivalent to\n" @@ -961,6 +961,9 @@ support a text mode, QEMU can display this output using a curses/ncurses interface. Nothing is displayed when the graphics device is in graphical mode or if the graphics device does not support a text mode. Generally only the VGA device models support text mode. +The font charset used by the guest can be specified with the +@code{charset} option, for example @code{charset=CP850} for IBM CP850 +encoding. The default is @code{CP437}. @item none Do not display video output. The guest will still see an emulated graphics card, but its output will not be displayed to the QEMU diff --git a/ui/curses.c b/ui/curses.c index cd8ed5f..f839a9d 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -31,6 +31,9 @@ #include #include #include +#ifdef CONFIG_ICONV +#include +#endif #include "qemu-common.h" #include "ui/console.h" @@ -397,6 +400,44 @@ static void curses_setup(void) vga_to_curses[0x1e].chars[0] = L'\u25b2'; vga_to_curses[0x1f].chars[0] = L'\u25bc'; +#ifdef CONFIG_ICONV + if (font_charset) { + unsigned char ch; + wchar_t wch; + char *pch, *pwch; + size_t sch, swch; + iconv_t conv; + + conv = iconv_open("WCHAR_T", font_charset); + if (conv == (iconv_t) -1) { + fprintf(stderr, "Could not convert font glyphs from %s: '%s'\n", + font_charset, strerror(errno)); + exit(1); + } + + for (i = 0x20; i <= 0xff; i++) { + ch = i; + pch = (char *) &ch; + pwch = (char *) &wch; + sch = sizeof(ch); + swch = sizeof(wch); + if (iconv(conv, &pch, &sch, &pwch, &swch) == (size_t) -1) { + fprintf(stderr, "Could not convert 0x%2x from %s: '%s'\n", + ch, font_charset, strerror(errno)); + } else { + vga_to_curses[ch].chars[0] = wch; + } + } + } else +#else + if (font_charset) { + if (strcmp(font_charset, "CP437")) { + fprintf(stderr, "iconv support not enabled for converting from %s, " + "only CP437 supported\n", font_charset); + exit(1); + } + } +#endif { /* Hardcode CP437 to unicode */ vga_to_curses[0x80].chars[0] = L'\u00C7'; diff --git a/vl.c b/vl.c index ad2664b..3043132 100644 --- a/vl.c +++ b/vl.c @@ -132,7 +132,8 @@ const char *bios_name = NULL; enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; int request_opengl = -1; int display_opengl; -const char* keyboard_layout = NULL; +const char *keyboard_layout; +const char *font_charset; ram_addr_t ram_size; const char *mem_path = NULL; int mem_prealloc = 0; /* force preallocation of physical target memory */ @@ -2140,6 +2141,24 @@ static DisplayType select_display(const char *p) } else if (strstart(p, "curses", &opts)) { #ifdef CONFIG_CURSES display = DT_CURSES; + while (*opts) { + const char *nextopt, *name; + + if (strstart(opts, ",charset=", &name)) { + nextopt = strchr(name, ','); + if (nextopt) { + font_charset = g_strndup(name, nextopt - name); + nextopt++; + } else { + font_charset = g_strdup(name); + nextopt = name + strlen(name); + } + } else { + error_report("invalid curses option string"); + exit(1); + } + opts = nextopt; + } #else error_report("curses support is disabled"); exit(1);