Write error messages to stderr by default

Disabled if -O is used or if -NOTIFYHWND is valid and returns 0 to QUERYHOST:QH_ENABLESTDERR



git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6798 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2016-11-22 21:17:00 +00:00
parent 9841c101cf
commit 04d6fe9367
6 changed files with 51 additions and 23 deletions

View file

@ -2,13 +2,17 @@
\H{v3.01} 3.01
Released on ? ?th, 201?
Released on December ?th, 2016
\S1{v3.01-cl} Changelog
\S2{} Major Changes
\b Error messages are now written to stderr by default
\S2{} Minor Changes
\b SetCtlColors now supports Windows color constants
\b \R{setctlcolors}{SetCtlColors} now supports Windows color constant values
\b Fixed buffer size bug in winchar.cpp (\W{http://sf.net/p/nsis/patches/271}{patch #271})

View file

@ -130,7 +130,7 @@ Sets the text and background color of a static control, edit control, button or
\c GetDlgItem $0 $1 1006
\c SetCtlColors $0 0xFF0000 0x00FF00 ; Red on Green
\c GetDlgItem $0 $1 1022
\c SetCtlColors $0 SYSCLR:23 SYSCLR:24
\c SetCtlColors $0 SYSCLR:23 SYSCLR:24 ; COLOR_INFOTEXT on COLOR_INFOBK
\c FunctionEnd
\NsisWarnBlockContainerBegin

View file

@ -82,10 +82,11 @@ namespace MakensisAPI {
};
#ifdef _WIN32
enum sndmsg_e {
QUERYHOST = WM_APP // QUERYHOST_e in wParam
QUERYHOST = WM_APP // [0x03000000] QUERYHOST_e in wParam. MUST return 0 for unknown QUERYHOST_e values!
};
enum QUERYHOST_e {
QH_OUTPUTCHARSET = 1 // return (wincodepage+1) or 0 for default (This encoding is used by stdout and the notify messages)
QH_OUTPUTCHARSET = 1, // [0x03000000] return (wincodepage+1) or 0 for default (This encoding is used by stdout, stderr and the notify messages)
QH_ENABLESTDERR // [0x03001000] return 1 to output error messages to stderr or 0 to output error messages to stdout
};
#endif
}

View file

@ -38,12 +38,12 @@ using namespace std;
bool g_dopause=false, g_warnaserror=false;
int g_display_errors=1;
FILE *g_output;
FILE *g_output, *g_errout;
NStreamEncoding g_outputenc;
#ifdef _WIN32
UINT g_wincon_orgoutcp;
#ifdef _UNICODE
WINSIO_OSDATA g_osdata_stdout;
WINSIO_OSDATA g_osdata_stdout, g_osdata_stderr;
#endif
#endif
const TCHAR *g_argv0=0;
@ -71,7 +71,8 @@ static void myatexit()
{
dopause();
ResetPrintColor();
if (g_output != stdout && g_output) fclose(g_output);
if (g_output != stdout && g_output) fclose(g_output), g_output = 0;
if (g_errout != stderr && g_errout) fclose(g_errout), g_errout = 0;
#ifdef _WIN32
SetConsoleOutputCP(g_wincon_orgoutcp);
#endif
@ -108,7 +109,11 @@ static DWORD WINAPI sigint_event_msg_handler(LPVOID ThreadParam)
return 0;
}
#endif
static UINT_PTR QueryHost(HWND hHost, UINT_PTR wp, UINT_PTR lp=0, UINT_PTR def=0) { return hHost ? SendMessage(hHost, MakensisAPI::QUERYHOST, wp, lp) : def; }
#else //! _WIN32
static inline UINT_PTR QueryHost(HWND hHost, UINT_PTR wp, UINT_PTR lp=0, UINT_PTR def=0) { return def; }
#endif //~ _WIN32
static void init_signals(HWND notify_hwnd)
{
@ -291,10 +296,11 @@ static inline int makensismain(int argc, TCHAR **argv)
assert(sizeof(WINWCHAR) == sizeof(WCHAR)); // Not really required but if WCHAR changes we need to know
g_argv0=argv[0];
g_output=stdout, g_errout=stderr;
if (!NSISRT_Initialize())
{
_ftprintf(stdout,_T("NSISRT_Initialize failed!\n"));
_ftprintf(stderr,_T("NSISRT_Initialize failed!\n"));
return 1;
}
@ -302,11 +308,10 @@ static inline int makensismain(int argc, TCHAR **argv)
const TCHAR*stdoutredirname=0;
NStreamEncoding inputenc, &outputenc = g_outputenc;
int argpos=0;
bool in_files=false;
bool do_cd=true;
bool do_cd=true, noconfig=false;
bool no_logo=true;
bool initialparsefail=false;
bool noconfig=false;
bool initialparsefail=false, in_files=false;
bool oneoutputstream=false;
signed char pponly=0;
#ifdef _WIN32
signed char outputbom=1;
@ -391,17 +396,23 @@ static inline int makensismain(int argc, TCHAR **argv)
FILE*stdoutredir=stdout;
if (stdoutredirname) stdoutredir=my_fopen(stdoutredirname,"w");
g_output=stdoutredir;
if (!g_output) g_output=stdout;
if (!g_output)
g_output=stdout; // We could not open stdoutredirname, fall back to stdout
else if (stdoutredirname)
oneoutputstream=true; // -O used, put all output in the same file
if (oneoutputstream || !(1 & QueryHost(hostnotifyhandle,MakensisAPI::QH_ENABLESTDERR,0,1)))
g_errout=g_output;
#if defined(_WIN32) && defined(_UNICODE)
if (hostnotifyhandle)
{
// The host can override the output format if they want to
LPARAM lp=MAKELONG(outputenc.GetCodepage(),outputbom);
LRESULT mr=SendMessage(hostnotifyhandle,MakensisAPI::QUERYHOST,MakensisAPI::QH_OUTPUTCHARSET,lp);
LRESULT mr=QueryHost(hostnotifyhandle,MakensisAPI::QH_OUTPUTCHARSET,lp);
if (mr) outputenc.SetCodepage((WORD)(--mr)), outputbom = -1;
}
if (!WinStdIO_OStreamInit(g_osdata_stdout,g_output,outputenc.GetCodepage(),outputbom))
if (( !WinStdIO_OStreamInit(g_osdata_stdout,g_output,outputenc.GetCodepage(),outputbom))
|| (g_errout != g_output && !WinStdIO_OStreamInit(g_osdata_stderr,g_errout,outputenc.GetCodepage(),outputbom)))
{
assert(!"StdIO init failed");
return 1;

View file

@ -56,7 +56,7 @@ namespace Apple { // defines struct section
using namespace std;
extern int g_display_errors;
extern FILE *g_output;
extern FILE *g_output, *g_errout;
double my_wtof(const wchar_t *str)
{
@ -1073,17 +1073,23 @@ end:
strm.Detach();
return retval;
}
static WINSIO_OSDATA*WinStdIO_GetNativeStreamData(FILE*strm)
{
extern WINSIO_OSDATA g_osdata_stdout, g_osdata_stderr;
if (g_output == strm) return &g_osdata_stdout;
return g_errout == strm ? &g_osdata_stderr : NULL;
}
int WINAPI WinStdIO_vfwprintf(FILE*strm, const wchar_t*Fmt, va_list val)
{
if (g_output == strm && Fmt)
WINSIO_OSDATA*pOSD;
if (Fmt && (pOSD = WinStdIO_GetNativeStreamData(strm)))
{
extern WINSIO_OSDATA g_osdata_stdout;
ExpandoString<wchar_t, NSIS_MAX_STRLEN> buf;
errno = ENOMEM;
const size_t cchfmt = buf.StrFmt(Fmt, val, false);
UINT cch = (UINT) cchfmt;
assert(sizeof(size_t) <= 4 || cchfmt == cch);
if (cch && !WinStdIO_OStreamWrite(g_osdata_stdout, buf, cch))
if (cch && !WinStdIO_OStreamWrite(*pOSD, buf, cch))
{
cch = 0, errno = EIO;
}
@ -1112,7 +1118,9 @@ int WinStdIO_wprintf(const wchar_t*Fmt, ...)
void PrintColorFmtMsg(unsigned int type, const TCHAR *fmtstr, va_list args)
{
#ifdef _WIN32
const HANDLE hWin32Con = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD conmode;
HANDLE hWin32Con = GetStdHandle(STD_OUTPUT_HANDLE);
if (!GetConsoleMode(hWin32Con, &conmode)) hWin32Con = GetStdHandle(STD_ERROR_HANDLE);
static INT32 contxtattrbak = -1;
WORD txtattr = 0;
if (contxtattrbak < 0)

View file

@ -161,7 +161,11 @@ inline void PrintColorFmtMsg_ERR(const TCHAR *fmtstr, ...)
{
va_list val;
va_start(val,fmtstr);
PrintColorFmtMsg(2, fmtstr, val);
PrintColorFmtMsg_WARN(_T("")); // flush g_output
SetPrintColorERR();
extern FILE *g_errout;
_vftprintf(g_errout, fmtstr, val), fflush(g_errout);
ResetPrintColor();
va_end(val);
}