|
| 1 | +From cc5842e3e1c8937d54b624dae9718a17573c630c Mon Sep 17 00:00:00 2001 |
| 2 | +From: "K.Takata" < [email protected]> |
| 3 | +Date: Wed, 26 Feb 2020 20:43:57 +0900 |
| 4 | +Subject: [PATCH] win32: Enable UTF-8 mode on Windows 10 1903 or later |
| 5 | + |
| 6 | +Also define `__USE_MINGW_ANSI_STDIO` so that `%zu` can be used. |
| 7 | +--- |
| 8 | + Makefile.am | 11 ++++ |
| 9 | + configure.ac | 3 ++ |
| 10 | + src/main.c | 17 ++++++ |
| 11 | + src/win32/ag.exe.manifest | 30 +++++++++++ |
| 12 | + src/win32/ag.rc | 107 ++++++++++++++++++++++++++++++++++++++ |
| 13 | + src/win32/resource.h | 14 +++++ |
| 14 | + 6 files changed, 182 insertions(+) |
| 15 | + create mode 100644 src/win32/ag.exe.manifest |
| 16 | + create mode 100644 src/win32/ag.rc |
| 17 | + create mode 100644 src/win32/resource.h |
| 18 | + |
| 19 | +diff --git a/Makefile.am b/Makefile.am |
| 20 | +index ead4a80..e4d71c0 100644 |
| 21 | +--- a/Makefile.am |
| 22 | ++++ b/Makefile.am |
| 23 | +@@ -12,6 +12,7 @@ zshcompdir = $(datadir)/zsh/site-functions |
| 24 | + dist_zshcomp_DATA = _the_silver_searcher |
| 25 | + |
| 26 | + EXTRA_DIST = Makefile.w32 LICENSE NOTICE the_silver_searcher.spec README.md |
| 27 | ++MOSTLYCLEANFILES = |
| 28 | + |
| 29 | + all: |
| 30 | + @$(MAKE) ag -r |
| 31 | +@@ -24,6 +25,16 @@ else |
| 32 | + @echo "clang-format is not available. Skipped clang-format test." |
| 33 | + endif |
| 34 | + |
| 35 | ++if HOST_MINGW |
| 36 | ++WINDRES = windres |
| 37 | ++RES_OBJ = src/win32/ag.res.o |
| 38 | ++ag_LDADD += $(RES_OBJ) |
| 39 | ++$(RES_OBJ): src/win32/ag.rc src/win32/ag.exe.manifest src/win32/resource.h |
| 40 | ++ @mkdir -p $(builddir)/src/win32 |
| 41 | ++ $(WINDRES) -o $@ -O coff $< |
| 42 | ++MOSTLYCLEANFILES += $(RES_OBJ) |
| 43 | ++endif |
| 44 | ++ |
| 45 | + test_big: ag |
| 46 | + cram -v tests/big/*.t |
| 47 | + |
| 48 | +diff --git a/configure.ac b/configure.ac |
| 49 | +index bf2b7d8..269eac1 100644 |
| 50 | +--- a/configure.ac |
| 51 | ++++ b/configure.ac |
| 52 | +@@ -35,9 +35,12 @@ LDFLAGS="$LDFLAGS" |
| 53 | + |
| 54 | + case $host in |
| 55 | + *mingw*) |
| 56 | ++ host_mingw=yes |
| 57 | + AC_CHECK_LIB(shlwapi, main,, AC_MSG_ERROR(libshlwapi missing)) |
| 58 | + CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0600" |
| 59 | ++ CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO" |
| 60 | + esac |
| 61 | ++AM_CONDITIONAL([HOST_MINGW], [test "x${host_mingw}" = "xyes"]) |
| 62 | + |
| 63 | + LIBS="$PTHREAD_LIBS $LIBS" |
| 64 | + |
| 65 | +diff --git a/src/main.c b/src/main.c |
| 66 | +index 6de2038..d707c7b 100644 |
| 67 | +--- a/src/main.c |
| 68 | ++++ b/src/main.c |
| 69 | +@@ -72,11 +72,28 @@ int main(int argc, char **argv) { |
| 70 | + #endif |
| 71 | + |
| 72 | + #ifdef _WIN32 |
| 73 | ++#define MAKE_VER(major, minor, build) \ |
| 74 | ++ (((major) << 24) | ((minor) << 16) | (build)) |
| 75 | + { |
| 76 | + SYSTEM_INFO si; |
| 77 | ++ OSVERSIONINFO ovi; |
| 78 | ++ DWORD ver; |
| 79 | ++ |
| 80 | + GetSystemInfo(&si); |
| 81 | + num_cores = si.dwNumberOfProcessors; |
| 82 | ++ |
| 83 | ++ // Use UTF-8 mode on Windows 10 1903 or later. |
| 84 | ++ ovi.dwOSVersionInfoSize = sizeof(ovi); |
| 85 | ++ GetVersionEx(&ovi); |
| 86 | ++ ver = MAKE_VER(min(ovi.dwMajorVersion, 255), |
| 87 | ++ min(ovi.dwMinorVersion, 255), |
| 88 | ++ min(ovi.dwBuildNumber, 36767)); |
| 89 | ++ if (ver >= MAKE_VER(10, 0, 18362)) { |
| 90 | ++ SetConsoleCP(CP_UTF8); |
| 91 | ++ SetConsoleOutputCP(CP_UTF8); |
| 92 | ++ } |
| 93 | + } |
| 94 | ++#undef MAKE_VER |
| 95 | + #else |
| 96 | + num_cores = (int)sysconf(_SC_NPROCESSORS_ONLN); |
| 97 | + #endif |
| 98 | +diff --git a/src/win32/ag.exe.manifest b/src/win32/ag.exe.manifest |
| 99 | +new file mode 100644 |
| 100 | +index 0000000..dd75735 |
| 101 | +--- /dev/null |
| 102 | ++++ b/src/win32/ag.exe.manifest |
| 103 | +@@ -0,0 +1,30 @@ |
| 104 | ++<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
| 105 | ++<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> |
| 106 | ++ <assemblyIdentity type="win32" name="The Silver Searcher" version="2.2.0.0" /> |
| 107 | ++ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
| 108 | ++ <security> |
| 109 | ++ <requestedPrivileges> |
| 110 | ++ <requestedExecutionLevel level="asInvoker" uiAccess="false" /> |
| 111 | ++ </requestedPrivileges> |
| 112 | ++ </security> |
| 113 | ++ </trustInfo> |
| 114 | ++ <application> |
| 115 | ++ <windowsSettings> |
| 116 | ++ <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage> |
| 117 | ++ </windowsSettings> |
| 118 | ++ </application> |
| 119 | ++ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> |
| 120 | ++ <application> |
| 121 | ++ <!--The ID below indicates application support for Windows Vista --> |
| 122 | ++ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> |
| 123 | ++ <!--The ID below indicates application support for Windows 7 --> |
| 124 | ++ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> |
| 125 | ++ <!--The ID below indicates application support for Windows 8 --> |
| 126 | ++ <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> |
| 127 | ++ <!--The ID below indicates application support for Windows 8.1 --> |
| 128 | ++ <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> |
| 129 | ++ <!--The ID below indicates application support for Windows 10 --> |
| 130 | ++ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> |
| 131 | ++ </application> |
| 132 | ++ </compatibility> |
| 133 | ++</assembly> |
| 134 | +diff --git a/src/win32/ag.rc b/src/win32/ag.rc |
| 135 | +new file mode 100644 |
| 136 | +index 0000000..d1fc191 |
| 137 | +--- /dev/null |
| 138 | ++++ b/src/win32/ag.rc |
| 139 | +@@ -0,0 +1,107 @@ |
| 140 | ++// Microsoft Visual C++ generated resource script. |
| 141 | ++// |
| 142 | ++#include "resource.h" |
| 143 | ++ |
| 144 | ++#define APSTUDIO_READONLY_SYMBOLS |
| 145 | ++///////////////////////////////////////////////////////////////////////////// |
| 146 | ++// |
| 147 | ++// Generated from the TEXTINCLUDE 2 resource. |
| 148 | ++// |
| 149 | ++#include "winresrc.h" |
| 150 | ++ |
| 151 | ++///////////////////////////////////////////////////////////////////////////// |
| 152 | ++#undef APSTUDIO_READONLY_SYMBOLS |
| 153 | ++ |
| 154 | ++///////////////////////////////////////////////////////////////////////////// |
| 155 | ++// English (United States) resources |
| 156 | ++ |
| 157 | ++#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) |
| 158 | ++LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US |
| 159 | ++#pragma code_page(1252) |
| 160 | ++ |
| 161 | ++#ifdef APSTUDIO_INVOKED |
| 162 | ++///////////////////////////////////////////////////////////////////////////// |
| 163 | ++// |
| 164 | ++// TEXTINCLUDE |
| 165 | ++// |
| 166 | ++ |
| 167 | ++1 TEXTINCLUDE |
| 168 | ++BEGIN |
| 169 | ++ "resource.h\0" |
| 170 | ++END |
| 171 | ++ |
| 172 | ++2 TEXTINCLUDE |
| 173 | ++BEGIN |
| 174 | ++ "#include ""winres.h""\r\n" |
| 175 | ++ "\0" |
| 176 | ++END |
| 177 | ++ |
| 178 | ++3 TEXTINCLUDE |
| 179 | ++BEGIN |
| 180 | ++ "\r\n" |
| 181 | ++ "\0" |
| 182 | ++END |
| 183 | ++ |
| 184 | ++#endif // APSTUDIO_INVOKED |
| 185 | ++ |
| 186 | ++ |
| 187 | ++///////////////////////////////////////////////////////////////////////////// |
| 188 | ++// |
| 189 | ++// RT_MANIFEST |
| 190 | ++// |
| 191 | ++ |
| 192 | ++1 RT_MANIFEST "ag.exe.manifest" |
| 193 | ++ |
| 194 | ++///////////////////////////////////////////////////////////////////////////// |
| 195 | ++// |
| 196 | ++// Version |
| 197 | ++// |
| 198 | ++ |
| 199 | ++VS_VERSION_INFO VERSIONINFO |
| 200 | ++ FILEVERSION 2,2,0,0 |
| 201 | ++ PRODUCTVERSION 2,2,0,0 |
| 202 | ++ FILEFLAGSMASK 0x3fL |
| 203 | ++#ifdef _DEBUG |
| 204 | ++ FILEFLAGS 0x1L |
| 205 | ++#else |
| 206 | ++ FILEFLAGS 0x0L |
| 207 | ++#endif |
| 208 | ++ FILEOS 0x40004L |
| 209 | ++ FILETYPE 0x1L |
| 210 | ++ FILESUBTYPE 0x0L |
| 211 | ++BEGIN |
| 212 | ++ BLOCK "StringFileInfo" |
| 213 | ++ BEGIN |
| 214 | ++ BLOCK "040904b0" |
| 215 | ++ BEGIN |
| 216 | ++ VALUE "CompanyName", "Geoff Greer" |
| 217 | ++ VALUE "FileDescription", "The Silver Searcher" |
| 218 | ++ VALUE "FileVersion", "2.2.0.0" |
| 219 | ++ VALUE "InternalName", "ag.exe" |
| 220 | ++ VALUE "LegalCopyright", "Copyright 2011-2016 Geoff Greer" |
| 221 | ++ VALUE "OriginalFilename", "ag.exe" |
| 222 | ++ VALUE "ProductName", "The Silver Searcher" |
| 223 | ++ VALUE "ProductVersion", "2.2.0.0" |
| 224 | ++ END |
| 225 | ++ END |
| 226 | ++ BLOCK "VarFileInfo" |
| 227 | ++ BEGIN |
| 228 | ++ VALUE "Translation", 0x409, 1200 |
| 229 | ++ END |
| 230 | ++END |
| 231 | ++ |
| 232 | ++#endif // English (United States) resources |
| 233 | ++///////////////////////////////////////////////////////////////////////////// |
| 234 | ++ |
| 235 | ++ |
| 236 | ++ |
| 237 | ++#ifndef APSTUDIO_INVOKED |
| 238 | ++///////////////////////////////////////////////////////////////////////////// |
| 239 | ++// |
| 240 | ++// Generated from the TEXTINCLUDE 3 resource. |
| 241 | ++// |
| 242 | ++ |
| 243 | ++ |
| 244 | ++///////////////////////////////////////////////////////////////////////////// |
| 245 | ++#endif // not APSTUDIO_INVOKED |
| 246 | ++ |
| 247 | +diff --git a/src/win32/resource.h b/src/win32/resource.h |
| 248 | +new file mode 100644 |
| 249 | +index 0000000..2012d73 |
| 250 | +--- /dev/null |
| 251 | ++++ b/src/win32/resource.h |
| 252 | +@@ -0,0 +1,14 @@ |
| 253 | ++//{{NO_DEPENDENCIES}} |
| 254 | ++// Microsoft Visual C++ generated include file. |
| 255 | ++// Used by ag.rc |
| 256 | ++ |
| 257 | ++// Next default values for new objects |
| 258 | ++// |
| 259 | ++#ifdef APSTUDIO_INVOKED |
| 260 | ++#ifndef APSTUDIO_READONLY_SYMBOLS |
| 261 | ++#define _APS_NEXT_RESOURCE_VALUE 101 |
| 262 | ++#define _APS_NEXT_COMMAND_VALUE 40001 |
| 263 | ++#define _APS_NEXT_CONTROL_VALUE 1001 |
| 264 | ++#define _APS_NEXT_SYMED_VALUE 101 |
| 265 | ++#endif |
| 266 | ++#endif |
| 267 | +-- |
| 268 | +2.21.0 |
| 269 | + |
0 commit comments