2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Utilities Library
4 * FILE: sdk/lib/conutils/conutils.h
5 * PURPOSE: Provides simple ready-to-use abstraction wrappers around
6 * CRT streams or Win32 console API I/O functions, to deal with
7 * i18n + Unicode related problems.
8 * PROGRAMMERS: - Hermes Belusca-Maito (for making this library);
9 * - All programmers who wrote the different console applications
10 * from which I took those functions and improved them.
13 #ifndef __CONUTILS_H__
14 #define __CONUTILS_H__
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 only supports compilation with _UNICODE defined, at the moment!
29 * General-purpose utility functions (wrappers around,
30 * or reimplementations of, Win32 APIs).
36 IN HINSTANCE hInstance OPTIONAL
,
45 IN LPCVOID lpSource OPTIONAL
,
47 IN DWORD dwLanguageId
,
50 IN
va_list *Arguments OPTIONAL
);
58 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
59 * for more information.
61 typedef enum _CON_STREAM_MODE
63 Binary
= 0, // #define _O_BINARY 0x8000 // file mode is binary (untranslated)
64 // #define _O_RAW _O_BINARY
65 AnsiText
, // #define _O_TEXT 0x4000 // file mode is text (translated) -- "ANSI"
66 WideText
, // #define _O_WTEXT 0x10000 // file mode is UTF16 with BOM (translated) -- "Unicode" of Windows
67 UTF16Text
, // #define _O_U16TEXT 0x20000 // file mode is UTF16 no BOM (translated) -- "" ""
68 UTF8Text
, // #define _O_U8TEXT 0x40000 // file mode is UTF8 no BOM (translated)
69 } CON_STREAM_MODE
, *PCON_STREAM_MODE
;
71 // Shadow type, implementation-specific
72 typedef struct _CON_STREAM CON_STREAM
, *PCON_STREAM
;
75 typedef INT (__stdcall
*CON_WRITE_FUNC
)(IN PCON_STREAM
, IN PTCHAR
, IN DWORD
);
78 * Standard console streams, initialized by
79 * calls to ConStreamInit/ConInitStdStreams.
82 extern CON_STREAM StdStreams
[3];
83 #define StdIn (&StdStreams[0]) // TODO!
84 #define StdOut (&StdStreams[1])
85 #define StdErr (&StdStreams[2])
87 extern CON_STREAM csStdIn
;
88 extern CON_STREAM csStdOut
;
89 extern CON_STREAM csStdErr
;
90 #define StdIn (&csStdIn) // TODO!
91 #define StdOut (&csStdOut)
92 #define StdErr (&csStdErr)
97 IsConsoleHandle(IN HANDLE hHandle
);
101 OUT PCON_STREAM Stream
,
103 IN CON_STREAM_MODE Mode
,
104 IN CON_WRITE_FUNC WriteFunc OPTIONAL
);
108 OUT PCON_STREAM Stream
,
110 IN CON_STREAM_MODE Mode
);
113 /* Console Standard Streams initialization helpers */
117 #define ConInitStdStreams() \
119 ConStreamInit(StdOut, stdout, UTF16Text); \
120 ConStreamInit(StdErr, stderr, UTF16Text); \
123 #define ConInitStdStreams() \
125 ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), UTF16Text); \
126 ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , UTF16Text); \
128 #endif /* defined(USE_CRT) */
133 #define ConInitStdStreams() \
135 ConStreamInit(StdOut, stdout, AnsiText); \
136 ConStreamInit(StdErr, stderr, AnsiText); \
139 #define ConInitStdStreams() \
141 ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), AnsiText); \
142 ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , AnsiText); \
144 #endif /* defined(USE_CRT) */
146 #endif /* defined(_UNICODE) */
151 * Console I/O utility API
152 * (for the moment, only Output)
155 /*** Redundant defines to keep compat with existing code for now... ***/
156 /*** Must be removed later! ***/
158 #define CON_RC_STRING_MAX_SIZE 4096
159 #define MAX_BUFFER_SIZE 4096 // some exotic programs set it to 5024
160 #define OUTPUT_BUFFER_SIZE 4096
163 // #define MAX_MESSAGE_SIZE 512
169 IN PCON_STREAM Stream
,
175 IN PCON_STREAM Stream
,
177 IN
va_list args
); // arg_ptr
181 IN PCON_STREAM Stream
,
187 IN PCON_STREAM Stream
,
189 IN
va_list args
); // arg_ptr
193 IN PCON_STREAM Stream
,
199 IN PCON_STREAM Stream
,
201 IN LPCVOID lpSource OPTIONAL
,
202 IN DWORD dwMessageId
,
203 IN DWORD dwLanguageId
,
204 IN
va_list args
); // arg_ptr
208 IN PCON_STREAM Stream
,
210 IN LPCVOID lpSource OPTIONAL
,
211 IN DWORD dwMessageId
,
212 IN DWORD dwLanguageId
,
213 IN
va_list args
); // arg_ptr
217 IN PCON_STREAM Stream
,
219 IN LPCVOID lpSource OPTIONAL
,
220 IN DWORD dwMessageId
,
221 IN DWORD dwLanguageId
,
226 * Those are compatibility #defines for old code!
231 #define PrintStringV(szStr, args) \
232 ConPrintfV(StdOut, (szStr), (args))
233 #define PrintString(szStr, ...) \
234 ConPrintf(StdOut, (szStr), ##__VA_ARGS__)
236 /*** network/net/main.c ***/
237 #define PrintToConsole(szStr, ...) \
238 ConPrintf(StdOut, (szStr), ##__VA_ARGS__)
240 /*** clip.c, comp.c, help.c, tree.c ***/
242 /*** format.c, network/net/main.c, shutdown.c, wlanconf.c, diskpart.c ***/
244 #define PrintResourceStringV(uID, args) \
245 ConResPrintfV(StdOut, (uID), (args))
246 #define PrintResourceString(uID, ...) \
247 ConResPrintf(StdOut, (uID), ##__VA_ARGS__)
250 // TODO: Add Console paged-output printf & ResPrintf functions!
253 #endif /* __CONUTILS_H__ */