From patchwork Sun Feb 2 21:15:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17668 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3BF2F44BAC7 for ; Sun, 2 Feb 2020 23:16:00 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 23BA6689884; Sun, 2 Feb 2020 23:16:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D42686891EF for ; Sun, 2 Feb 2020 23:15:53 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B7A2EE3446; Sun, 2 Feb 2020 22:15:53 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ruIz3ThA5Cn8; Sun, 2 Feb 2020 22:15:52 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7AE65E3DF2; Sun, 2 Feb 2020 22:15:51 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Feb 2020 22:15:34 +0100 Message-Id: <20200202211534.12739-5-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200202211534.12739-1-cus@passwd.hu> References: <20200202211534.12739-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 5/5] avutil/log: add support for multibyte console log for win32 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes ticket #5398. Signed-off-by: Marton Balint --- libavutil/log.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libavutil/log.c b/libavutil/log.c index 213594c2a5..78e703b9e9 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -120,6 +120,31 @@ static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { #endif static int use_color = -1; +#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE +static void win_console_puts(const char *str) +{ + const uint8_t *q = str; + uint16_t line[LINE_SZ]; + + while (*q) { + uint16_t *buf = line; + DWORD nb_chars = 0; + DWORD written; + + while (*q && nb_chars < LINE_SZ - 1) { + uint32_t ch; + uint16_t tmp; + + GET_UTF8(ch, *q ? *q++ : 0, ch = 0xfffd; goto continue_on_invalid;) +continue_on_invalid: + PUT_UTF16(ch, tmp, *buf++ = tmp; nb_chars++;) + } + + WriteConsoleW(con, line, nb_chars, &written, NULL); + } +} +#endif + static void check_color_terminal(void) { char *term = getenv("TERM"); @@ -195,7 +220,7 @@ static void colored_fputs(int level, int tint, const char *str) if (con != INVALID_HANDLE_VALUE) { if (local_use_color) SetConsoleTextAttribute(con, background | color[level]); - fputs(str, stderr); + win_console_puts(str); if (local_use_color) SetConsoleTextAttribute(con, attr_orig); } else {