From be72d98a837cce70f3a30c58f62558c6c60ca9d7 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Sat, 17 Jan 2009 19:58:18 +0000 Subject: [PATCH] Convert all line-endings to LF first in StringOut before passing the strings to printf and OutputDebugStringA. Both functions treat the string as text and convert the line-endings themselves to CRLF. If you already give them a CRLF line-ending, it'll be converted to CRCRLF.. By unifying the line-endings in StringOut, it is also possible now to pass both LF and CRLF to the function. This should fix the empty lines in the BuildBot log. Thanks to Christoph for the help! svn path=/trunk/; revision=38840 --- rostests/rosautotest/tools.c | 43 +++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/rostests/rosautotest/tools.c b/rostests/rosautotest/tools.c index 763c817c7f4..adb7b730d70 100644 --- a/rostests/rosautotest/tools.c +++ b/rostests/rosautotest/tools.c @@ -38,13 +38,15 @@ EscapeString(PCHAR Output, PCHAR Input) *Output++ = HexCharacters[((UCHAR)*Input >> 4) % 16]; *Output++ = HexCharacters[(UCHAR)*Input % 16]; } - } while(*++Input); + } + while(*++Input); *Output = 0; } /** * Outputs a string through the standard output and the debug output. + * The string may have LF or CRLF line endings. * * @param String * The string to output @@ -52,6 +54,41 @@ EscapeString(PCHAR Output, PCHAR Input) VOID StringOut(PCHAR String) { - printf(String); - OutputDebugStringA(String); + PCHAR NewString; + PCHAR pNewString; + size_t Length; + + /* The piped output of the tests may use CRLF line endings, so convert them to LF. + As both printf and OutputDebugStringA operate in text mode, the line-endings will be properly converted again later. */ + Length = strlen(String); + NewString = HeapAlloc(hProcessHeap, 0, Length + 1); + pNewString = NewString; + + do + { + /* If this is a CRLF line-ending, only copy a \n to the new string and skip the next character */ + if(*String == '\r' && *(String + 1) == '\n') + { + *pNewString = '\n'; + ++String; + } + else + { + /* Otherwise copy the string */ + *pNewString = *String; + } + + ++pNewString; + } + while(*++String); + + /* Null-terminate it */ + *pNewString = 0; + + /* Output it */ + printf(NewString); + OutputDebugStringA(NewString); + + /* Cleanup */ + HeapFree(hProcessHeap, 0, NewString); }