ReactOS 0.4.16-dev-306-g647d351
console.c File Reference
#include "precomp.h"
#include <cjkcode.h>
#include "wcwidth.c"
Include dependency graph for console.c:

Go to the source code of this file.

Macros

#define OUTPUT_BUFFER_SIZE   4096
 
#define IS_FULL_WIDTH(wch)    (((USHORT)(wch) >= 0x0080) && (mk_wcwidth_cjk(wch) == 2))
 

Functions

VOID ConInDisable (VOID)
 
VOID ConInEnable (VOID)
 
VOID ConInFlush (VOID)
 
VOID ConInKey (PINPUT_RECORD lpBuffer)
 
VOID ConInString (LPWSTR lpInput, DWORD dwLength)
 
VOID ConOutChar (WCHAR c)
 
VOID ConErrChar (WCHAR c)
 
VOID __cdecl ConFormatMessage (PCON_STREAM Stream, DWORD MessageId,...)
 
BOOL ConPrintfVPaging (PCON_PAGER Pager, BOOL StartPaging, LPWSTR szFormat, va_list arg_ptr)
 
BOOL __cdecl ConOutPrintfPaging (BOOL StartPaging, LPWSTR szFormat,...)
 
VOID ConOutResPaging (BOOL StartPaging, UINT resID)
 
VOID SetCursorXY (SHORT x, SHORT y)
 
VOID GetCursorXY (PSHORT x, PSHORT y)
 
SHORT GetCursorX (VOID)
 
SHORT GetCursorY (VOID)
 
VOID SetCursorType (BOOL bInsert, BOOL bVisible)
 
VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
 
BOOL ConGetDefaultAttributes (PWORD pwDefAttr)
 
BOOL ConSetTitle (IN LPCWSTR lpConsoleTitle)
 
VOID ConRingBell (HANDLE hOutput)
 
BOOL ConSetScreenColor (HANDLE hOutput, WORD wColor, BOOL bFill)
 
SIZE_T ConGetTextWidthW (PCWSTR pszText)
 
SIZE_T ConGetTextWidthA (PCSTR pszText)
 

Variables

UINT InputCodePage
 
UINT OutputCodePage
 
CON_SCREEN StdOutScreen = INIT_CON_SCREEN(StdOut)
 
CON_PAGER StdOutPager = INIT_CON_PAGER(&StdOutScreen)
 

Macro Definition Documentation

◆ IS_FULL_WIDTH

#define IS_FULL_WIDTH (   wch)     (((USHORT)(wch) >= 0x0080) && (mk_wcwidth_cjk(wch) == 2))

Definition at line 333 of file console.c.

◆ OUTPUT_BUFFER_SIZE

#define OUTPUT_BUFFER_SIZE   4096

Definition at line 22 of file console.c.

Function Documentation

◆ ConErrChar()

VOID ConErrChar ( WCHAR  c)

Definition at line 124 of file console.c.

125{
126 ConWrite(StdErr, &c, 1);
127}
#define StdErr
Definition: fc.c:15
const GLubyte * c
Definition: glext.h:8905
INT __stdcall ConWrite(IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
Definition: outstream.c:85

◆ ConFormatMessage()

VOID __cdecl ConFormatMessage ( PCON_STREAM  Stream,
DWORD  MessageId,
  ... 
)

Definition at line 129 of file console.c.

130{
131 INT Len;
132 va_list arg_ptr;
133
134 va_start(arg_ptr, MessageId);
137 NULL,
138 MessageId,
140 &arg_ptr);
141 va_end(arg_ptr);
142
143 if (Len <= 0)
145}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define STRING_CONSOLE_ERROR
Definition: resource.h:6
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define Len
Definition: deflate.h:82
#define NULL
Definition: types.h:112
static IStream Stream
Definition: htmldoc.c:1115
INT ConMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1030
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
int32_t INT
Definition: typedefs.h:58
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449

◆ ConGetDefaultAttributes()

BOOL ConGetDefaultAttributes ( PWORD  pwDefAttr)

Definition at line 251 of file console.c.

252{
254 HANDLE hConsole;
256
257 /* Do not modify *pwDefAttr if we fail, in which case use default attributes */
258
259 hConsole = CreateFile(_T("CONOUT$"), GENERIC_READ|GENERIC_WRITE,
261 OPEN_EXISTING, 0, NULL);
262 if (hConsole == INVALID_HANDLE_VALUE)
263 return FALSE; // No default console
264
265 Success = GetConsoleScreenBufferInfo(hConsole, &csbi);
266 if (Success)
267 *pwDefAttr = csbi.wAttributes;
268
269 CloseHandle(hConsole);
270 return Success;
271}
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
#define _T(x)
Definition: vfdio.h:22
#define CreateFile
Definition: winbase.h:3774

Referenced by Initialize().

◆ ConGetTextWidthA()

SIZE_T ConGetTextWidthA ( PCSTR  pszText)

Definition at line 354 of file console.c.

355{
356 int cchMax;
357 PWSTR pszWide;
358 SIZE_T cxWidth;
359
360 cchMax = MultiByteToWideChar(OutputCodePage, 0, pszText, -1, NULL, 0);
361 pszWide = cmd_alloc(cchMax * sizeof(WCHAR));
362 MultiByteToWideChar(OutputCodePage, 0, pszText, -1, pszWide, cchMax);
363 cxWidth = ConGetTextWidthW(pszWide);
364 cmd_free(pszWide);
365 return cxWidth;
366}
UINT cchMax
SIZE_T ConGetTextWidthW(PCWSTR pszText)
Definition: console.c:336
UINT OutputCodePage
Definition: console.c:26
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define MultiByteToWideChar
Definition: compat.h:110
uint16_t * PWSTR
Definition: typedefs.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:80
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ ConGetTextWidthW()

SIZE_T ConGetTextWidthW ( PCWSTR  pszText)

Definition at line 336 of file console.c.

337{
338 SIZE_T ich, cxWidth;
339
341 return _tcslen(pszText);
342
343 for (ich = cxWidth = 0; pszText[ich]; ++ich)
344 {
345 if (IS_FULL_WIDTH(pszText[ich]))
346 cxWidth += 2;
347 else
348 ++cxWidth;
349 }
350
351 return cxWidth;
352}
#define IS_FULL_WIDTH(wch)
Definition: console.c:333
#define IsCJKCodePage(CodePage)
Definition: cjkcode.h:27
#define _tcslen
Definition: xmlstorage.h:198

Referenced by ConGetTextWidthA().

◆ ConInDisable()

VOID ConInDisable ( VOID  )

Definition at line 36 of file console.c.

37{
39 DWORD dwMode;
40
41 GetConsoleMode(hInput, &dwMode);
42 dwMode &= ~ENABLE_PROCESSED_INPUT;
43 SetConsoleMode(hInput, dwMode);
44}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STD_INPUT_HANDLE
Definition: winbase.h:293

Referenced by FilePromptYN(), FilePromptYNA(), and PagePrompt().

◆ ConInEnable()

VOID ConInEnable ( VOID  )

Definition at line 46 of file console.c.

47{
49 DWORD dwMode;
50
51 GetConsoleMode(hInput, &dwMode);
52 dwMode |= ENABLE_PROCESSED_INPUT;
53 SetConsoleMode(hInput, dwMode);
54}
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:78

Referenced by FilePromptYN(), FilePromptYNA(), and PagePrompt().

◆ ConInFlush()

VOID ConInFlush ( VOID  )

Definition at line 56 of file console.c.

57{
59}
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:220

Referenced by CommandChoice().

◆ ConInKey()

VOID ConInKey ( PINPUT_RECORD  lpBuffer)

Definition at line 61 of file console.c.

62{
64 DWORD dwRead;
65
66 if (hInput == INVALID_HANDLE_VALUE)
67 WARN ("Invalid input handle!!!\n");
68
69 do
70 {
71 ReadConsoleInput(hInput, lpBuffer, 1, &dwRead);
72 if (lpBuffer->EventType == KEY_EVENT &&
73 lpBuffer->Event.KeyEvent.bKeyDown)
74 {
75 break;
76 }
77 }
78 while (TRUE);
79}
#define WARN(fmt,...)
Definition: precomp.h:61
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define TRUE
Definition: types.h:120
#define ReadConsoleInput
Definition: wincon.h:778
#define KEY_EVENT
Definition: wincon.h:128

Referenced by CommandChoice(), FilePromptYN(), FilePromptYNA(), PagePrompt(), and ReadCommand().

◆ ConInString()

VOID ConInString ( LPWSTR  lpInput,
DWORD  dwLength 
)

Definition at line 81 of file console.c.

82{
83 DWORD dwOldMode;
84 DWORD dwRead = 0;
86
87 LPWSTR p;
88 PCHAR pBuf;
89
90 pBuf = (PCHAR)cmd_alloc(dwLength - 1);
91
92 ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
94 GetConsoleMode(hFile, &dwOldMode);
95
97
98 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
99
100 MultiByteToWideChar(InputCodePage, 0, pBuf, dwRead, lpInput, dwLength - 1);
101 cmd_free(pBuf);
102
103 for (p = lpInput; *p; p++)
104 {
105 if (*p == L'\r') // Terminate at the carriage-return.
106 {
107 *p = L'\0';
108 break;
109 }
110 }
111
112 SetConsoleMode(hFile, dwOldMode);
113}
UINT InputCodePage
Definition: console.c:25
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
static DWORD DWORD * dwLength
Definition: fusion.c:86
GLfloat GLfloat p
Definition: glext.h:8902
#define PCHAR
Definition: match.c:90
_In_ HANDLE hFile
Definition: mswsock.h:90
#define L(x)
Definition: ntvdm.h:50
char * PCHAR
Definition: typedefs.h:51
#define ZeroMemory
Definition: winbase.h:1737
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ ConOutChar()

VOID ConOutChar ( WCHAR  c)

Definition at line 119 of file console.c.

120{
121 ConWrite(StdOut, &c, 1);
122}
#define StdOut
Definition: fc.c:14

◆ ConOutPrintfPaging()

BOOL __cdecl ConOutPrintfPaging ( BOOL  StartPaging,
LPWSTR  szFormat,
  ... 
)

Definition at line 167 of file console.c.

168{
169 BOOL bRet;
170 va_list arg_ptr;
171
172 va_start(arg_ptr, szFormat);
173 bRet = ConPrintfVPaging(&StdOutPager, StartPaging, szFormat, arg_ptr);
174 va_end(arg_ptr);
175 return bRet;
176}
CON_PAGER StdOutPager
Definition: console.c:30
BOOL ConPrintfVPaging(PCON_PAGER Pager, BOOL StartPaging, LPWSTR szFormat, va_list arg_ptr)
Definition: console.c:151

Referenced by cmd_type(), CommandDir(), and DoTypeFile().

◆ ConOutResPaging()

VOID ConOutResPaging ( BOOL  StartPaging,
UINT  resID 
)

Definition at line 178 of file console.c.

179{
180 ConResPaging(&StdOutPager, PagePrompt, StartPaging, resID);
181}
static BOOL __stdcall PagePrompt(PCON_PAGER Pager, DWORD Done, DWORD Total)
Definition: more.c:160
BOOL ConResPaging(IN PCON_PAGER Pager, IN PAGE_PROMPT PagePrompt, IN BOOL StartPaging, IN UINT uID)
Definition: pager.c:681

Referenced by cmd_beep(), cmd_call(), cmd_chdir(), cmd_cls(), cmd_copy(), cmd_ctty(), cmd_date(), cmd_for(), cmd_goto(), cmd_if(), cmd_mkdir(), cmd_move(), cmd_path(), cmd_pause(), cmd_prompt(), cmd_rename(), cmd_rmdir(), cmd_set(), cmd_shift(), cmd_start(), cmd_time(), cmd_title(), cmd_type(), cmd_ver(), cmd_verify(), cmd_vol(), CommandAlias(), CommandAssoc(), CommandChoice(), CommandColor(), CommandDelay(), CommandDelete(), CommandEcho(), CommandExit(), CommandFree(), CommandMemory(), CommandRem(), CommandScreen(), DirHelp(), and Initialize().

◆ ConPrintfVPaging()

BOOL ConPrintfVPaging ( PCON_PAGER  Pager,
BOOL  StartPaging,
LPWSTR  szFormat,
va_list  arg_ptr 
)

Definition at line 151 of file console.c.

152{
153 // INT len;
155
156 /* Return if no string has been given */
157 if (szFormat == NULL)
158 return TRUE;
159
160 /*len =*/ vswprintf(szOut, szFormat, arg_ptr);
161
162 // return ConPutsPaging(Pager, PagePrompt, StartPaging, szOut);
163 return ConWritePaging(Pager, PagePrompt, StartPaging,
164 szOut, wcslen(szOut));
165}
#define OUTPUT_BUFFER_SIZE
Definition: console.c:22
static _Check_return_opt_ int __cdecl vswprintf(_Out_writes_z_(_SizeInWords) wchar_t *_DstBuf, _In_ size_t _SizeInWords, _In_z_ _Printf_format_string_ const wchar_t *_Format, va_list _ArgList)
Definition: stdio.h:977
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL ConWritePaging(IN PCON_PAGER Pager, IN PAGE_PROMPT PagePrompt, IN BOOL StartPaging, IN PCTCH szStr, IN DWORD len)
Definition: pager.c:549

Referenced by ConOutPrintfPaging(), and DirPrintf().

◆ ConRingBell()

VOID ConRingBell ( HANDLE  hOutput)

Definition at line 283 of file console.c.

284{
285#if 0
286 /* Emit an error beep sound */
287 if (IsConsoleHandle(hOutput))
288 Beep(800, 200);
289 else if (IsTTYHandle(hOutput))
290 ConOutPuts(_T("\a")); // BEL character 0x07
291 else
292#endif
293 MessageBeep(-1);
294}
#define ConOutPuts(szStr)
Definition: console.h:29
BOOL WINAPI Beep(IN DWORD dwFreq, IN DWORD dwDuration)
Definition: deviceio.c:48
#define IsConsoleHandle(h)
Definition: console.h:14
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:393
BOOL WINAPI MessageBeep(_In_ UINT uType)

Referenced by cmd_beep().

◆ ConSetScreenColor()

BOOL ConSetScreenColor ( HANDLE  hOutput,
WORD  wColor,
BOOL  bFill 
)

Definition at line 298 of file console.c.

299{
300 DWORD dwWritten;
302 COORD coPos;
303
304 /* Foreground and Background colors can't be the same */
305 if ((wColor & 0x0F) == (wColor & 0xF0) >> 4)
306 return FALSE;
307
308 /* Fill the whole background if needed */
309 if (bFill)
310 {
311 GetConsoleScreenBufferInfo(hOutput, &csbi);
312
313 coPos.X = 0;
314 coPos.Y = 0;
316 wColor & 0x00FF,
317 csbi.dwSize.X * csbi.dwSize.Y,
318 coPos,
319 &dwWritten);
320 }
321
322 /* Set the text attribute */
323 SetConsoleTextAttribute(hOutput, wColor & 0x00FF);
324 return TRUE;
325}
BOOL WINAPI SetConsoleTextAttribute(IN HANDLE hConsoleOutput, IN WORD wAttributes)
Definition: console.c:672
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:525
WORD wColor
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
SHORT Y
Definition: blue.h:27
SHORT X
Definition: blue.h:26

Referenced by CommandColor(), and Initialize().

◆ ConSetTitle()

BOOL ConSetTitle ( IN LPCWSTR  lpConsoleTitle)

Definition at line 276 of file console.c.

277{
278 /* Now really set the console title */
279 return SetConsoleTitle(lpConsoleTitle);
280}
#define SetConsoleTitle
Definition: wincon.h:783

Referenced by cmd_title(), ResetConTitle(), and SetConTitle().

◆ GetCursorX()

SHORT GetCursorX ( VOID  )

Definition at line 206 of file console.c.

207{
209
211 return csbi.dwCursorPosition.X;
212}
#define STD_OUTPUT_HANDLE
Definition: winbase.h:294

Referenced by ReadCommand().

◆ GetCursorXY()

VOID GetCursorXY ( PSHORT  x,
PSHORT  y 
)

Definition at line 196 of file console.c.

197{
199
201
202 *x = csbi.dwCursorPosition.X;
203 *y = csbi.dwCursorPosition.Y;
204}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548

Referenced by ReadCommand().

◆ GetCursorY()

SHORT GetCursorY ( VOID  )

Definition at line 214 of file console.c.

Referenced by PagePrompt(), PrintPrompt(), and ReadCommand().

◆ GetScreenSize()

VOID GetScreenSize ( PSHORT  maxx,
PSHORT  maxy 
)

Definition at line 232 of file console.c.

233{
235
237 {
238 csbi.dwSize.X = 80;
239 csbi.dwSize.Y = 25;
240 }
241
242 if (maxx) *maxx = csbi.dwSize.X;
243 if (maxy) *maxy = csbi.dwSize.Y;
244}
SHORT maxx
Definition: cmdinput.c:115
SHORT maxy
Definition: cmdinput.c:116

Referenced by CommandScreen(), DirPrintWideList(), and PagePrompt().

◆ SetCursorType()

VOID SetCursorType ( BOOL  bInsert,
BOOL  bVisible 
)

Definition at line 222 of file console.c.

223{
225
226 cci.dwSize = bInsert ? 10 : 99;
227 cci.bVisible = bVisible;
228
230}
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:618
static BOOL bInsert
Definition: cmdinput.c:121

Referenced by ReadCommand().

◆ SetCursorXY()

VOID SetCursorXY ( SHORT  x,
SHORT  y 
)

Definition at line 187 of file console.c.

188{
189 COORD coPos;
190
191 coPos.X = x;
192 coPos.Y = y;
194}
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:641

Referenced by ClearCommandLine(), CommandScreen(), PagePrompt(), and ReadCommand().

Variable Documentation

◆ InputCodePage

UINT InputCodePage

Definition at line 25 of file console.c.

Referenced by _tmain(), cmd_start(), ConInString(), Execute(), and ReadCommand().

◆ OutputCodePage

◆ StdOutPager

Definition at line 30 of file console.c.

Referenced by ConOutPrintfPaging(), ConOutResPaging(), and DirPrintf().

◆ StdOutScreen

Definition at line 29 of file console.c.