From 0ad5badc39bfad5593bf0643ace021ce72d0de1d Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Sat, 29 Aug 2020 11:25:25 -0700 Subject: [PATCH] LF to CRLF translation Translate LF-only endings to CRLF endings. This is much better than having processing scripts such as IdentifyChromeProcesses.py trying to print the \r characters that Windows so often requires. --- UIforETW/ChildProcess.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/UIforETW/ChildProcess.cpp b/UIforETW/ChildProcess.cpp index 0c45184f..29befdae 100644 --- a/UIforETW/ChildProcess.cpp +++ b/UIforETW/ChildProcess.cpp @@ -100,10 +100,25 @@ DWORD ChildProcess::ListenerThread() #ifdef OUTPUT_DEBUG_STRINGS OutputDebugStringA(buffer); #endif + // Convert from LF to CRLF line endings. + char buffer2[sizeof(buffer) * 2]; + bool lastWasCR = false; + for (int in = 0, out = 0; /**/; /**/) + { + char c = buffer[in++]; + // Edit controls on older versions of Windows (and by default on newer + // versions) need \r\n line endings, \n is not sufficient. + if (c == '\n' && !lastWasCR) + buffer2[out++] = '\r'; + buffer2[out++] = c; + lastWasCR = c == '\r'; + if (!c) + break; + } #ifdef _UNICODE - processOutput_ += AnsiToUnicode(buffer); + processOutput_ += AnsiToUnicode(buffer2); #else - processOutput_ += buffer; + processOutput += buffer2; #endif } SetEvent(hOutputAvailable_);