ReactOS 0.4.16-dev-2491-g3dc6630
outstream.c File Reference

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

#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <winnls.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 55 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 359 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:346

Definition at line 352 of file outstream.c.

◆ CON_STREAM_WRITE_CALL

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

Definition at line 346 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 1480 of file outstream.c.

1481{
1483
1484 /*
1485 * Erase the full line where the cursor is, and move
1486 * the cursor back to the beginning of the line.
1487 */
1488
1489 if (IsConsoleHandle(hOutput))
1490 {
1492 DWORD dwWritten;
1493
1494 GetConsoleScreenBufferInfo(hOutput, &csbi);
1495
1496 csbi.dwCursorPosition.X = 0;
1497 // csbi.dwCursorPosition.Y;
1498
1499 FillConsoleOutputCharacterW(hOutput, L' ',
1500 csbi.dwSize.X,
1501 csbi.dwCursorPosition,
1502 &dwWritten);
1504 }
1505 else if (IsTTYHandle(hOutput))
1506 {
1507 ConPuts(Stream, L"\x1B[2K\x1B[1G"); // FIXME: Just use WriteFile
1508 }
1509 // else, do nothing for files
1510}
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
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
INT ConPuts(IN PCON_STREAM Stream, IN PCWSTR szStr)
Definition: outstream.c:426
#define IsConsoleHandle(h)
Definition: console.h:14
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:239
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:403
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 1128 of file outstream.c.

1135{
1136 INT Len;
1137 va_list args;
1138
1139 /* Sanitize dwFlags */
1140 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
1141
1142 va_start(args, dwLanguageId);
1144 dwFlags,
1145 lpSource,
1146 dwMessageId,
1147 dwLanguageId,
1148 &args);
1149 va_end(args);
1150
1151 return Len;
1152}
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
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:1028
#define args
Definition: format.c:66
Definition: match.c:390
int32_t INT
Definition: typedefs.h:58

◆ 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 907 of file outstream.c.

914{
915 INT Len;
916 DWORD dwLength = 0;
917 LPWSTR lpMsgBuf = NULL;
918
919 /*
920 * Sanitize dwFlags. This version always ignores explicitly the inserts.
921 * The string that we will return to the user will not be pre-formatted.
922 */
923 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
924 dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS; // Ignore inserts for FormatMessage.
925 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
926
927 /*
928 * Retrieve the message string without appending extra newlines.
929 * Wrap in SEH to protect from invalid string parameters.
930 */
932 {
934 lpSource,
935 dwMessageId,
936 dwLanguageId,
937 (LPWSTR)&lpMsgBuf,
938 0,
939 NULL);
940 }
942 {
943 }
944 _SEH2_END;
945
946 Len = (INT)dwLength;
947
948 if (!lpMsgBuf)
949 {
950 // ASSERT(dwLength == 0);
951 }
952 else
953 {
954 // ASSERT(dwLength != 0);
955
956 /* lpMsgBuf is NULL-terminated by FormatMessage */
957 Len = ConPrintfV(Stream, lpMsgBuf, args);
958 // CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
959
960 /* Fixup returned length in case of errors */
961 if (Len < 0)
962 Len = 0;
963
964 /* Free the buffer allocated by FormatMessage */
965 LocalFree(lpMsgBuf);
966 }
967
968 return Len;
969}
#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:90
INT ConPrintfV(IN PCON_STREAM Stream, IN PCWSTR szStr, IN va_list args)
Definition: outstream.c:465
#define INT
Definition: polytest.cpp:20
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:397
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:396
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 1028 of file outstream.c.

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

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 835 of file outstream.c.

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

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

◆ ConPrintf()

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

Definition at line 519 of file outstream.c.

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

◆ ConPrintfV()

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

Definition at line 465 of file outstream.c.

469{
470 INT Len;
472
473 // Len = vfwprintf(Stream->fStream, szStr, args); // vfprintf for direct ANSI
474
475 /*
476 * Re-use szStr as the pointer to end-of-string, so as
477 * to compute the string length instead of calling wcslen().
478 */
479 // StringCchVPrintfW(bufSrc, ARRAYSIZE(bufSrc), szStr, args);
480 // Len = wcslen(bufSrc);
481 StringCchVPrintfExW(bufSrc, ARRAYSIZE(bufSrc), (PWSTR*)&szStr, NULL, 0, szStr, args);
482 Len = szStr - bufSrc;
483
484 CON_STREAM_WRITE2(Stream, bufSrc, Len, Len);
485
486 /* Fixup returned length in case of errors */
487 if (Len < 0)
488 Len = 0;
489
490 return Len;
491}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CON_RC_STRING_MAX_SIZE
Definition: outstream.c:55
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(), DirPrintf(), PrintMessage(), and PrintRow().

◆ ConPuts()

INT ConPuts ( IN PCON_STREAM  Stream,
IN PCWSTR  szStr 
)

Definition at line 426 of file outstream.c.

429{
430 INT Len;
431
432 Len = (INT)wcslen(szStr);
434
435 /* Fixup returned length in case of errors */
436 if (Len < 0)
437 Len = 0;
438
439 return Len;
440}
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983

Referenced by ConClearLine().

◆ ConResMsgPrintf()

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

Definition at line 1458 of file outstream.c.

1463{
1464 INT Len;
1465 va_list args;
1466
1467 /* Sanitize dwFlags */
1468 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
1469
1470 va_start(args, uID);
1472 va_end(args);
1473
1474 return Len;
1475}
INT ConResMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1327
_In_ UINT uID
Definition: shlwapi.h:156

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 1391 of file outstream.c.

1398{
1399 INT Len;
1400 va_list args;
1401
1402 /* Sanitize dwFlags */
1403 dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
1404
1405 va_start(args, LanguageId);
1407 hInstance,
1408 dwFlags,
1409 uID,
1410 LanguageId,
1411 &args);
1412 va_end(args);
1413
1414 return Len;
1415}
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:1216

◆ 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 1216 of file outstream.c.

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

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 1327 of file outstream.c.

1332{
1335 Arguments);
1336}
#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 779 of file outstream.c.

783{
784 INT Len;
786
787 va_start(args, uID);
789 va_end(args);
790
791 return Len;
792}
INT ConResPrintfV(IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
Definition: outstream.c:694

◆ ConResPrintfEx()

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

Definition at line 738 of file outstream.c.

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

◆ ConResPrintfExV()

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

Definition at line 652 of file outstream.c.

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

Referenced by ConResPrintfEx(), ConResPrintfV(), and PrintMessageFromModule().

◆ ConResPrintfV()

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

Definition at line 694 of file outstream.c.

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

◆ ConResPuts()

INT ConResPuts ( IN PCON_STREAM  Stream,
IN UINT  uID 
)

Definition at line 609 of file outstream.c.

612{
613 return ConResPutsEx(Stream, NULL, uID,
615}
INT ConResPutsEx(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId)
Definition: outstream.c:568

◆ ConResPutsEx()

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

Definition at line 568 of file outstream.c.

573{
574 INT Len;
575 PWCHAR szStr = NULL;
576
577 Len = K32LoadStringExW(hInstance, uID, LanguageId, (PWSTR)&szStr, 0);
578 if (szStr && Len)
579 // Len = ConPuts(Stream, szStr);
581
582 /* Fixup returned length in case of errors */
583 if (Len < 0)
584 Len = 0;
585
586 return Len;
587}
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 397 of file outstream.c.

401{
402 INT Len;
404 return Len;
405}
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 84 of file outstream.c.

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

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