Unify g_output and console initialization
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6802 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
37c2cce029
commit
27ed0e502b
7 changed files with 39 additions and 17 deletions
|
@ -77,6 +77,7 @@ int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
|
|||
NSIS_ENTRYPOINT_TMAIN
|
||||
int _tmain(int argc, TCHAR* argv[])
|
||||
{
|
||||
if (!NSISRT_Initialize()) return 1;
|
||||
|
||||
// Parse the command line
|
||||
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "../util.h" // HACKHACK: for NSISRT_DEFINEGLOBALS
|
||||
|
||||
using namespace std; // for std::min
|
||||
|
||||
NSISRT_DEFINEGLOBALS(); // HACKHACK: This really belongs in textrunner.cpp?
|
||||
|
||||
void quit() {
|
||||
extern FILE *g_errout;
|
||||
_ftprintf(g_errout, _T("MMap quit\n"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#include <cppunit/CompilerOutputter.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include "../util.h" // for NSISRT_*
|
||||
|
||||
NSISRT_DEFINEGLOBALS();
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (!NSISRT_Initialize()) return 1;
|
||||
|
||||
// Get the top level suite from the registry
|
||||
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ class WinCharTest : public CppUnit::TestFixture {
|
|||
|
||||
public:
|
||||
void setUp() {
|
||||
NSISRT_Initialize(); // HACKHACK: This really belongs in textrunner.cpp?
|
||||
}
|
||||
|
||||
void testFromTchar() {
|
||||
|
|
|
@ -81,11 +81,11 @@ static UINT read_line_helper(NStreamLineReader&lr, TCHAR*buf, UINT cch)
|
|||
static bool LookupWinSysColorId(const TCHAR*Str, UINT&Clr)
|
||||
{
|
||||
static const struct { const TCHAR*Name; UINT Id; } map[] = { // Note: This list is incomplete.
|
||||
{ TEXT("WINDOW"), 5 }, { TEXT("WINDOWTEXT"), 8 },
|
||||
{ TEXT("3DFACE"), 15 }, { TEXT("BTNTEXT"), 18 }, // "Three-dimensional display elements and dialog box"
|
||||
{ TEXT("HIGHLIGHT"), 13 }, { TEXT("HIGHLIGHTTEXT"), 14 }, // "Item(s) selected in a control"
|
||||
{ TEXT("GRAYTEXT"), 17 }, // "Grayed (disabled) text"
|
||||
{ TEXT("HOTLIGHT"), 26 }, // "Color for a hyperlink or hot-tracked item" (Win98+)
|
||||
{ _T("WINDOW"), 5 }, { _T("WINDOWTEXT"), 8 },
|
||||
{ _T("3DFACE"), 15 }, { _T("BTNTEXT"), 18 }, // "Three-dimensional display elements and dialog box"
|
||||
{ _T("HIGHLIGHT"), 13 }, { _T("HIGHLIGHTTEXT"), 14 }, // "Item(s) selected in a control"
|
||||
{ _T("GRAYTEXT"), 17 }, // "Grayed (disabled) text"
|
||||
{ _T("HOTLIGHT"), 26 }, // "Color for a hyperlink or hot-tracked item" (Win98+)
|
||||
};
|
||||
for (UINT i = 0; i < COUNTOF(map); ++i)
|
||||
if (!_tcsicmp(map[i].Name, Str)) return (Clr = map[i].Id, true);
|
||||
|
@ -3235,7 +3235,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
case 1: comp=4; break;
|
||||
case 2: comp=5, validparams=!!*(define=line.gettoken_str(2)); break;
|
||||
case 3: cmpv=line.gettoken_int(3,&validparams); break;
|
||||
default: comp=-1;
|
||||
default: forceutf8=comp=-1;
|
||||
}
|
||||
if (!validparams || comp == -1) PRINTHELP()
|
||||
tstring compile;
|
||||
|
|
|
@ -203,7 +203,7 @@ static char g_nrt_iconv_narrowlocbuf[50], *g_nrt_iconv_narrowloc = 0;
|
|||
#ifdef HAVE_LANGINFO_H // BUGBUG: scons needs to check for HAVE_LANGINFO_H and HAVE_NL_LANGINFO support?
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
bool NSISRT_Initialize()
|
||||
bool NSISRT_Initialize() // Init function for POSIX
|
||||
{
|
||||
iconvdescriptor id;
|
||||
g_nrt_iconv_narrowloc = const_cast<char*>(""); // Use "" and not "char", "char" is a GNU extension?
|
||||
|
@ -1019,7 +1019,13 @@ bool GetFileSize64(HANDLE hFile, ULARGE_INTEGER &uli)
|
|||
uli.LowPart = GetFileSize(hFile, &uli.HighPart);
|
||||
return INVALID_FILE_SIZE != uli.LowPart || !GetLastError();
|
||||
}
|
||||
#endif
|
||||
static HANDLE NSISRT_GetConsoleScreenHandle()
|
||||
{
|
||||
DWORD cm;
|
||||
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
return GetConsoleMode(hCon, &cm) ? hCon : GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
#endif //~ _WIN32
|
||||
#if defined(_WIN32) && defined(_UNICODE) && defined(MAKENSIS)
|
||||
#include <io.h> // for _get_osfhandle
|
||||
bool WINAPI WinStdIO_OStreamInit(WINSIO_OSDATA&osd, FILE*strm, WORD cp, int bom)
|
||||
|
@ -1113,6 +1119,22 @@ int WinStdIO_wprintf(const wchar_t*Fmt, ...)
|
|||
va_end(val);
|
||||
return rv;
|
||||
}
|
||||
static HANDLE NSISRT_FastGetConsoleScreenHandle()
|
||||
{
|
||||
extern WINSIO_OSDATA g_osdata_stdout, g_osdata_stderr;
|
||||
return WinStdIO_IsConsole(g_osdata_stdout) ? g_osdata_stdout.hNative : g_osdata_stderr.hNative;
|
||||
}
|
||||
bool NSISRT_Initialize() // Init function for MakeNSIS Win32
|
||||
{
|
||||
static bool inited = false;
|
||||
if (inited) return inited;
|
||||
extern WINSIO_OSDATA g_osdata_stdout, g_osdata_stderr;
|
||||
g_osdata_stderr.mode = g_osdata_stdout.mode = 0, g_osdata_stderr.hNative = g_osdata_stdout.hNative = 0;
|
||||
return (inited = true);
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
#define NSISRT_FastGetConsoleScreenHandle NSISRT_GetConsoleScreenHandle
|
||||
bool NSISRT_Initialize() { return true; } // Init function for non-MakeNSIS Win32 (NSISRT_DEFINEGLOBALS sets g_output and g_errout)
|
||||
#endif
|
||||
|
||||
void PrintColorFmtErrMsg(const TCHAR *fmtstr, va_list args)
|
||||
|
@ -1126,9 +1148,7 @@ void PrintColorFmtErrMsg(const TCHAR *fmtstr, va_list args)
|
|||
void PrintColorFmtMsg(unsigned int type, const TCHAR *fmtstr, va_list args)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD conmode;
|
||||
HANDLE hWin32Con = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (!GetConsoleMode(hWin32Con, &conmode)) hWin32Con = GetStdHandle(STD_ERROR_HANDLE);
|
||||
HANDLE hWin32Con = NSISRT_FastGetConsoleScreenHandle();
|
||||
static INT32 contxtattrbak = -1;
|
||||
WORD txtattr = 0;
|
||||
if (contxtattrbak < 0)
|
||||
|
|
|
@ -168,6 +168,7 @@ inline void PrintColorFmtMsg_ERR(const TCHAR *fmtstr, ...)
|
|||
}
|
||||
|
||||
|
||||
bool NSISRT_Initialize();
|
||||
#ifndef _WIN32
|
||||
// iconv const inconsistency workaround by Alexandre Oliva
|
||||
template <typename T>
|
||||
|
@ -235,7 +236,6 @@ BOOL IsValidCodePage(UINT CodePage);
|
|||
#else
|
||||
#define CharNext CharNextA
|
||||
#endif
|
||||
bool NSISRT_Initialize();
|
||||
#define NSISRT_free(p) ( free((void*)(p)) )
|
||||
wchar_t* NSISRT_mbtowc(const char *Str);
|
||||
char* NSISRT_wctomb(const wchar_t *Str);
|
||||
|
@ -262,8 +262,6 @@ int my_open(const TCHAR *pathname, int flags);
|
|||
|
||||
#else // _WIN32
|
||||
|
||||
#define NSISRT_Initialize() (true)
|
||||
|
||||
#define my_convert(x) (x)
|
||||
#define my_convert_free(x)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue