2 * PROJECT: ReactOS Console Utilities Library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Provides basic abstraction wrappers around CRT streams or
5 * Win32 console API I/O functions, to deal with i18n + Unicode
7 * COPYRIGHT: Copyright 2017-2018 ReactOS Team
8 * Copyright 2017-2018 Hermes Belusca-Maito
15 * @brief Console I/O streams
24 * Enable this define if you want to only use CRT functions to output
25 * UNICODE stream to the console, as in the way explained by
26 * http://archives.miloush.net/michkap/archive/2008/03/18/8306597.html
28 /** NOTE: Experimental! Don't use USE_CRT yet because output to console is a bit broken **/
32 #error The ConUtils library at the moment only supports compilation with _UNICODE defined!
40 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
41 * for more information.
43 typedef enum _CON_STREAM_MODE
45 Binary
= 0, // #define _O_BINARY 0x8000 // file mode is binary (untranslated)
46 // #define _O_RAW _O_BINARY
47 AnsiText
, // #define _O_TEXT 0x4000 // file mode is text (translated) -- "ANSI"
48 WideText
, // #define _O_WTEXT 0x10000 // file mode is UTF16 with BOM (translated) -- "Unicode" of Windows
49 UTF16Text
, // #define _O_U16TEXT 0x20000 // file mode is UTF16 no BOM (translated) -- "" ""
50 UTF8Text
, // #define _O_U8TEXT 0x40000 // file mode is UTF8 no BOM (translated)
51 } CON_STREAM_MODE
, *PCON_STREAM_MODE
;
53 #define INVALID_CP ((UINT)-1)
55 // Shadow type, implementation-specific
56 typedef struct _CON_STREAM CON_STREAM
, *PCON_STREAM
;
58 // typedef INT (__stdcall *CON_READ_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
60 typedef INT (__stdcall
*CON_WRITE_FUNC
)(IN PCON_STREAM
, IN PTCHAR
, IN DWORD
);
63 * Standard console streams, initialized by
64 * calls to ConStreamInit/ConInitStdStreams.
67 extern CON_STREAM StdStreams
[3];
68 #define StdIn (&StdStreams[0])
69 #define StdOut (&StdStreams[1])
70 #define StdErr (&StdStreams[2])
72 extern CON_STREAM csStdIn
;
73 extern CON_STREAM csStdOut
;
74 extern CON_STREAM csStdErr
;
75 #define StdIn (&csStdIn )
76 #define StdOut (&csStdOut)
77 #define StdErr (&csStdErr)
82 OUT PCON_STREAM Stream
,
84 IN CON_STREAM_MODE Mode
,
85 IN UINT CacheCodePage OPTIONAL
,
86 // IN ReadWriteMode ????
87 // IN CON_READ_FUNC ReadFunc OPTIONAL,
88 IN CON_WRITE_FUNC WriteFunc OPTIONAL
);
92 OUT PCON_STREAM Stream
,
94 // IN ReadWriteMode ????
95 IN CON_STREAM_MODE Mode
,
96 IN UINT CacheCodePage OPTIONAL
);
99 /* Console Standard Streams initialization helpers */
101 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
103 ConStreamInit(StdIn , stdin , (Mode), (CacheCodePage)); \
104 ConStreamInit(StdOut, stdout, (Mode), (CacheCodePage)); \
105 ConStreamInit(StdErr, stderr, (Mode), (CacheCodePage)); \
108 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
110 ConStreamInit(StdIn , GetStdHandle(STD_INPUT_HANDLE) , (Mode), (CacheCodePage)); \
111 ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), (Mode), (CacheCodePage)); \
112 ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , (Mode), (CacheCodePage)); \
114 #endif /* defined(USE_CRT) */
117 * Use ANSI by default for file output, with no cached code page.
118 * Note that setting the stream mode to AnsiText and the code page value
119 * to CP_UTF8 sets the stream to UTF8 mode, and has the same effect as if
120 * the stream mode UTF8Text had been specified instead.
122 #define ConInitStdStreams() \
123 ConInitStdStreamsAndMode(AnsiText, INVALID_CP)
125 /* Stream translation modes */
128 IN PCON_STREAM Stream
,
129 IN CON_STREAM_MODE Mode
,
130 IN UINT CacheCodePage OPTIONAL
);
134 #warning The ConStreamSetCacheCodePage function does not make much sense with the CRT!
137 ConStreamSetCacheCodePage(
138 IN PCON_STREAM Stream
,
139 IN UINT CacheCodePage
);
143 ConStreamGetOSHandle(
144 IN PCON_STREAM Stream
);
147 ConStreamSetOSHandle(
148 IN PCON_STREAM Stream
,
156 #endif /* __STREAM_H__ */