X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fformatter.hpp;h=55ed28abec1501d19c909dfe0be544b983941319;hb=refs%2Fheads%2Fglx-copy-sub-buffer;hp=10661e3b14ebb1b1df1b75f5b92f6e8e082fdbab;hpb=ee659c84695e9f94b1f6a5f8be203dc0012ca685;p=apitrace diff --git a/common/formatter.hpp b/common/formatter.hpp index 10661e3..55ed28a 100644 --- a/common/formatter.hpp +++ b/common/formatter.hpp @@ -33,6 +33,39 @@ #include +#ifdef _WIN32 +#include + +#ifndef COMMON_LVB_LEADING_BYTE +#define COMMON_LVB_LEADING_BYTE 0x0100 +#endif + +#ifndef COMMON_LVB_TRAILING_BYTE +#define COMMON_LVB_TRAILING_BYTE 0x0200 +#endif + +#ifndef COMMON_LVB_GRID_HORIZONTAL +#define COMMON_LVB_GRID_HORIZONTAL 0x0400 +#endif + +#ifndef COMMON_LVB_GRID_LVERTICAL +#define COMMON_LVB_GRID_LVERTICAL 0x0800 +#endif + +#ifndef COMMON_LVB_GRID_RVERTICAL +#define COMMON_LVB_GRID_RVERTICAL 0x1000 +#endif + +#ifndef COMMON_LVB_REVERSE_VIDEO +#define COMMON_LVB_REVERSE_VIDEO 0x4000 +#endif + +#ifndef COMMON_LVB_UNDERSCORE +#define COMMON_LVB_UNDERSCORE 0x8000 +#endif + +#endif /* _WIN32 */ + namespace formatter { @@ -113,38 +146,6 @@ inline std::ostream& operator<<(std::ostream& os, const Attribute *attr) { #ifdef _WIN32 -#include - - -#ifndef COMMON_LVB_LEADING_BYTE -#define COMMON_LVB_LEADING_BYTE 0x0100 -#endif - -#ifndef COMMON_LVB_TRAILING_BYTE -#define COMMON_LVB_TRAILING_BYTE 0x0200 -#endif - -#ifndef COMMON_LVB_GRID_HORIZONTAL -#define COMMON_LVB_GRID_HORIZONTAL 0x0400 -#endif - -#ifndef COMMON_LVB_GRID_LVERTICAL -#define COMMON_LVB_GRID_LVERTICAL 0x0800 -#endif - -#ifndef COMMON_LVB_GRID_RVERTICAL -#define COMMON_LVB_GRID_RVERTICAL 0x1000 -#endif - -#ifndef COMMON_LVB_REVERSE_VIDEO -#define COMMON_LVB_REVERSE_VIDEO 0x4000 -#endif - -#ifndef COMMON_LVB_UNDERSCORE -#define COMMON_LVB_UNDERSCORE 0x8000 -#endif - - class WindowsAttribute : public Attribute { protected: WORD wAttributes; @@ -152,9 +153,9 @@ public: WindowsAttribute(WORD _wAttributes) : wAttributes(_wAttributes) {} void apply(std::ostream& os) const { DWORD nStdHandleOutput; - if (os == std::cout) { + if (&os == &std::cout) { nStdHandleOutput = STD_OUTPUT_HANDLE; - } else if (os == std::cerr) { + } else if (&os == &std::cerr) { nStdHandleOutput = STD_ERROR_HANDLE; } else { return; @@ -189,12 +190,25 @@ public: } }; -#endif + +#endif /* _WIN32 */ inline Formatter *defaultFormatter(bool color = true) { if (color) { #ifdef _WIN32 + // http://wiki.winehq.org/DeveloperFaq#detect-wine + static HMODULE hNtDll = NULL; + static bool bWine = false; + if (!hNtDll) { + hNtDll = LoadLibraryA("ntdll"); + if (hNtDll) { + bWine = GetProcAddress(hNtDll, "wine_get_version") != NULL; + } + } + if (bWine) { + return new AnsiFormatter; + } return new WindowsFormatter; #else return new AnsiFormatter;