-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
0140-gcc-8.2.0-diagnostic-color.patch
68 lines (62 loc) · 2.2 KB
/
0140-gcc-8.2.0-diagnostic-color.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From af52a4883ae383b95ff9e027c7d1a883d02b738f Mon Sep 17 00:00:00 2001
From: Alexey Pavlov <alexpux@gmail.com>
Date: Sat, 4 Aug 2018 08:38:11 +0300
Subject: [PATCH] gcc: Enable diagnostic colors under mintty
---
gcc/diagnostic-color.cc | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/gcc/diagnostic-color.cc b/gcc/diagnostic-color.cc
index 640adfad558..5ea6979878a 100644
--- a/gcc/diagnostic-color.cc
+++ b/gcc/diagnostic-color.cc
@@ -23,6 +23,7 @@
#ifdef __MINGW32__
# include <windows.h>
+# include <winternl.h>
#endif
#include "color-macros.h"
@@ -211,9 +212,42 @@ should_colorize (void)
HANDLE h;
DWORD m;
+ bool ret = false;
h = GetStdHandle (STD_ERROR_HANDLE);
- return (h != INVALID_HANDLE_VALUE) && (h != NULL)
+ ret = (h != INVALID_HANDLE_VALUE) && (h != NULL)
&& GetConsoleMode (h, &m);
+ if (!ret){
+ HMODULE ntdll = GetModuleHandle ("ntdll.dll");
+ if (ntdll != INVALID_HANDLE_VALUE){
+
+ typedef NTSTATUS NTAPI func_NtQueryObject (HANDLE, OBJECT_INFORMATION_CLASS,
+ PVOID, ULONG, PULONG);
+ func_NtQueryObject *fNtQueryObject =
+ (func_NtQueryObject*) GetProcAddress (ntdll, "NtQueryObject");
+ if (fNtQueryObject){
+
+ ULONG s = 0xffff * sizeof (WCHAR);
+ OBJECT_NAME_INFORMATION *oni = (OBJECT_NAME_INFORMATION*) xmalloc (s);
+ ULONG len;
+ /* mintty uses a named pipe like "ptyNNNN-to-master". */
+ if (!fNtQueryObject (h, ObjectNameInformation, oni, s, &len))
+ {
+ wchar_t namedPipe[] = L"\\Device\\NamedPipe\\";
+ size_t l1 = sizeof (namedPipe) / 2 - 1;
+ wchar_t toMaster[] = L"-to-master";
+ size_t l2 = sizeof (toMaster) / 2 - 1;
+ USHORT name_length = oni->Name.Length / 2;
+ if (name_length > l1 + l2 &&
+ !memcmp (oni->Name.Buffer, namedPipe, l1 * 2) &&
+ !memcmp (oni->Name.Buffer + (name_length - l2), toMaster, l2 * 2))
+ ret = true;
+ }
+
+ free (oni);
+ }
+ }
+ }
+ return ret;
#else
char const *t = getenv ("TERM");
/* emacs M-x shell sets TERM="dumb". */
--
2.35.3