mirror of
https://github.com/reactos/reactos.git
synced 2025-06-10 20:34:59 +00:00
[CONUTILS] In ConWrite(), emit an \r when a \n is encountered but not already preceded by \r.
And, don't emit \r\n when an \r alone is encountered. This fixes the problem of extra newlines appearing when redirecting "more" output to a file. CORE-14592
This commit is contained in:
parent
78b6e43d22
commit
b277cbdf22
1 changed files with 42 additions and 28 deletions
|
@ -158,36 +158,43 @@ ConWrite(
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find any newline character in the buffer,
|
* Find any newline character in the buffer,
|
||||||
* write the part BEFORE the newline, then write
|
* write the part BEFORE the newline, then emit
|
||||||
* a carriage-return + newline, and then write
|
* a carriage-return + newline sequence and finally
|
||||||
* the remaining part of the buffer.
|
* write the remaining part of the buffer.
|
||||||
*
|
*
|
||||||
* This fixes output in files and serial console.
|
* This fixes output in files and serial console.
|
||||||
*/
|
*/
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
/* Loop until we find a \r or \n character */
|
/* Loop until we find a newline character */
|
||||||
// FIXME: What about the pair \r\n ?
|
|
||||||
p = szStr;
|
p = szStr;
|
||||||
while (len > 0 && *(PWCHAR)p != L'\r' && *(PWCHAR)p != L'\n')
|
while (len > 0 && *(PWCHAR)p != L'\n')
|
||||||
{
|
{
|
||||||
/* Advance one character */
|
/* Advance one character */
|
||||||
p = (PVOID)((PWCHAR)p + 1);
|
p = (PVOID)((PWCHAR)p + 1);
|
||||||
len--;
|
--len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write everything up to \r or \n */
|
/* Write everything up to \n */
|
||||||
dwNumBytes = ((PWCHAR)p - (PWCHAR)szStr) * sizeof(WCHAR);
|
dwNumBytes = ((PWCHAR)p - (PWCHAR)szStr) * sizeof(WCHAR);
|
||||||
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
|
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
|
||||||
|
|
||||||
/* If we hit \r or \n ... */
|
/*
|
||||||
if (len > 0 && (*(PWCHAR)p == L'\r' || *(PWCHAR)p == L'\n'))
|
* If we hit a newline and the previous character is not a carriage-return,
|
||||||
|
* emit a carriage-return + newline sequence, otherwise just emit the newline.
|
||||||
|
*/
|
||||||
|
if (len > 0 && *(PWCHAR)p == L'\n')
|
||||||
{
|
{
|
||||||
/* ... send a carriage-return + newline sequence and skip \r or \n */
|
if (p == (PVOID)szStr || (p > (PVOID)szStr && *((PWCHAR)p - 1) != L'\r'))
|
||||||
WriteFile(Stream->hHandle, L"\r\n", 2 * sizeof(WCHAR), &dwNumBytes, NULL);
|
WriteFile(Stream->hHandle, L"\r\n", 2 * sizeof(WCHAR), &dwNumBytes, NULL);
|
||||||
szStr = (PVOID)((PWCHAR)p + 1);
|
else
|
||||||
len--;
|
WriteFile(Stream->hHandle, L"\n", sizeof(WCHAR), &dwNumBytes, NULL);
|
||||||
|
|
||||||
|
/* Skip \n */
|
||||||
|
p = (PVOID)((PWCHAR)p + 1);
|
||||||
|
--len;
|
||||||
}
|
}
|
||||||
|
szStr = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _UNICODE
|
#ifndef _UNICODE
|
||||||
|
@ -235,36 +242,43 @@ ConWrite(
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find any newline character in the buffer,
|
* Find any newline character in the buffer,
|
||||||
* write the part BEFORE the newline, then write
|
* write the part BEFORE the newline, then emit
|
||||||
* a carriage-return + newline, and then write
|
* a carriage-return + newline sequence and finally
|
||||||
* the remaining part of the buffer.
|
* write the remaining part of the buffer.
|
||||||
*
|
*
|
||||||
* This fixes output in files and serial console.
|
* This fixes output in files and serial console.
|
||||||
*/
|
*/
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
/* Loop until we find a \r or \n character */
|
/* Loop until we find a newline character */
|
||||||
// FIXME: What about the pair \r\n ?
|
|
||||||
p = szStr;
|
p = szStr;
|
||||||
while (len > 0 && *(PCHAR)p != '\r' && *(PCHAR)p != '\n')
|
while (len > 0 && *(PCHAR)p != '\n')
|
||||||
{
|
{
|
||||||
/* Advance one character */
|
/* Advance one character */
|
||||||
p = (PVOID)((PCHAR)p + 1);
|
p = (PVOID)((PCHAR)p + 1);
|
||||||
len--;
|
--len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write everything up to \r or \n */
|
/* Write everything up to \n */
|
||||||
dwNumBytes = ((PCHAR)p - (PCHAR)szStr) * sizeof(CHAR);
|
dwNumBytes = ((PCHAR)p - (PCHAR)szStr) * sizeof(CHAR);
|
||||||
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
|
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
|
||||||
|
|
||||||
/* If we hit \r or \n ... */
|
/*
|
||||||
if (len > 0 && (*(PCHAR)p == '\r' || *(PCHAR)p == '\n'))
|
* If we hit a newline and the previous character is not a carriage-return,
|
||||||
|
* emit a carriage-return + newline sequence, otherwise just emit the newline.
|
||||||
|
*/
|
||||||
|
if (len > 0 && *(PCHAR)p == '\n')
|
||||||
{
|
{
|
||||||
/* ... send a carriage-return + newline sequence and skip \r or \n */
|
if (p == (PVOID)szStr || (p > (PVOID)szStr && *((PCHAR)p - 1) != '\r'))
|
||||||
WriteFile(Stream->hHandle, "\r\n", 2, &dwNumBytes, NULL);
|
WriteFile(Stream->hHandle, "\r\n", 2, &dwNumBytes, NULL);
|
||||||
szStr = (PVOID)((PCHAR)p + 1);
|
else
|
||||||
len--;
|
WriteFile(Stream->hHandle, "\n", 1, &dwNumBytes, NULL);
|
||||||
|
|
||||||
|
/* Skip \n */
|
||||||
|
p = (PVOID)((PCHAR)p + 1);
|
||||||
|
--len;
|
||||||
}
|
}
|
||||||
|
szStr = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue