OSVERSIONINFO osvi;
HANDLE hIn;
HANDLE hOut;
-HANDLE hConsole;
LPTSTR lpOriginalEnvironment;
HANDLE CMD_ModuleHandle;
}
}
- ReadCommand (readline, CMDLINE_LENGTH - 1);
+ if (!ReadCommand(readline, CMDLINE_LENGTH - 1))
+ {
+ bExit = TRUE;
+ return FALSE;
+ }
+
if (CheckCtrlBreak(BREAK_INPUT))
{
ConOutPuts(_T("\n"));
*/
int cmd_main (int argc, const TCHAR *argv[])
{
+ HANDLE hConsole;
TCHAR startPath[MAX_PATH];
CONSOLE_SCREEN_BUFFER_INFO Info;
INT nExitCode;
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();
/* global variables */
extern HANDLE hOut;
extern HANDLE hIn;
-extern HANDLE hConsole;
extern LPTSTR lpOriginalEnvironment;
extern WORD wColor;
extern WORD wDefColor;
/* Prototypes for CMDINPUT.C */
-VOID ReadCommand (LPTSTR, INT);
+BOOL ReadCommand (LPTSTR, INT);
/* Prototypes for CMDTABLE.C */
/* 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*/
TCHAR PreviousChar;
#endif
+ 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;
+ }
+
/* get screen size */
- GetScreenSize (&maxx, &maxy);
+ maxx = csbi.dwSize.X;
+ maxy = csbi.dwSize.Y;
- GetCursorXY (&orgx, &orgy);
- GetCursorXY (&curx, &cury);
+ curx = orgx = csbi.dwCursorPosition.X;
+ cury = orgy = csbi.dwCursorPosition.Y;
memset (str, 0, maxlen * sizeof (TCHAR));
/* expand all aliases */
ExpandAlias (str, maxlen);
#endif /* FEATURE_ALIAS */
+ return TRUE;
}
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi);
+ GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
*x = csbi.dwCursorPosition.X;
*y = csbi.dwCursorPosition.Y;
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi);
+ GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
return csbi.dwCursorPosition.X;
}
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi);
+ GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
return csbi.dwCursorPosition.Y;
}
{
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;