mirror of
https://github.com/reactos/reactos.git
synced 2025-06-01 07:28:19 +00:00
Make cmd able to (sort of) work without a console.
svn path=/trunk/; revision=40289
This commit is contained in:
parent
c233cfcaf8
commit
c1ff41171d
4 changed files with 50 additions and 17 deletions
|
@ -164,7 +164,6 @@ DWORD dwChildProcessId = 0;
|
|||
OSVERSIONINFO osvi;
|
||||
HANDLE hIn;
|
||||
HANDLE hOut;
|
||||
HANDLE hConsole;
|
||||
LPTSTR lpOriginalEnvironment;
|
||||
HANDLE CMD_ModuleHandle;
|
||||
|
||||
|
@ -1380,7 +1379,12 @@ ReadLine (TCHAR *commandline, BOOL bMore)
|
|||
}
|
||||
}
|
||||
|
||||
ReadCommand (readline, CMDLINE_LENGTH - 1);
|
||||
if (!ReadCommand(readline, CMDLINE_LENGTH - 1))
|
||||
{
|
||||
bExit = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (CheckCtrlBreak(BREAK_INPUT))
|
||||
{
|
||||
ConOutPuts(_T("\n"));
|
||||
|
@ -1805,6 +1809,7 @@ static VOID Cleanup()
|
|||
*/
|
||||
int cmd_main (int argc, const TCHAR *argv[])
|
||||
{
|
||||
HANDLE hConsole;
|
||||
TCHAR startPath[MAX_PATH];
|
||||
CONSOLE_SCREEN_BUFFER_INFO Info;
|
||||
INT nExitCode;
|
||||
|
@ -1821,12 +1826,16 @@ int cmd_main (int argc, const TCHAR *argv[])
|
|||
hConsole = CreateFile(_T("CONOUT$"), GENERIC_READ|GENERIC_WRITE,
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, 0, NULL);
|
||||
if (GetConsoleScreenBufferInfo(hConsole, &Info) == FALSE)
|
||||
if (hConsole != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ConErrFormatMessage(GetLastError());
|
||||
return(1);
|
||||
if (!GetConsoleScreenBufferInfo(hConsole, &Info))
|
||||
{
|
||||
ConErrFormatMessage(GetLastError());
|
||||
return(1);
|
||||
}
|
||||
wDefColor = Info.wAttributes;
|
||||
CloseHandle(hConsole);
|
||||
}
|
||||
wDefColor = Info.wAttributes;
|
||||
|
||||
InputCodePage= GetConsoleCP();
|
||||
OutputCodePage = GetConsoleOutputCP();
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
/* global variables */
|
||||
extern HANDLE hOut;
|
||||
extern HANDLE hIn;
|
||||
extern HANDLE hConsole;
|
||||
extern LPTSTR lpOriginalEnvironment;
|
||||
extern WORD wColor;
|
||||
extern WORD wDefColor;
|
||||
|
@ -120,7 +119,7 @@ extern HANDLE CMD_ModuleHandle;
|
|||
|
||||
|
||||
/* Prototypes for CMDINPUT.C */
|
||||
VOID ReadCommand (LPTSTR, INT);
|
||||
BOOL ReadCommand (LPTSTR, INT);
|
||||
|
||||
|
||||
/* Prototypes for CMDTABLE.C */
|
||||
|
|
|
@ -126,8 +126,9 @@ ClearCommandLine (LPTSTR str, INT maxlen, SHORT orgx, SHORT orgy)
|
|||
|
||||
|
||||
/* read in a command line */
|
||||
VOID ReadCommand (LPTSTR str, INT maxlen)
|
||||
BOOL ReadCommand (LPTSTR str, INT maxlen)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
SHORT orgx; /* origin x/y */
|
||||
SHORT orgy;
|
||||
SHORT curx; /*current x/y cursor position*/
|
||||
|
@ -149,11 +150,30 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
|||
TCHAR PreviousChar;
|
||||
#endif
|
||||
|
||||
/* get screen size */
|
||||
GetScreenSize (&maxx, &maxy);
|
||||
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
||||
{
|
||||
/* No console */
|
||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD dwRead;
|
||||
CHAR chr;
|
||||
do
|
||||
{
|
||||
if (!ReadFile(hStdin, &chr, 1, &dwRead, NULL) || !dwRead)
|
||||
return FALSE;
|
||||
#ifdef _UNICODE
|
||||
MultiByteToWideChar(InputCodePage, 0, &chr, 1, &str[charcount++], 1);
|
||||
#endif
|
||||
} while (chr != '\n' && charcount < maxlen);
|
||||
str[charcount] = _T('\0');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GetCursorXY (&orgx, &orgy);
|
||||
GetCursorXY (&curx, &cury);
|
||||
/* get screen size */
|
||||
maxx = csbi.dwSize.X;
|
||||
maxy = csbi.dwSize.Y;
|
||||
|
||||
curx = orgx = csbi.dwCursorPosition.X;
|
||||
cury = orgy = csbi.dwCursorPosition.Y;
|
||||
|
||||
memset (str, 0, maxlen * sizeof (TCHAR));
|
||||
|
||||
|
@ -590,4 +610,5 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
|||
/* expand all aliases */
|
||||
ExpandAlias (str, maxlen);
|
||||
#endif /* FEATURE_ALIAS */
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ VOID GetCursorXY (PSHORT x, PSHORT y)
|
|||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
GetConsoleScreenBufferInfo (hConsole, &csbi);
|
||||
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
|
||||
*x = csbi.dwCursorPosition.X;
|
||||
*y = csbi.dwCursorPosition.Y;
|
||||
|
@ -424,7 +424,7 @@ SHORT GetCursorX (VOID)
|
|||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
GetConsoleScreenBufferInfo (hConsole, &csbi);
|
||||
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
|
||||
return csbi.dwCursorPosition.X;
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ SHORT GetCursorY (VOID)
|
|||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
GetConsoleScreenBufferInfo (hConsole, &csbi);
|
||||
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
|
||||
return csbi.dwCursorPosition.Y;
|
||||
}
|
||||
|
@ -444,7 +444,11 @@ VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
|
|||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
GetConsoleScreenBufferInfo (hConsole, &csbi);
|
||||
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
||||
{
|
||||
csbi.dwSize.X = 80;
|
||||
csbi.dwSize.Y = 25;
|
||||
}
|
||||
|
||||
if (maxx)
|
||||
*maxx = csbi.dwSize.X;
|
||||
|
|
Loading…
Reference in a new issue