ReactOS 0.4.16-dev-2534-gdcd45a5
util.c File Reference
#include "replace.h"
Include dependency graph for util.c:

Go to the source code of this file.

Functions

INT GetRootPath (IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
 
VOID GetPathCase (TCHAR *Path, TCHAR *OutPath)
 
BOOL IsExistingFile (IN LPCTSTR pszPath)
 
BOOL IsExistingDirectory (IN LPCTSTR pszPath)
 
INT FilePromptYNA (UINT resID)
 
VOID ConInString (LPTSTR lpInput, DWORD dwLength)
 
VOID msg_pause (VOID)
 
VOID __cdecl ConFormatMessage (PCON_STREAM Stream, DWORD MessageId,...)
 
VOID ConOutChar (TCHAR c)
 
TCHAR cgetchar (VOID)
 

Variables

BOOL bCtrlBreak = FALSE
 

Function Documentation

◆ cgetchar()

TCHAR cgetchar ( VOID  )

Definition at line 243 of file util.c.

244{
246 INPUT_RECORD irBuffer;
247 DWORD dwRead;
248
249 do
250 {
251 ReadConsoleInput(hInput, &irBuffer, 1, &dwRead);
252 if ((irBuffer.EventType == KEY_EVENT) &&
253 (irBuffer.Event.KeyEvent.bKeyDown != FALSE))
254 {
255 if (irBuffer.Event.KeyEvent.dwControlKeyState &
257 {
258 if (irBuffer.Event.KeyEvent.wVirtualKeyCode == 'C')
259 {
261 break;
262 }
263 }
264 else if ((irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
265 (irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
267 {
268 // Nothing to do
269 }
270 else
271 {
272 break;
273 }
274 }
275 }
276 while (TRUE);
277
278#ifndef _UNICODE
279 return irBuffer.Event.KeyEvent.uChar.AsciiChar;
280#else
281 return irBuffer.Event.KeyEvent.uChar.UnicodeChar;
282#endif /* _UNICODE */
283}
BOOL bCtrlBreak
Definition: util.c:11
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
union _INPUT_RECORD::@3531 Event
WORD EventType
Definition: wincon.h:294
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:296
union _KEY_EVENT_RECORD::@3530 uChar
DWORD dwControlKeyState
Definition: wincon.h:269
WORD wVirtualKeyCode
Definition: wincon.h:263
WCHAR UnicodeChar
Definition: wincon.h:266
#define STD_INPUT_HANDLE
Definition: winbase.h:291
#define LEFT_CTRL_PRESSED
Definition: wincon.h:168
#define ReadConsoleInput
Definition: wincon.h:1024
#define KEY_EVENT
Definition: wincon.h:156
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:167
#define VK_CONTROL
Definition: winuser.h:2239
#define VK_SHIFT
Definition: winuser.h:2238
#define VK_MENU
Definition: winuser.h:2240

◆ ConFormatMessage()

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

Definition at line 216 of file util.c.

217{
218 INT Len;
219 va_list arg_ptr;
220
221 va_start(arg_ptr, MessageId);
224 NULL,
225 MessageId,
227 &arg_ptr);
228 va_end(arg_ptr);
229
230 if (Len <= 0)
232}
#define STRING_CONSOLE_ERROR
Definition: resource.h:6
void ConResPrintf(FILE *fp, UINT nID,...)
#define Len
Definition: deflate.h:82
#define NULL
Definition: types.h:112
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
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:1028
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
int32_t INT
Definition: typedefs.h:58
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400

◆ ConInString()

VOID ConInString ( LPTSTR  lpInput,
DWORD  dwLength 
)

Definition at line 173 of file util.c.

174{
175 DWORD dwOldMode;
176 DWORD dwRead = 0;
178
179 LPTSTR p;
180 PCHAR pBuf;
181
182#ifdef _UNICODE
183 pBuf = (PCHAR)malloc(dwLength - 1);
184#else
185 pBuf = lpInput;
186#endif
187 ZeroMemory(lpInput, dwLength * sizeof(TCHAR));
189 GetConsoleMode(hFile, &dwOldMode);
190
192
193 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
194
195#ifdef _UNICODE
196 MultiByteToWideChar(GetConsoleCP(), 0, pBuf, dwRead, lpInput, dwLength - 1);
197 free(pBuf);
198#endif
199 for (p = lpInput; *p; p++)
200 {
201 if (*p == _T('\r')) // Terminate at the carriage-return.
202 {
203 *p = _T('\0');
204 break;
205 }
206 }
207
208 SetConsoleMode(hFile, dwOldMode);
209}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define MultiByteToWideChar
Definition: compat.h:110
static DWORD DWORD * dwLength
Definition: fusion.c:86
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(void)
Definition: console.c:821
GLfloat GLfloat p
Definition: glext.h:8902
#define ZeroMemory
Definition: minwinbase.h:31
#define PCHAR
Definition: match.c:90
_In_ HANDLE hFile
Definition: mswsock.h:90
char * PCHAR
Definition: typedefs.h:51
#define _T(x)
Definition: vfdio.h:22
#define ENABLE_ECHO_INPUT
Definition: wincon.h:109
#define ENABLE_LINE_INPUT
Definition: wincon.h:108
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:107
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by FilePromptYNA().

◆ ConOutChar()

VOID ConOutChar ( TCHAR  c)

Definition at line 234 of file util.c.

235{
236 ConWrite(StdOut, &c, 1);
237}
#define StdOut
Definition: conutils_noros.h:6
const GLubyte * c
Definition: glext.h:8905
INT __stdcall ConWrite(IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
Definition: outstream.c:84

Referenced by Batch(), CheckCtrlBreak(), ClearCommandLine(), cmd_pause(), cmd_set(), cmd_ver(), CommandEcho(), DumpCommand(), EchoCommand(), ExecuteCommandWithEcho(), Initialize(), PagePrompt(), PrintCommandList(), PrintPrompt(), ReadCommand(), and ReadLine().

◆ FilePromptYNA()

INT FilePromptYNA ( UINT  resID)

Definition at line 111 of file util.c.

112{
113 TCHAR szMsg[4];
114// TCHAR cKey = 0;
115// LPTSTR szKeys = _T("yna");
116
117 TCHAR szIn[10];
118 LPTSTR p;
119
120 if (resID != 0)
121 ConOutResPrintf(resID);
122
123 /* preliminary fix */
124 ConInString(szIn, 10);
125
126 _tcsupr(szIn);
127 for (p = szIn; _istspace(*p); p++)
128 ;
129
131
132 if (_tcsncmp(p, &szMsg[0], 1) == 0)
133 return PROMPT_YES;
134 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
135 return PROMPT_NO;
136 else if (_tcsncmp(p, &szMsg[2], 1) == 0)
137 return PROMPT_ALL;
138#if 0
139 else if (*p == _T('\03'))
140 return PROMPT_BREAK;
141#endif
142
143 return PROMPT_NO;
144
145 /* unfinished solution */
146#if 0
148 ConInDisable();
149
150 do
151 {
152 ConInKey(&ir);
153 cKey = _totlower(ir.Event.KeyEvent.uChar.AsciiChar);
154 if (_tcschr(szKeys, cKey[0]) == NULL)
155 cKey = 0;
156 }
157 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
158 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
159 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
160
162 ConInEnable();
163
164 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
165 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
166 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
167 return PROMPT_BREAK;
168
169 return PROMPT_YES;
170#endif
171}
#define STRING_COPY_OPTION
Definition: resource.h:24
VOID ConInString(LPTSTR lpInput, DWORD dwLength)
Definition: util.c:173
VOID AddBreakHandler(VOID)
Definition: cmd.c:1844
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1850
VOID ConInDisable(VOID)
Definition: console.c:36
VOID ConInEnable(VOID)
Definition: console.c:46
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define _istspace
Definition: tchar.h:1504
#define _tcsupr
Definition: tchar.h:1467
#define _tcsncmp
Definition: tchar.h:1428
#define _tcschr
Definition: tchar.h:1406
#define _totlower
Definition: tchar.h:1511
#define ConOutResPrintf(uID,...)
Definition: replace.h:31
#define PROMPT_YES
Definition: replace.h:21
#define PROMPT_NO
Definition: replace.h:20
#define PROMPT_ALL
Definition: replace.h:22
#define PROMPT_BREAK
Definition: replace.h:23
#define LoadStringW
Definition: utils.h:64
#define VK_ESCAPE
Definition: winuser.h:2250

◆ GetPathCase()

VOID GetPathCase ( TCHAR Path,
TCHAR OutPath 
)

Definition at line 53 of file util.c.

54{
55 UINT i = 0;
56 TCHAR TempPath[MAX_PATH];
57 WIN32_FIND_DATA FindFileData;
58 HANDLE hFind;
59
60 _tcscpy(TempPath, _T(""));
61 _tcscpy(OutPath, _T(""));
62
63 for (i = 0; i < _tcslen(Path); i++)
64 {
65 if (Path[i] != _T('\\'))
66 {
67 _tcsncat(TempPath, &Path[i], 1);
68 if (i != _tcslen(Path) - 1)
69 continue;
70 }
71 /* Handle the base part of the path different.
72 Because if you put it into findfirstfile, it will
73 return your current folder */
74 if (_tcslen(TempPath) == 2 && TempPath[1] == _T(':'))
75 {
76 _tcscat(OutPath, TempPath);
77 _tcscat(OutPath, _T("\\"));
78 _tcscat(TempPath, _T("\\"));
79 }
80 else
81 {
82 hFind = FindFirstFile(TempPath,&FindFileData);
83 if (hFind == INVALID_HANDLE_VALUE)
84 {
85 _tcscpy(OutPath, Path);
86 return;
87 }
88 _tcscat(TempPath, _T("\\"));
89 _tcscat(OutPath, FindFileData.cFileName);
90 _tcscat(OutPath, _T("\\"));
91 FindClose(hFind);
92 }
93 }
94}
PRTL_UNICODE_STRING_BUFFER Path
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define _tcsncat
Definition: tchar.h:1408
unsigned int UINT
Definition: ndis.h:50
#define FindFirstFile
Definition: winbase.h:3531
#define _tcslen
Definition: xmlstorage.h:198

Referenced by replace(), and SetRootPath().

◆ GetRootPath()

INT GetRootPath ( IN LPCTSTR  InPath,
OUT LPTSTR  OutPath,
IN INT  size 
)

Definition at line 21 of file util.c.

25{
26 if (InPath[0] && InPath[1] == _T(':'))
27 {
28 INT t = 0;
29
30 if ((InPath[0] >= _T('0')) && (InPath[0] <= _T('9')))
31 {
32 t = (InPath[0] - _T('0')) + 28;
33 }
34 else if ((InPath[0] >= _T('a')) && (InPath[0] <= _T('z')))
35 {
36 t = (InPath[0] - _T('a')) + 1;
37 }
38 else if ((InPath[0] >= _T('A')) && (InPath[0] <= _T('Z')))
39 {
40 t = (InPath[0] - _T('A')) + 1;
41 }
42
43 return (_tgetdcwd(t, OutPath, size) == NULL);
44 }
45
46 /* Get current directory */
47 return !GetCurrentDirectory(size, OutPath);
48}
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
#define _tgetdcwd
Definition: tchar.h:674
#define GetCurrentDirectory
Definition: winbase.h:3554

◆ IsExistingDirectory()

BOOL IsExistingDirectory ( IN LPCTSTR  pszPath)

Definition at line 105 of file util.c.

106{
107 DWORD attr = GetFileAttributes(pszPath);
109}
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
Definition: cookie.c:202
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define GetFileAttributes
Definition: winbase.h:3564

◆ IsExistingFile()

BOOL IsExistingFile ( IN LPCTSTR  pszPath)

Definition at line 99 of file util.c.

100{
101 DWORD attr = GetFileAttributes(pszPath);
103}

◆ msg_pause()

VOID msg_pause ( VOID  )

Definition at line 211 of file util.c.

212{
214}
#define STRING_ERROR_D_PAUSEMSG
Definition: resource.h:29
#define ConOutResPuts(uID)
Definition: replace.h:28

Variable Documentation

◆ bCtrlBreak

BOOL bCtrlBreak = FALSE

Definition at line 11 of file util.c.

Referenced by cgetchar().