[CONUTILS] Fix macro definition.
[reactos.git] / sdk / lib / conutils / stream.h
1 /*
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
7 * related problems.
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.
11 */
12
13 #ifndef __STREAM_H__
14 #define __STREAM_H__
15
16 /*
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
20 */
21 /** NOTE: Experimental! Don't use USE_CRT yet because output to console is a bit broken **/
22 // #define USE_CRT
23
24 #ifndef _UNICODE
25 #error The ConUtils library at the moment only supports compilation with _UNICODE defined!
26 #endif
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /*
33 * Console I/O streams
34 */
35
36 /*
37 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
38 * for more information.
39 */
40 typedef enum _CON_STREAM_MODE
41 {
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;
49
50 #define INVALID_CP ((UINT)-1)
51
52 // Shadow type, implementation-specific
53 typedef struct _CON_STREAM CON_STREAM, *PCON_STREAM;
54
55 // typedef INT (__stdcall *CON_READ_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
56 // Stream, szStr, len
57 typedef INT (__stdcall *CON_WRITE_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
58
59 /*
60 * Standard console streams, initialized by
61 * calls to ConStreamInit/ConInitStdStreams.
62 */
63 #if 0 // FIXME!
64 extern CON_STREAM StdStreams[3];
65 #define StdIn (&StdStreams[0])
66 #define StdOut (&StdStreams[1])
67 #define StdErr (&StdStreams[2])
68 #else
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)
75 #endif
76
77 BOOL
78 ConStreamInitEx(
79 OUT PCON_STREAM Stream,
80 IN PVOID Handle,
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);
86
87 BOOL
88 ConStreamInit(
89 OUT PCON_STREAM Stream,
90 IN PVOID Handle,
91 // IN ReadWriteMode ????
92 IN CON_STREAM_MODE Mode,
93 IN UINT CacheCodePage OPTIONAL);
94
95
96 /* Console Standard Streams initialization helpers */
97 #ifdef USE_CRT
98 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
99 do { \
100 ConStreamInit(StdIn , stdin , (Mode), (CacheCodePage)); \
101 ConStreamInit(StdOut, stdout, (Mode), (CacheCodePage)); \
102 ConStreamInit(StdErr, stderr, (Mode), (CacheCodePage)); \
103 } while(0)
104 #else
105 #define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
106 do { \
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)); \
110 } while(0)
111 #endif /* defined(USE_CRT) */
112
113 #ifdef _UNICODE
114 /*
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).
118 */
119 #define ConInitStdStreams() \
120 ConInitStdStreamsAndMode(UTF8Text, INVALID_CP)
121 /* Note that here the cache code page is unused */
122 #else
123 /* Use ANSI by default for file output */
124 #define ConInitStdStreams() \
125 ConInitStdStreamsAndMode(AnsiText, INVALID_CP)
126 #endif /* defined(_UNICODE) */
127
128 /* Stream translation modes */
129 BOOL
130 ConStreamSetMode(
131 IN PCON_STREAM Stream,
132 IN CON_STREAM_MODE Mode,
133 IN UINT CacheCodePage OPTIONAL);
134
135 #ifdef USE_CRT
136 // FIXME!
137 #warning The ConStreamSetCacheCodePage function does not make much sense with the CRT!
138 #else
139 BOOL
140 ConStreamSetCacheCodePage(
141 IN PCON_STREAM Stream,
142 IN UINT CacheCodePage);
143 #endif
144
145 HANDLE
146 ConStreamGetOSHandle(
147 IN PCON_STREAM Stream);
148
149 BOOL
150 ConStreamSetOSHandle(
151 IN PCON_STREAM Stream,
152 IN HANDLE Handle);
153
154
155 /*
156 * Console I/O utility API
157 * (for the moment, only Output)
158 */
159
160 INT
161 __stdcall
162 ConWrite(
163 IN PCON_STREAM Stream,
164 IN PTCHAR szStr,
165 IN DWORD len);
166
167 INT
168 ConStreamWrite(
169 IN PCON_STREAM Stream,
170 IN PTCHAR szStr,
171 IN DWORD len);
172
173 INT
174 ConPuts(
175 IN PCON_STREAM Stream,
176 IN LPWSTR szStr);
177
178 INT
179 ConPrintfV(
180 IN PCON_STREAM Stream,
181 IN LPWSTR szStr,
182 IN va_list args); // arg_ptr
183
184 INT
185 __cdecl
186 ConPrintf(
187 IN PCON_STREAM Stream,
188 IN LPWSTR szStr,
189 ...);
190
191 INT
192 ConResPutsEx(
193 IN PCON_STREAM Stream,
194 IN HINSTANCE hInstance OPTIONAL,
195 IN UINT uID);
196
197 INT
198 ConResPuts(
199 IN PCON_STREAM Stream,
200 IN UINT uID);
201
202 INT
203 ConResPrintfExV(
204 IN PCON_STREAM Stream,
205 IN HINSTANCE hInstance OPTIONAL,
206 IN UINT uID,
207 IN va_list args); // arg_ptr
208
209 INT
210 ConResPrintfV(
211 IN PCON_STREAM Stream,
212 IN UINT uID,
213 IN va_list args); // arg_ptr
214
215 INT
216 __cdecl
217 ConResPrintfEx(
218 IN PCON_STREAM Stream,
219 IN HINSTANCE hInstance OPTIONAL,
220 IN UINT uID,
221 ...);
222
223 INT
224 __cdecl
225 ConResPrintf(
226 IN PCON_STREAM Stream,
227 IN UINT uID,
228 ...);
229
230 INT
231 ConMsgPuts(
232 IN PCON_STREAM Stream,
233 IN DWORD dwFlags,
234 IN LPCVOID lpSource OPTIONAL,
235 IN DWORD dwMessageId,
236 IN DWORD dwLanguageId);
237
238 INT
239 ConMsgPrintf2V(
240 IN PCON_STREAM Stream,
241 IN DWORD dwFlags,
242 IN LPCVOID lpSource OPTIONAL,
243 IN DWORD dwMessageId,
244 IN DWORD dwLanguageId,
245 IN va_list args); // arg_ptr
246
247 INT
248 ConMsgPrintfV(
249 IN PCON_STREAM Stream,
250 IN DWORD dwFlags,
251 IN LPCVOID lpSource OPTIONAL,
252 IN DWORD dwMessageId,
253 IN DWORD dwLanguageId,
254 IN va_list args); // arg_ptr
255
256 INT
257 __cdecl
258 ConMsgPrintf(
259 IN PCON_STREAM Stream,
260 IN DWORD dwFlags,
261 IN LPCVOID lpSource OPTIONAL,
262 IN DWORD dwMessageId,
263 IN DWORD dwLanguageId,
264 ...);
265
266
267
268 VOID
269 ConClearLine(IN PCON_STREAM Stream);
270
271
272 #ifdef __cplusplus
273 }
274 #endif
275 #endif /* __STREAM_H__ */