From 7ece458307ec1c6617f2eda1099cc393a876ca79 Mon Sep 17 00:00:00 2001 From: bird Date: Sat, 29 Jan 2022 02:41:10 +0000 Subject: [PATCH] grep: Use get_crt_codepage(). Don't default to the UTF-8 manifest for older VCC versions as the CRT won't do the right thing. git-svn-id: https://www.virtualbox.org/svn/kbuild-mirror/trunk@3548 1093d150-e988-4e3a-8fd4-90e8b09e91e5 --- src/grep/Makefile.kmk | 5 ++--- src/grep/config.win.h | 2 ++ src/grep/lib/regcomp.c | 2 +- src/grep/src/grep.c | 9 +++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/grep/Makefile.kmk b/src/grep/Makefile.kmk index cc11c4fe..681641c9 100644 --- a/src/grep/Makefile.kmk +++ b/src/grep/Makefile.kmk @@ -133,8 +133,7 @@ kmk_grep_SOURCES.win = \ lib/xbinary-io.c \ lib/strerror.c \ \ - ../lib/maybe_con_fwrite.c \ - ../lib/is_console.c \ + ../lib/get_codepage.c \ ../lib/nt/ntstat.c \ ../lib/nt/ntdir.c \ ../lib/nt/nthlpcore.c \ @@ -239,7 +238,7 @@ $$(kmk_grep_0_OUTDIR)/unistd.h: $(MAKEFILE_CURRENT) | $$(call DIRDEP,$$(kmk_grep $$(kmk_grep_0_OUTDIR)/sigsegv.h: $(PATH_SUB_CURRENT)/lib/sigsegv.in.h | $$(call DIRDEP,$$(kmk_grep_0_OUTDIR)) $(CP) -f -- "$^" "$@" -if 1 # Add a manifest making UTF-8 as the active code page. +ifndef KBUILD_NEW_VCC # Add a manifest making UTF-8 as the active code page. kmk_grep_LNK_DEPS.win = \ $(kmk_grep_0_OUTDIR)/kmk_grep.manifest diff --git a/src/grep/config.win.h b/src/grep/config.win.h index e56fc779..64e241b9 100644 --- a/src/grep/config.win.h +++ b/src/grep/config.win.h @@ -2588,5 +2588,7 @@ extern int wcwidth(wchar_t); #define initialize_main w32_initialize_main void w32_initialize_main(int *pcArgs, char ***ppapszArgs); +#include "get_codepage.h" + #endif /* !INCLUDED_CONFIG_WIN_H */ diff --git a/src/grep/lib/regcomp.c b/src/grep/lib/regcomp.c index 7b397d85..02b0e700 100644 --- a/src/grep/lib/regcomp.c +++ b/src/grep/lib/regcomp.c @@ -876,7 +876,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len) #else # ifdef _MSC_VER (void)codeset_name; - if (GetACP() == 65001 /*utf-8*/) + if (get_crt_codepage() == CP_UTF8) # else codeset_name = nl_langinfo (CODESET); if ((codeset_name[0] == 'U' || codeset_name[0] == 'u') diff --git a/src/grep/src/grep.c b/src/grep/src/grep.c index a1706848..aabae2d3 100644 --- a/src/grep/src/grep.c +++ b/src/grep/src/grep.c @@ -533,9 +533,10 @@ fwrite_errno (void const *ptr, size_t size, size_t nmemb) s_hStdOut = (HANDLE)_get_osfhandle (fileno (stdout)); g_fStdOutIsConsole = GetConsoleMode (s_hStdOut, &fModeIgnored) ? TRUE : FALSE; - if (getenv("KMK_GREP_CONSOLE_DEBUG")) - fprintf(stderr, "kmk_grep: g_fStdOutIsConsole=%d s_hStdOut=%p codepage=%u\n", - g_fStdOutIsConsole, s_hStdOut, ___lc_codepage_func()); + if (getenv ("KMK_GREP_CONSOLE_DEBUG")) + fprintf (stderr, "kmk_grep: hStdOut=%p %sconsole codepage=%u ansi=%u\n", + s_hStdOut, g_fStdOutIsConsole ? "" : "!", + get_crt_codepage (), get_ansi_codepage ()); } if (g_fStdOutIsConsole == TRUE && size && nmemb) { @@ -559,7 +560,7 @@ fwrite_errno (void const *ptr, size_t size, size_t nmemb) pawcFree = pawcBuf = (wchar_t *)malloc(cwcBuf * sizeof(wchar_t)); if (pawcBuf) { - int cwcToWrite = MultiByteToWideChar(___lc_codepage_func(), + int cwcToWrite = MultiByteToWideChar(get_crt_codepage(), 0 /*dwFlags*/, ptr, (int)cbToWrite, pawcBuf, (int)(cwcBuf - 1)); -- 2.11.4.GIT