Skip to content

Commit

Permalink
LF to CRLF translation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
randomascii committed Aug 29, 2020
1 parent 90c2a35 commit 0ad5bad
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions UIforETW/ChildProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down

0 comments on commit 0ad5bad

Please sign in to comment.