2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Utilities Library
4 * FILE: sdk/lib/conutils/stream.h
5 * PURPOSE: Provides basic abstraction wrappers around CRT streams or
6 * Win32 console API I/O functions, to deal with i18n + Unicode
8 * PROGRAMMERS: - Hermes Belusca-Maito (for the library);
9 * - All programmers who wrote the different console applications
10 * from which I took those functions and improved them.
17 * Enable this define if you want to only use CRT functions to output
18 * UNICODE stream to the console, as in the way explained by
19 * http://archives.miloush.net/michkap/archive/2008/03/18/8306597.html
21 /** NOTE: Experimental! Don't use USE_CRT yet because output to console is a bit broken **/
25 #error The ConUtils library at the moment only supports compilation with _UNICODE defined!
37 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
38 * for more information.
40 typedef enum _CON_STREAM_MODE
42 Binary
= 0, // #define _O_BINARY 0x8000 // file mode is binary (untranslated)
43 // #define _O_RAW _O_BINARY
44 AnsiText
, // #define _O_TEXT 0x4000 // file mode is text (translated) -- "ANSI"
45 WideText
, // #define _O_WTEXT 0x10000 // file mode is UTF16 with BOM (translated) -- "Unicode" of Windows
46 UTF16Text
, // #define _O_U16TEXT 0x20000 // file mode is UTF16 no BOM (translated) -- "" ""
47 UTF8Text
, // #define _O_U8TEXT 0x40000 // file mode is UTF8 no BOM (translated)
48 } CON_STREAM_MODE
, *PCON_STREAM_MODE
;
50 #define INVALID_CP ((UINT)-1)
52 // Shadow type, implementation-specific
53 typedef struct _CON_STREAM CON_STREAM
, *PCON_STREAM
;
55 // typedef INT (__stdcall *CON_READ_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
57 typedef INT (__stdcall
*CON_WRITE_FUNC
)(IN PCON_STREAM
, IN PTCHAR
, IN DWORD
);
60 * Standard console streams, initialized by
61 * calls to ConStreamInit/ConInitStdStreams.
64 extern CON_STREAM StdStreams
[3];
65 #define StdIn (&StdStreams[0])
66 #define StdOut (&StdStreams[1])
67 #define StdErr (&StdStreams[2])
69 extern CON_STREAM csStdIn
;
70 extern CON_STREAM csStdOut
;
71 extern CON_STREAM csStdErr
;
72 #define StdIn (&csStdIn )
73 #define StdOut (&csStdOut)
74 #define StdErr (&csStdErr)
79 OUT PCON_STREAM Stream
,
81 IN CON_STREAM_MODE Mode
,
82 IN UINT CacheCodePage OPTIONAL
,
83 // IN ReadWriteMode ????
84 // IN CON_READ_FUNC ReadFunc OPTIONAL,
85 IN CON_WRITE_FUNC WriteFunc OPTIONAL
);
89 OUT PCON_STREAM Stream
,
91 // IN ReadWriteMode ????
92 IN CON_STREAM_MODE Mode
,
93 IN UINT CacheCodePage OPTIONAL
);
96 /* Console Standard Streams initialization helpers */
98 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
100 ConStreamInit(StdIn , stdin , (Mode), (CacheCodePage)); \
101 ConStreamInit(StdOut, stdout, (Mode), (CacheCodePage)); \
102 ConStreamInit(StdErr, stderr, (Mode), (CacheCodePage)); \
105 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
107 ConStreamInit(StdIn , GetStdHandle(STD_INPUT_HANDLE) , (Mode), (CacheCodePage)); \
108 ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), (Mode), (CacheCodePage)); \
109 ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , (Mode), (CacheCodePage)); \
111 #endif /* defined(USE_CRT) */
115 * Use UTF8 by default for file output, because this mode is back-compatible
116 * with ANSI, and it displays nice on terminals that support UTF8 by default
117 * (not many terminals support UTF16 on the contrary).
119 #define ConInitStdStreams() \
120 ConInitStdStreamsAndMode(UTF8Text, INVALID_CP); // Cache code page unused
122 /* Use ANSI by default for file output */
123 #define ConInitStdStreams() \
124 ConInitStdStreamsAndMode(AnsiText, INVALID_CP);
125 #endif /* defined(_UNICODE) */
127 /* Stream translation modes */
130 IN PCON_STREAM Stream
,
131 IN CON_STREAM_MODE Mode
,
132 IN UINT CacheCodePage OPTIONAL
);
136 #warning The ConStreamSetCacheCodePage function does not make much sense with the CRT!
139 ConStreamSetCacheCodePage(
140 IN PCON_STREAM Stream
,
141 IN UINT CacheCodePage
);
145 ConStreamGetOSHandle(
146 IN PCON_STREAM Stream
);
149 ConStreamSetOSHandle(
150 IN PCON_STREAM Stream
,
155 * Console I/O utility API
156 * (for the moment, only Output)
162 IN PCON_STREAM Stream
,
168 IN PCON_STREAM Stream
,
174 IN PCON_STREAM Stream
,
179 IN PCON_STREAM Stream
,
181 IN
va_list args
); // arg_ptr
186 IN PCON_STREAM Stream
,
192 IN PCON_STREAM Stream
,
193 IN HINSTANCE hInstance OPTIONAL
,
198 IN PCON_STREAM Stream
,
203 IN PCON_STREAM Stream
,
204 IN HINSTANCE hInstance OPTIONAL
,
206 IN
va_list args
); // arg_ptr
210 IN PCON_STREAM Stream
,
212 IN
va_list args
); // arg_ptr
217 IN PCON_STREAM Stream
,
218 IN HINSTANCE hInstance OPTIONAL
,
225 IN PCON_STREAM Stream
,
231 IN PCON_STREAM Stream
,
233 IN LPCVOID lpSource OPTIONAL
,
234 IN DWORD dwMessageId
,
235 IN DWORD dwLanguageId
);
239 IN PCON_STREAM Stream
,
241 IN LPCVOID lpSource OPTIONAL
,
242 IN DWORD dwMessageId
,
243 IN DWORD dwLanguageId
,
244 IN
va_list args
); // arg_ptr
248 IN PCON_STREAM Stream
,
250 IN LPCVOID lpSource OPTIONAL
,
251 IN DWORD dwMessageId
,
252 IN DWORD dwLanguageId
,
253 IN
va_list args
); // arg_ptr
258 IN PCON_STREAM Stream
,
260 IN LPCVOID lpSource OPTIONAL
,
261 IN DWORD dwMessageId
,
262 IN DWORD dwLanguageId
,
268 ConClearLine(IN PCON_STREAM Stream
);
274 #endif /* __STREAM_H__ */