ReactOS 0.4.15-dev-7788-g1ad9096
stream.h
Go to the documentation of this file.
1/*
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
6 * related problems.
7 * COPYRIGHT: Copyright 2017-2018 ReactOS Team
8 * Copyright 2017-2018 Hermes Belusca-Maito
9 */
10
18#ifndef __STREAM_H__
19#define __STREAM_H__
20
21#pragma once
22
23/*
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
27 */
29// #define USE_CRT
30
31#ifndef _UNICODE
32#error The ConUtils library at the moment only supports compilation with _UNICODE defined!
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/*
40 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
41 * for more information.
42 */
43typedef enum _CON_STREAM_MODE
44{
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)
52
53#define INVALID_CP ((UINT)-1)
54
55// Shadow type, implementation-specific
57
58// typedef INT (__stdcall *CON_READ_FUNC)(
59 // IN PCON_STREAM Stream,
60 // OUT PTCHAR szStr,
61 // IN OUT PDWORD len);
62
65 IN PCTCH szStr,
66 IN DWORD len);
67
68/*
69 * Standard console streams, initialized by
70 * calls to ConStreamInit/ConInitStdStreams.
71 */
72#if 0 // FIXME!
73extern CON_STREAM StdStreams[3];
74#define StdIn (&StdStreams[0])
75#define StdOut (&StdStreams[1])
76#define StdErr (&StdStreams[2])
77#else
78extern CON_STREAM csStdIn;
79extern CON_STREAM csStdOut;
80extern CON_STREAM csStdErr;
81#define StdIn (&csStdIn )
82#define StdOut (&csStdOut)
83#define StdErr (&csStdErr)
84#endif
85
86BOOL
91 IN UINT CacheCodePage OPTIONAL,
92 // IN ReadWriteMode ????
93 // IN CON_READ_FUNC ReadFunc OPTIONAL,
95
96BOOL
100 // IN ReadWriteMode ????
102 IN UINT CacheCodePage OPTIONAL);
103
104
105/* Console Standard Streams initialization helpers */
106#ifdef USE_CRT
107#define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
108do { \
109 ConStreamInit(StdIn , stdin , (Mode), (CacheCodePage)); \
110 ConStreamInit(StdOut, stdout, (Mode), (CacheCodePage)); \
111 ConStreamInit(StdErr, stderr, (Mode), (CacheCodePage)); \
112} while(0)
113#else
114#define ConInitStdStreamsAndMode(Mode, CacheCodePage) \
115do { \
116 ConStreamInit(StdIn , GetStdHandle(STD_INPUT_HANDLE) , (Mode), (CacheCodePage)); \
117 ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), (Mode), (CacheCodePage)); \
118 ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , (Mode), (CacheCodePage)); \
119} while(0)
120#endif /* defined(USE_CRT) */
121
122/*
123 * Use ANSI by default for file output, with no cached code page.
124 * Note that setting the stream mode to AnsiText and the code page value
125 * to CP_UTF8 sets the stream to UTF8 mode, and has the same effect as if
126 * the stream mode UTF8Text had been specified instead.
127 */
128#define ConInitStdStreams() \
129 ConInitStdStreamsAndMode(AnsiText, INVALID_CP)
130
131/* Stream translation modes */
132BOOL
136 IN UINT CacheCodePage OPTIONAL);
137
138#ifdef USE_CRT
139
140// FIXME!
141#warning The ConStreamSetCacheCodePage function does not make much sense with the CRT!
142
143#define ConStdStreamsSetCacheCodePage(InputCodePage, OutputCodePage) NOTHING
144
145#else
146
147BOOL
150 IN UINT CacheCodePage);
151
152#define ConStdStreamsSetCacheCodePage(InputCodePage, OutputCodePage) \
153do { \
154 ConStreamSetCacheCodePage(StdIn , (InputCodePage )); \
155 ConStreamSetCacheCodePage(StdOut, (OutputCodePage)); \
156 ConStreamSetCacheCodePage(StdErr, (OutputCodePage)); \
157} while(0)
158
159#endif /* defined(USE_CRT) */
160
161HANDLE
164
165BOOL
169
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif /* __STREAM_H__ */
176
177/* EOF */
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
GLenum GLsizei len
Definition: glext.h:6722
_In_ ULONG Mode
Definition: hubbusif.h:303
static IStream Stream
Definition: htmldoc.c:1115
unsigned int UINT
Definition: ndis.h:50
LPCCH PCTCH
Definition: ntbasedef.h:486
#define INT
Definition: polytest.cpp:20
static const PCON_STREAM StdStreams[]
Definition: redir.c:36
_CON_STREAM_MODE
Definition: stream.h:44
@ AnsiText
Definition: stream.h:47
@ UTF16Text
Definition: stream.h:49
@ WideText
Definition: stream.h:48
@ Binary
Definition: stream.h:45
@ UTF8Text
Definition: stream.h:50
enum _CON_STREAM_MODE CON_STREAM_MODE
CON_STREAM csStdErr
Definition: stream.c:61
BOOL ConStreamInitEx(OUT PCON_STREAM Stream, IN PVOID Handle, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL, IN CON_WRITE_FUNC WriteFunc OPTIONAL)
Definition: stream.c:127
BOOL ConStreamSetOSHandle(IN PCON_STREAM Stream, IN HANDLE Handle)
Definition: stream.c:263
BOOL ConStreamSetCacheCodePage(IN PCON_STREAM Stream, IN UINT CacheCodePage)
Definition: stream.c:215
BOOL ConStreamSetMode(IN PCON_STREAM Stream, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL)
Definition: stream.c:195
CON_STREAM csStdIn
Definition: stream.c:59
BOOL ConStreamInit(OUT PCON_STREAM Stream, IN PVOID Handle, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL)
Definition: stream.c:185
CON_STREAM csStdOut
Definition: stream.c:60
struct _CON_STREAM * PCON_STREAM
Definition: stream.h:56
INT(__stdcall * CON_WRITE_FUNC)(IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
Definition: stream.h:63
enum _CON_STREAM_MODE * PCON_STREAM_MODE
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
CON_WRITE_FUNC WriteFunc
#define __stdcall
Definition: typedefs.h:25
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40