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!
33 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
34 * for more information.
36 typedef enum _CON_STREAM_MODE
38 Binary
= 0, // #define _O_BINARY 0x8000 // file mode is binary (untranslated)
39 // #define _O_RAW _O_BINARY
40 AnsiText
, // #define _O_TEXT 0x4000 // file mode is text (translated) -- "ANSI"
41 WideText
, // #define _O_WTEXT 0x10000 // file mode is UTF16 with BOM (translated) -- "Unicode" of Windows
42 UTF16Text
, // #define _O_U16TEXT 0x20000 // file mode is UTF16 no BOM (translated) -- "" ""
43 UTF8Text
, // #define _O_U8TEXT 0x40000 // file mode is UTF8 no BOM (translated)
44 } CON_STREAM_MODE
, *PCON_STREAM_MODE
;
46 #define INVALID_CP ((UINT)-1)
48 // Shadow type, implementation-specific
49 typedef struct _CON_STREAM CON_STREAM
, *PCON_STREAM
;
51 // typedef INT (__stdcall *CON_READ_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
53 typedef INT (__stdcall
*CON_WRITE_FUNC
)(IN PCON_STREAM
, IN PTCHAR
, IN DWORD
);
56 * Standard console streams, initialized by
57 * calls to ConStreamInit/ConInitStdStreams.
60 extern CON_STREAM StdStreams
[3];
61 #define StdIn (&StdStreams[0])
62 #define StdOut (&StdStreams[1])
63 #define StdErr (&StdStreams[2])
65 extern CON_STREAM csStdIn
;
66 extern CON_STREAM csStdOut
;
67 extern CON_STREAM csStdErr
;
68 #define StdIn (&csStdIn )
69 #define StdOut (&csStdOut)
70 #define StdErr (&csStdErr)
75 OUT PCON_STREAM Stream
,
77 IN CON_STREAM_MODE Mode
,
78 IN UINT CacheCodePage OPTIONAL
,
79 // IN ReadWriteMode ????
80 // IN CON_READ_FUNC ReadFunc OPTIONAL,
81 IN CON_WRITE_FUNC WriteFunc OPTIONAL
);
85 OUT PCON_STREAM Stream
,
87 // IN ReadWriteMode ????
88 IN CON_STREAM_MODE Mode
,
89 IN UINT CacheCodePage OPTIONAL
);
92 /* Console Standard Streams initialization helpers */
94 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
96 ConStreamInit(StdIn , stdin , (Mode), (CacheCodePage)); \
97 ConStreamInit(StdOut, stdout, (Mode), (CacheCodePage)); \
98 ConStreamInit(StdErr, stderr, (Mode), (CacheCodePage)); \
101 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
103 ConStreamInit(StdIn , GetStdHandle(STD_INPUT_HANDLE) , (Mode), (CacheCodePage)); \
104 ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), (Mode), (CacheCodePage)); \
105 ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , (Mode), (CacheCodePage)); \
107 #endif /* defined(USE_CRT) */
111 * Use UTF8 by default for file output, because this mode is back-compatible
112 * with ANSI, and it displays nice on terminals that support UTF8 by default
113 * (not many terminals support UTF16 on the contrary).
115 #define ConInitStdStreams() \
116 ConInitStdStreamsAndMode(UTF8Text, INVALID_CP); // Cache code page unused
118 /* Use ANSI by default for file output */
119 #define ConInitStdStreams() \
120 ConInitStdStreamsAndMode(AnsiText, INVALID_CP);
121 #endif /* defined(_UNICODE) */
123 /* Stream translation modes */
126 IN PCON_STREAM Stream
,
127 IN CON_STREAM_MODE Mode
,
128 IN UINT CacheCodePage OPTIONAL
);
132 #warning The ConStreamSetCacheCodePage function does not make much sense with the CRT!
135 ConStreamSetCacheCodePage(
136 IN PCON_STREAM Stream
,
137 IN UINT CacheCodePage
);
141 ConStreamGetOSHandle(
142 IN PCON_STREAM Stream
);
145 ConStreamSetOSHandle(
146 IN PCON_STREAM Stream
,
151 * Console I/O utility API
152 * (for the moment, only Output)
158 IN PCON_STREAM Stream
,
164 IN PCON_STREAM Stream
,
170 IN PCON_STREAM Stream
,
175 IN PCON_STREAM Stream
,
177 IN
va_list args
); // arg_ptr
182 IN PCON_STREAM Stream
,
188 IN PCON_STREAM Stream
,
189 IN HINSTANCE hInstance OPTIONAL
,
194 IN PCON_STREAM Stream
,
199 IN PCON_STREAM Stream
,
200 IN HINSTANCE hInstance OPTIONAL
,
202 IN
va_list args
); // arg_ptr
206 IN PCON_STREAM Stream
,
208 IN
va_list args
); // arg_ptr
213 IN PCON_STREAM Stream
,
214 IN HINSTANCE hInstance OPTIONAL
,
221 IN PCON_STREAM Stream
,
227 IN PCON_STREAM Stream
,
229 IN LPCVOID lpSource OPTIONAL
,
230 IN DWORD dwMessageId
,
231 IN DWORD dwLanguageId
);
235 IN PCON_STREAM Stream
,
237 IN LPCVOID lpSource OPTIONAL
,
238 IN DWORD dwMessageId
,
239 IN DWORD dwLanguageId
,
240 IN
va_list args
); // arg_ptr
244 IN PCON_STREAM Stream
,
246 IN LPCVOID lpSource OPTIONAL
,
247 IN DWORD dwMessageId
,
248 IN DWORD dwLanguageId
,
249 IN
va_list args
); // arg_ptr
254 IN PCON_STREAM Stream
,
256 IN LPCVOID lpSource OPTIONAL
,
257 IN DWORD dwMessageId
,
258 IN DWORD dwLanguageId
,
264 ConClearLine(IN PCON_STREAM Stream
);
267 #endif /* __STREAM_H__ */