ReactOS 0.4.16-dev-295-g4aee028
outstream.c File Reference

Console I/O utility API – Output. More...

#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <winuser.h>
#include <wincon.h>
#include <strsafe.h>
#include <pseh/pseh2.h>
#include "conutils.h"
#include "stream.h"
#include "stream_private.h"
Include dependency graph for outstream.c:

Go to the source code of this file.

Macros

#define UNICODE
 
#define _UNICODE
 
#define CON_RC_STRING_MAX_SIZE   4096
 

Functions

ConStreamWrite

Writes a counted string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the counted string to write.
[in]lenLength of the string pointed by szStr, specified in number of characters.
Returns
Numbers of characters successfully written to Stream.
INT ConStreamWrite (IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
 
ConPuts

Writes a NULL-terminated string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the NULL-terminated string to write.
Returns
Numbers of characters successfully written to Stream.
Remarks
Contrary to the CRT puts() function, ConPuts() does not append a terminating new-line character. In this way it behaves more like the CRT fputs() function.
INT ConPuts (IN PCON_STREAM Stream, IN PCWSTR szStr)
 
ConPrintfV

Formats and writes a NULL-terminated string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the NULL-terminated format string, that follows the same specifications as the szStr format string in ConPrintf().
[in]argsParameter describing a variable number of arguments, initialized with va_start(), that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), printf(), vprintf()
INT ConPrintfV (IN PCON_STREAM Stream, IN PCWSTR szStr, IN va_list args)
 
ConPrintf

Formats and writes a NULL-terminated string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the NULL-terminated format string, that follows the same specifications as the format string in printf(). This string can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.
[in]...Additional arguments that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintfV(), printf(), vprintf()
INT __cdecl ConPrintf (IN PCON_STREAM Stream, IN PCWSTR szStr,...)
 
ConResPutsEx

Writes a string resource to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]uIDThe identifier of the string to be written.
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
Returns
Numbers of characters successfully written to Stream.
Remarks
Similarly to ConPuts(), no terminating new-line character is appended.
See also
ConPuts(), ConResPuts()
INT ConResPutsEx (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId)
 
ConResPuts

Writes a string resource contained in the current application to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]uIDThe identifier of the string to be written.
Returns
Numbers of characters successfully written to Stream.
Remarks
Similarly to ConPuts(), no terminating new-line character is appended.
See also
ConPuts(), ConResPutsEx()
INT ConResPuts (IN PCON_STREAM Stream, IN UINT uID)
 
ConResPrintfExV

Formats and writes a string resource to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]argsParameter describing a variable number of arguments, initialized with va_start(), that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfEx(), ConResPrintfV(), ConResPrintf()
INT ConResPrintfExV (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, IN va_list args)
 
ConResPrintfV

Formats and writes a string resource contained in the current application to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]argsParameter describing a variable number of arguments, initialized with va_start(), that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfExV(), ConResPrintfEx(), ConResPrintf()
INT ConResPrintfV (IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
 
ConResPrintfEx

Formats and writes a string resource to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]...Additional arguments that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfExV(), ConResPrintfV(), ConResPrintf()
INT __cdecl ConResPrintfEx (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId,...)
 
ConResPrintf

Formats and writes a string resource contained in the current application to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]...Additional arguments that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfExV(), ConResPrintfEx(), ConResPrintfV()
INT __cdecl ConResPrintf (IN PCON_STREAM Stream, IN UINT uID,...)
 
ConMsgPuts

Writes a message string to a stream without formatting. The function requires a message definition as input. The message definition can come from a buffer passed to the function. It can come from a message table resource in an already-loaded module, or the caller can ask the function to search the system's message table resource(s) for the message definition. Please refer to the Win32 FormatMessage() function for more details.

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, and how to interpret the lpSource parameter. See FormatMessage() for more details. The FORMAT_MESSAGE_ALLOCATE_BUFFER and FORMAT_MESSAGE_ARGUMENT_ARRAY flags are always ignored. The function implicitly uses the FORMAT_MESSAGE_IGNORE_INSERTS flag to implement its behaviour.
[in]lpSourceThe location of the message definition. The type of this parameter depends upon the settings in the dwFlags parameter.
[in]dwMessageIdThe message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]dwLanguageIdThe language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
Returns
Numbers of characters successfully written to Stream.
Remarks
Similarly to ConPuts(), no terminating new-line character is appended.
See also
ConPuts(), ConResPuts() and associated functions, FormatMessage() (on MSDN)
INT ConMsgPuts (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
 
ConMsgPrintf2V

Formats and writes a message string to a stream.

Remarks
For internal use only.
See also
ConMsgPrintfV()
INT ConMsgPrintf2V (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list args)
 
ConMsgPrintfV

Formats and writes a message string to a stream. The function requires a message definition as input. The message definition can come from a buffer passed to the function. It can come from a message table resource in an already-loaded module, or the caller can ask the function to search the system's message table resource(s) for the message definition. Please refer to the Win32 FormatMessage() function for more details.

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, and how to interpret the lpSource parameter. See FormatMessage() for more details. The FORMAT_MESSAGE_ALLOCATE_BUFFER flag is always ignored.
[in]lpSourceThe location of the message definition. The type of this parameter depends upon the settings in the dwFlags parameter.
[in]dwMessageIdThe message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]dwLanguageIdThe language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]ArgumentsOptional pointer to an array of values describing a variable number of arguments, depending on the message string. Each argument is used to replace an insert sequence in the message string. By default, the Arguments parameter is of type va_list*, initialized with va_start(). The state of the va_list argument is undefined upon return from the function. To use the va_list again, destroy the variable argument list pointer using va_end() and reinitialize it with va_start(). If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values. Each insert must have a corresponding element in the array.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT ConMsgPrintfV (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
 
ConMsgPrintf

Formats and writes a message string to a stream. The function requires a message definition as input. The message definition can come from a buffer passed to the function. It can come from a message table resource in an already-loaded module, or the caller can ask the function to search the system's message table resource(s) for the message definition. Please refer to the Win32 FormatMessage() function for more details.

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, and how to interpret the lpSource parameter. See FormatMessage() for more details. The FORMAT_MESSAGE_ALLOCATE_BUFFER and FORMAT_MESSAGE_ARGUMENT_ARRAY flags are always ignored.
[in]lpSourceThe location of the message definition. The type of this parameter depends upon the settings in the dwFlags parameter.
[in]dwMessageIdThe message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]dwLanguageIdThe language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]...Additional arguments that can be expected by the function, depending on the message string. Each argument is used to replace an insert sequence in the message string.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintfV(), FormatMessage() (on MSDN)
INT __cdecl ConMsgPrintf (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId,...)
 
ConResMsgPrintfExV

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_ARGUMENT_ARRAY, FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]ArgumentsOptional pointer to an array of values describing a variable number of arguments, depending on the message string. Each argument is used to replace an insert sequence in the message string. By default, the Arguments parameter is of type va_list*, initialized with va_start(). The state of the va_list argument is undefined upon return from the function. To use the va_list again, destroy the variable argument list pointer using va_end() and reinitialize it with va_start(). If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values. Each insert must have a corresponding element in the array.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT ConResMsgPrintfExV (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId, IN va_list *Arguments OPTIONAL)
 
ConResMsgPrintfV

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_ARGUMENT_ARRAY, FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]ArgumentsOptional pointer to an array of values describing a variable number of arguments, depending on the message string. Each argument is used to replace an insert sequence in the message string. By default, the Arguments parameter is of type va_list*, initialized with va_start(). The state of the va_list argument is undefined upon return from the function. To use the va_list again, destroy the variable argument list pointer using va_end() and reinitialize it with va_start(). If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values. Each insert must have a corresponding element in the array.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT ConResMsgPrintfV (IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID, IN va_list *Arguments OPTIONAL)
 
ConResMsgPrintfEx

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]...Additional arguments that can be expected by the function, depending on the message string. Each argument is used to replace an insert sequence in the message string.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT __cdecl ConResMsgPrintfEx (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId,...)
 
ConResMsgPrintf

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]...Additional arguments that can be expected by the function, depending on the message string. Each argument is used to replace an insert sequence in the message string.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT __cdecl ConResMsgPrintf (IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID,...)
 
VOID ConClearLine (IN PCON_STREAM Stream)
 

ConWrite

Writes a counted string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the counted string to write.
[in]lenLength of the string pointed by szStr, specified in number of characters.
Returns
Numbers of characters successfully written to Stream.
Note
This function is used as an internal function. Use the ConStreamWrite() function instead.
Remarks
Should be called with the stream locked.
#define CON_STREAM_WRITE_CALL(Stream, Str, Len)    (Stream)->WriteFunc((Stream), (Str), (Len))
 
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
 
#define CON_STREAM_WRITE(Stream, Str, Len)
 
INT __stdcall ConWrite (IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
 

Detailed Description

Console I/O utility API – Output.

Definition in file outstream.c.

Macro Definition Documentation

◆ _UNICODE

#define _UNICODE

Definition at line 28 of file outstream.c.

◆ CON_RC_STRING_MAX_SIZE

#define CON_RC_STRING_MAX_SIZE   4096

Definition at line 56 of file outstream.c.

◆ CON_STREAM_WRITE

#define CON_STREAM_WRITE (   Stream,
  Str,
  Len 
)
Value:
do { \
EnterCriticalSection(&(Stream)->Lock); \
CON_STREAM_WRITE_CALL((Stream), (Str), (Len)); \
LeaveCriticalSection(&(Stream)->Lock); \
} while(0)
#define Len
Definition: deflate.h:82
static IStream Stream
Definition: htmldoc.c:1115
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

Definition at line 360 of file outstream.c.

◆ CON_STREAM_WRITE2

#define CON_STREAM_WRITE2 (   Stream,
  Str,
  Len,
  RetLen 
)
Value:
do { \
EnterCriticalSection(&(Stream)->Lock); \
(RetLen) = CON_STREAM_WRITE_CALL((Stream), (Str), (Len)); \
LeaveCriticalSection(&(Stream)->Lock); \
} while(0)
#define CON_STREAM_WRITE_CALL(Stream, Str, Len)
Definition: outstream.c:347

Definition at line 353 of file outstream.c.

◆ CON_STREAM_WRITE_CALL

#define CON_STREAM_WRITE_CALL (   Stream,
  Str,
  Len 
)     (Stream)->WriteFunc((Stream), (Str), (Len))

Definition at line 347 of file outstream.c.

◆ UNICODE

NOTE: Experimental! Don't use USE_CRT yet because output to console is a bit broken

Definition at line 27 of file outstream.c.

Function Documentation

◆ ConClearLine()

VOID ConClearLine ( IN PCON_STREAM  Stream)

Definition at line 1483 of file outstream.c.

1484{
1486
1487 /*
1488 * Erase the full line where the cursor is, and move
1489 * the cursor back to the beginning of the line.
1490 */
1491
1492 if (IsConsoleHandle(hOutput))
1493 {
1495 DWORD dwWritten;
1496
1497 GetConsoleScreenBufferInfo(hOutput, &csbi);
1498
1499 csbi.dwCursorPosition.X = 0;
1500 // csbi.dwCursorPosition.Y;
1501
1502 FillConsoleOutputCharacterW(hOutput, L' ',
1503 csbi.dwSize.X,
1504 csbi.dwCursorPosition,
1505 &dwWritten);
1507 }
1508 else if (IsTTYHandle(hOutput))
1509 {
1510 ConPuts(Stream, L"\x1B[2K\x1B[1G"); // FIXME: Just use WriteFile
1511 }
1512 // else, do nothing for files
1513}
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:641
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: readwrite.c:1674
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
INT ConPuts(IN PCON_STREAM Stream, IN PCWSTR szStr)
Definition: outstream.c:427
#define IsConsoleHandle(h)
Definition: console.h:14
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:393
SHORT X
Definition: blue.h:26

Referenced by PagePrompt().

◆ ConMsgPrintf()

INT __cdecl ConMsgPrintf ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId,
  ... 
)

Definition at line 1130 of file outstream.c.

1137{
1138 INT Len;
1139 va_list args;
1140
1141 /* Sanitize dwFlags */
1142 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
1143
1144 va_start(args, dwLanguageId);
1146 dwFlags,
1147 lpSource,
1148 dwMessageId,
1149 dwLanguageId,
1150 &args);
1151 va_end(args);
1152
1153 return Len;
1154}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
INT ConMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1030
#define args
Definition: format.c:66
Definition: match.c:390
int32_t INT
Definition: typedefs.h:58
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

◆ ConMsgPrintf2V()

INT ConMsgPrintf2V ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId,
IN va_list  args 
)

Definition at line 909 of file outstream.c.

916{
917 INT Len;
918 DWORD dwLength = 0;
919 LPWSTR lpMsgBuf = NULL;
920
921 /*
922 * Sanitize dwFlags. This version always ignores explicitly the inserts.
923 * The string that we will return to the user will not be pre-formatted.
924 */
925 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
926 dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS; // Ignore inserts for FormatMessage.
927 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
928
929 /*
930 * Retrieve the message string without appending extra newlines.
931 * Wrap in SEH to protect from invalid string parameters.
932 */
934 {
936 lpSource,
937 dwMessageId,
938 dwLanguageId,
939 (LPWSTR)&lpMsgBuf,
940 0,
941 NULL);
942 }
944 {
945 }
946 _SEH2_END;
947
948 Len = (INT)dwLength;
949
950 if (!lpMsgBuf)
951 {
952 // ASSERT(dwLength == 0);
953 }
954 else
955 {
956 // ASSERT(dwLength != 0);
957
958 /* lpMsgBuf is NULL-terminated by FormatMessage */
959 Len = ConPrintfV(Stream, lpMsgBuf, args);
960 // CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
961
962 /* Fixup returned length in case of errors */
963 if (Len < 0)
964 Len = 0;
965
966 /* Free the buffer allocated by FormatMessage */
967 LocalFree(lpMsgBuf);
968 }
969
970 return Len;
971}
#define NULL
Definition: types.h:112
static DWORD DWORD * dwLength
Definition: fusion.c:86
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
INT ConPrintfV(IN PCON_STREAM Stream, IN PCWSTR szStr, IN va_list args)
Definition: outstream.c:466
#define INT
Definition: polytest.cpp:20
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:446
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:445
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ ConMsgPrintfV()

INT ConMsgPrintfV ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId,
IN va_list *Arguments  OPTIONAL 
)

Definition at line 1030 of file outstream.c.

1037{
1038 INT Len;
1039 DWORD dwLength = 0;
1040 LPWSTR lpMsgBuf = NULL;
1041
1042 /* Sanitize dwFlags */
1043 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
1044
1045 /*
1046 * Retrieve the message string without appending extra newlines.
1047 * Use the "safe" FormatMessage version (SEH-protected) to protect
1048 * from invalid string parameters.
1049 */
1051 lpSource,
1052 dwMessageId,
1053 dwLanguageId,
1054 (LPWSTR)&lpMsgBuf,
1055 0,
1056 Arguments);
1057
1058 Len = (INT)dwLength;
1059
1060 if (!lpMsgBuf)
1061 {
1062 // ASSERT(dwLength == 0);
1063 }
1064 else
1065 {
1066 // ASSERT(dwLength != 0);
1067
1068 CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
1069
1070 /* Fixup returned length in case of errors */
1071 if (Len < 0)
1072 Len = 0;
1073
1074 /* Free the buffer allocated by FormatMessage */
1075 LocalFree(lpMsgBuf);
1076 }
1077
1078 return Len;
1079}
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
DWORD WINAPI FormatMessageSafeW(IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, OUT LPWSTR lpBuffer, IN DWORD nSize, IN va_list *Arguments OPTIONAL)
Definition: utils.c:254

Referenced by ConFormatMessage(), ConMsgPrintf(), and ErrorMessage().

◆ ConMsgPuts()

INT ConMsgPuts ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId 
)

Definition at line 837 of file outstream.c.

843{
844 INT Len;
845 DWORD dwLength = 0;
846 LPWSTR lpMsgBuf = NULL;
847
848 /*
849 * Sanitize dwFlags. This version always ignores explicitly the inserts
850 * as we emulate the behaviour of the (f)puts function.
851 */
852 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
853 dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS; // Ignore inserts for FormatMessage.
854 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
855
856 /*
857 * Retrieve the message string without appending extra newlines.
858 * Wrap in SEH to protect from invalid string parameters.
859 */
861 {
863 lpSource,
864 dwMessageId,
865 dwLanguageId,
866 (LPWSTR)&lpMsgBuf,
867 0,
868 NULL);
869 }
871 {
872 }
873 _SEH2_END;
874
875 Len = (INT)dwLength;
876
877 if (!lpMsgBuf)
878 {
879 // ASSERT(dwLength == 0);
880 }
881 else
882 {
883 // ASSERT(dwLength != 0);
884
885 /* lpMsgBuf is NULL-terminated by FormatMessage */
886 // Len = ConPuts(Stream, lpMsgBuf);
888
889 /* Fixup returned length in case of errors */
890 if (Len < 0)
891 Len = 0;
892
893 /* Free the buffer allocated by FormatMessage */
894 LocalFree(lpMsgBuf);
895 }
896
897 return Len;
898}

Referenced by DisplayError(), DoFormatMessage(), HelpCommand(), PrintError(), and PrintWin32Error().

◆ ConPrintf()

INT __cdecl ConPrintf ( IN PCON_STREAM  Stream,
IN PCWSTR  szStr,
  ... 
)

Definition at line 520 of file outstream.c.

524{
525 INT Len;
527
528 // Len = vfwprintf(Stream->fStream, szMsgBuf, args); // vfprintf for direct ANSI
529
530 // StringCchPrintfW
531 va_start(args, szStr);
532 Len = ConPrintfV(Stream, szStr, args);
533 va_end(args);
534
535 return Len;
536}

◆ ConPrintfV()

INT ConPrintfV ( IN PCON_STREAM  Stream,
IN PCWSTR  szStr,
IN va_list  args 
)

Definition at line 466 of file outstream.c.

470{
471 INT Len;
473
474 // Len = vfwprintf(Stream->fStream, szStr, args); // vfprintf for direct ANSI
475
476 /*
477 * Re-use szStr as the pointer to end-of-string, so as
478 * to compute the string length instead of calling wcslen().
479 */
480 // StringCchVPrintfW(bufSrc, ARRAYSIZE(bufSrc), szStr, args);
481 // Len = wcslen(bufSrc);
482 StringCchVPrintfExW(bufSrc, ARRAYSIZE(bufSrc), (PWSTR*)&szStr, NULL, 0, szStr, args);
483 Len = szStr - bufSrc;
484
485 CON_STREAM_WRITE2(Stream, bufSrc, Len, Len);
486
487 /* Fixup returned length in case of errors */
488 if (Len < 0)
489 Len = 0;
490
491 return Len;
492}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CON_RC_STRING_MAX_SIZE
Definition: outstream.c:56
STRSAFEAPI StringCchVPrintfExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat, va_list argList)
Definition: strsafe.h:661
uint16_t * PWSTR
Definition: typedefs.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ConMsgPrintf2V(), ConPrintf(), ConResPrintfExV(), and DirPrintf().

◆ ConPuts()

INT ConPuts ( IN PCON_STREAM  Stream,
IN PCWSTR  szStr 
)

Definition at line 427 of file outstream.c.

430{
431 INT Len;
432
433 Len = wcslen(szStr);
435
436 /* Fixup returned length in case of errors */
437 if (Len < 0)
438 Len = 0;
439
440 return Len;
441}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by ConClearLine().

◆ ConResMsgPrintf()

INT __cdecl ConResMsgPrintf ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN UINT  uID,
  ... 
)

Definition at line 1461 of file outstream.c.

1466{
1467 INT Len;
1468 va_list args;
1469
1470 /* Sanitize dwFlags */
1471 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
1472
1473 va_start(args, uID);
1475 va_end(args);
1476
1477 return Len;
1478}
INT ConResMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1329

Referenced by EnumProcessAndPrint(), HandleFindCommand(), HandleInfoCommand(), HandleInstallCommand(), HandleSetupCommand(), PagePrompt(), and ProcessArguments().

◆ ConResMsgPrintfEx()

INT __cdecl ConResMsgPrintfEx ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN DWORD  dwFlags,
IN UINT  uID,
IN LANGID  LanguageId,
  ... 
)

Definition at line 1394 of file outstream.c.

1401{
1402 INT Len;
1403 va_list args;
1404
1405 /* Sanitize dwFlags */
1406 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
1407
1408 va_start(args, LanguageId);
1410 hInstance,
1411 dwFlags,
1412 uID,
1413 LanguageId,
1414 &args);
1415 va_end(args);
1416
1417 return Len;
1418}
HINSTANCE hInstance
Definition: charmap.c:19
INT ConResMsgPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1218

◆ ConResMsgPrintfExV()

INT ConResMsgPrintfExV ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN DWORD  dwFlags,
IN UINT  uID,
IN LANGID  LanguageId,
IN va_list *Arguments  OPTIONAL 
)

Definition at line 1218 of file outstream.c.

1225{
1226 INT Len;
1227 DWORD dwLength = 0;
1228 LPWSTR lpMsgBuf = NULL;
1230
1231 /* Retrieve the string from the resource string table */
1232 // NOTE: We may use the special behaviour where nBufMaxSize == 0
1233 Len = K32LoadStringExW(hInstance, uID, LanguageId, bufSrc, ARRAYSIZE(bufSrc));
1234 if (Len == 0)
1235 return Len;
1236
1237 /* Sanitize dwFlags */
1238 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
1239
1240 /* The string has already been manually loaded */
1243
1244 /*
1245 * Retrieve the message string without appending extra newlines.
1246 * Use the "safe" FormatMessage version (SEH-protected) to protect
1247 * from invalid string parameters.
1248 */
1250 bufSrc,
1251 0, 0,
1252 (LPWSTR)&lpMsgBuf,
1253 0,
1254 Arguments);
1255
1256 Len = (INT)dwLength;
1257
1258 if (!lpMsgBuf)
1259 {
1260 // ASSERT(dwLength == 0);
1261 }
1262 else
1263 {
1264 // ASSERT(dwLength != 0);
1265
1266 CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
1267
1268 /* Fixup returned length in case of errors */
1269 if (Len < 0)
1270 Len = 0;
1271
1272 /* Free the buffer allocated by FormatMessage */
1273 LocalFree(lpMsgBuf);
1274 }
1275
1276 return Len;
1277}
INT WINAPI K32LoadStringExW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:99
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:447
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:448

Referenced by ConResMsgPrintfEx(), and ConResMsgPrintfV().

◆ ConResMsgPrintfV()

INT ConResMsgPrintfV ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN UINT  uID,
IN va_list *Arguments  OPTIONAL 
)

Definition at line 1329 of file outstream.c.

1334{
1335 return ConResMsgPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
1336 dwFlags, uID,
1338 Arguments);
1339}
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_NEUTRAL
Definition: nls.h:167

Referenced by ConResMsgPrintf().

◆ ConResPrintf()

INT __cdecl ConResPrintf ( IN PCON_STREAM  Stream,
IN UINT  uID,
  ... 
)

Definition at line 781 of file outstream.c.

785{
786 INT Len;
788
789 va_start(args, uID);
790 Len = ConResPrintfV(Stream, uID, args);
791 va_end(args);
792
793 return Len;
794}
INT ConResPrintfV(IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
Definition: outstream.c:695

◆ ConResPrintfEx()

INT __cdecl ConResPrintfEx ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN UINT  uID,
IN LANGID  LanguageId,
  ... 
)

Definition at line 740 of file outstream.c.

746{
747 INT Len;
749
750 va_start(args, LanguageId);
751 Len = ConResPrintfExV(Stream, hInstance, uID, LanguageId, args);
752 va_end(args);
753
754 return Len;
755}
INT ConResPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, IN va_list args)
Definition: outstream.c:653

◆ ConResPrintfExV()

INT ConResPrintfExV ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN UINT  uID,
IN LANGID  LanguageId,
IN va_list  args 
)

Definition at line 653 of file outstream.c.

659{
660 INT Len;
662
663 // NOTE: We may use the special behaviour where nBufMaxSize == 0
664 Len = K32LoadStringExW(hInstance, uID, LanguageId, bufSrc, ARRAYSIZE(bufSrc));
665 if (Len)
666 Len = ConPrintfV(Stream, bufSrc, args);
667
668 return Len;
669}

Referenced by ConResPrintfEx(), and ConResPrintfV().

◆ ConResPrintfV()

INT ConResPrintfV ( IN PCON_STREAM  Stream,
IN UINT  uID,
IN va_list  args 
)

Definition at line 695 of file outstream.c.

699{
700 return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
702 args);
703}

Referenced by ConResPrintf(), PrintParserError(), and UnderlinedResPrintf().

◆ ConResPuts()

INT ConResPuts ( IN PCON_STREAM  Stream,
IN UINT  uID 
)

Definition at line 610 of file outstream.c.

613{
614 return ConResPutsEx(Stream, NULL /*GetModuleHandleW(NULL)*/,
616}
INT ConResPutsEx(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId)
Definition: outstream.c:569

◆ ConResPutsEx()

INT ConResPutsEx ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN UINT  uID,
IN LANGID  LanguageId 
)

Definition at line 569 of file outstream.c.

574{
575 INT Len;
576 PWCHAR szStr = NULL;
577
578 Len = K32LoadStringExW(hInstance, uID, LanguageId, (PWSTR)&szStr, 0);
579 if (szStr && Len)
580 // Len = ConPuts(Stream, szStr);
582
583 /* Fixup returned length in case of errors */
584 if (Len < 0)
585 Len = 0;
586
587 return Len;
588}
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by ConResPuts().

◆ ConStreamWrite()

INT ConStreamWrite ( IN PCON_STREAM  Stream,
IN PCTCH  szStr,
IN DWORD  len 
)

Definition at line 398 of file outstream.c.

402{
403 INT Len;
405 return Len;
406}
GLenum GLsizei len
Definition: glext.h:6722

Referenced by MorePagerLine(), PagePrompt(), and UnderlinedResPrintf().

◆ ConWrite()

INT __stdcall ConWrite ( IN PCON_STREAM  Stream,
IN PCTCH  szStr,
IN DWORD  len 
)

Definition at line 85 of file outstream.c.

89{
90#ifndef USE_CRT
91 DWORD TotalLen = len, dwNumBytes = 0;
92 LPCVOID p;
93
94 /* If we do not write anything, just return */
95 if (!szStr || len == 0)
96 return 0;
97
98 /* Check whether we are writing to a console */
99 // if (IsConsoleHandle(Stream->hHandle))
100 if (Stream->IsConsole)
101 {
102 // TODO: Check if (Stream->Mode == WideText or UTF16Text) ??
103
104 /*
105 * This code is inspired from _cputws, in particular from the fact that,
106 * according to MSDN: https://msdn.microsoft.com/en-us/library/ms687401(v=vs.85).aspx
107 * the buffer size must be less than 64 KB.
108 *
109 * A similar code can be used for implementing _cputs too.
110 */
111
112 DWORD cchWrite;
113 TotalLen = len, dwNumBytes = 0;
114
115 while (len > 0)
116 {
117 cchWrite = min(len, 65535 / sizeof(WCHAR));
118
119 // FIXME: Check return value!
120 WriteConsole(Stream->hHandle, szStr, cchWrite, &dwNumBytes, NULL);
121
122 szStr += cchWrite;
123 len -= cchWrite;
124 }
125
126 return (INT)TotalLen; // FIXME: Really return the number of chars written!
127 }
128
129 /*
130 * We are redirected and writing to a file or pipe instead of the console.
131 * Convert the string from TCHARs to the desired output format, if the two differ.
132 *
133 * Implementation NOTE:
134 * MultiByteToWideChar (resp. WideCharToMultiByte) are equivalent to
135 * OemToCharBuffW (resp. CharToOemBuffW), but these latter functions
136 * uselessly depend on user32.dll, while MultiByteToWideChar and
137 * WideCharToMultiByte only need kernel32.dll.
138 */
139 if ((Stream->Mode == WideText) || (Stream->Mode == UTF16Text))
140 {
141#ifndef _UNICODE // UNICODE means that TCHAR == WCHAR == UTF-16
142 /* Convert from the current process/thread's code page to UTF-16 */
144 if (!buffer)
145 {
147 return 0;
148 }
149 len = (DWORD)MultiByteToWideChar(CP_THREAD_ACP, // CP_ACP, CP_OEMCP
150 0, szStr, (INT)len, buffer, (INT)len);
151 szStr = (PVOID)buffer;
152#else
153 /*
154 * Do not perform any conversion since we are already in UTF-16,
155 * that is the same encoding as the stream.
156 */
157#endif
158
159 /*
160 * Find any newline character in the buffer,
161 * write the part BEFORE the newline, then emit
162 * a carriage-return + newline sequence and finally
163 * write the remaining part of the buffer.
164 *
165 * This fixes output in files and serial console.
166 */
167 while (len > 0)
168 {
169 /* Loop until we find a newline character */
170 p = szStr;
171 while (len > 0 && *(PCWCH)p != L'\n')
172 {
173 /* Advance one character */
174 p = (LPCVOID)((PCWCH)p + 1);
175 --len;
176 }
177
178 /* Write everything up to \n */
179 dwNumBytes = ((PCWCH)p - (PCWCH)szStr) * sizeof(WCHAR);
180 WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
181
182 /*
183 * If we hit a newline and the previous character is not a carriage-return,
184 * emit a carriage-return + newline sequence, otherwise just emit the newline.
185 */
186 if (len > 0 && *(PCWCH)p == L'\n')
187 {
188 if (p == (LPCVOID)szStr || (p > (LPCVOID)szStr && *((PCWCH)p - 1) != L'\r'))
189 WriteFile(Stream->hHandle, L"\r\n", 2 * sizeof(WCHAR), &dwNumBytes, NULL);
190 else
191 WriteFile(Stream->hHandle, L"\n", sizeof(WCHAR), &dwNumBytes, NULL);
192
193 /* Skip \n */
194 p = (LPCVOID)((PCWCH)p + 1);
195 --len;
196 }
197 szStr = p;
198 }
199
200#ifndef _UNICODE
202#endif
203 }
204 else if ((Stream->Mode == UTF8Text) || (Stream->Mode == AnsiText))
205 {
206 UINT CodePage;
208
209 /*
210 * Resolve the current code page if it has not been assigned yet
211 * (we do this only if the stream is in ANSI mode; in UTF8 mode
212 * the code page is always set to CP_UTF8). Otherwise use the
213 * current stream's code page.
214 */
215 if (/*(Stream->Mode == AnsiText) &&*/ (Stream->CodePage == INVALID_CP))
216 CodePage = GetConsoleOutputCP(); // CP_ACP, CP_OEMCP
217 else
218 CodePage = Stream->CodePage;
219
220#ifdef _UNICODE // UNICODE means that TCHAR == WCHAR == UTF-16
221 /* Convert from UTF-16 to either UTF-8 or ANSI, using the stream code page */
222 // NOTE: MB_LEN_MAX defined either in limits.h or in stdlib.h .
224 if (!buffer)
225 {
227 return 0;
228 }
229 len = WideCharToMultiByte(CodePage, 0,
230 szStr, len, buffer, len * MB_LEN_MAX,
231 NULL, NULL);
232 szStr = (PVOID)buffer;
233#else
234 /*
235 * Convert from the current process/thread's code page to either
236 * UTF-8 or ANSI, using the stream code page.
237 * We need to perform a double conversion, by going through UTF-16.
238 */
239 // TODO!
240 #error "Need to implement double conversion!"
241#endif
242
243 /*
244 * Find any newline character in the buffer,
245 * write the part BEFORE the newline, then emit
246 * a carriage-return + newline sequence and finally
247 * write the remaining part of the buffer.
248 *
249 * This fixes output in files and serial console.
250 */
251 while (len > 0)
252 {
253 /* Loop until we find a newline character */
254 p = szStr;
255 while (len > 0 && *(PCCH)p != '\n')
256 {
257 /* Advance one character */
258 p = (LPCVOID)((PCCH)p + 1);
259 --len;
260 }
261
262 /* Write everything up to \n */
263 dwNumBytes = ((PCCH)p - (PCCH)szStr) * sizeof(CHAR);
264 WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
265
266 /*
267 * If we hit a newline and the previous character is not a carriage-return,
268 * emit a carriage-return + newline sequence, otherwise just emit the newline.
269 */
270 if (len > 0 && *(PCCH)p == '\n')
271 {
272 if (p == (LPCVOID)szStr || (p > (LPCVOID)szStr && *((PCCH)p - 1) != '\r'))
273 WriteFile(Stream->hHandle, "\r\n", 2, &dwNumBytes, NULL);
274 else
275 WriteFile(Stream->hHandle, "\n", 1, &dwNumBytes, NULL);
276
277 /* Skip \n */
278 p = (LPCVOID)((PCCH)p + 1);
279 --len;
280 }
281 szStr = p;
282 }
283
284#ifdef _UNICODE
286#else
287 // TODO!
288#endif
289 }
290 else // if (Stream->Mode == Binary)
291 {
292 /* Directly output the string */
293 WriteFile(Stream->hHandle, szStr, len, &dwNumBytes, NULL);
294 }
295
296 // FIXME!
297 return (INT)TotalLen;
298
299#else /* defined(USE_CRT) */
300
301 DWORD total = len;
302 DWORD written = 0;
303
304 /* If we do not write anything, just return */
305 if (!szStr || len == 0)
306 return 0;
307
308#if 1
309 /*
310 * There is no "counted" printf-to-stream or puts-like function, therefore
311 * we use this trick to output the counted string to the stream.
312 */
313 while (1)
314 {
315 written = fwprintf(Stream->fStream, L"%.*s", total, szStr);
316 if (written < total)
317 {
318 /*
319 * Some embedded NULL or special character
320 * was encountered, print it apart.
321 */
322 if (written == 0)
323 {
324 fputwc(*szStr, Stream->fStream);
325 written++;
326 }
327
328 szStr += written;
329 total -= written;
330 }
331 else
332 {
333 break;
334 }
335 }
336 return (INT)len;
337#else
338 /* ANSI text or Binary output only */
339 _setmode(_fileno(Stream->fStream), _O_TEXT); // _O_BINARY
340 return fwrite(szStr, sizeof(*szStr), len, Stream->fStream);
341#endif
342
343#endif /* defined(USE_CRT) */
344}
#define _setmode(fd, mode)
Definition: cat.c:21
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define _O_TEXT
Definition: cabinet.h:50
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2451
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
size_t total
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_opt_ _CRTIMP wint_t __cdecl fputwc(_In_ wchar_t _Ch, _Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fwprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const wchar_t *_Format,...)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define MB_LEN_MAX
Definition: stdlib.h:19
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
CONST WCHAR * PCWCH
Definition: ntbasedef.h:419
CONST CHAR * PCCH
Definition: ntbasedef.h:400
@ AnsiText
Definition: stream.h:47
@ UTF16Text
Definition: stream.h:49
@ WideText
Definition: stream.h:48
@ UTF8Text
Definition: stream.h:50
#define INVALID_CP
Definition: stream.h:53
void * PVOID
Definition: typedefs.h:50
char * PCHAR
Definition: typedefs.h:51
#define WriteConsole
Definition: wincon.h:784
CONST void * LPCVOID
Definition: windef.h:191
#define CP_THREAD_ACP
Definition: winnls.h:235
char CHAR
Definition: xmlstorage.h:175

Referenced by ConErrChar(), ConOutChar(), ConStreamInit(), and ConStreamInitEx().