--- trunk/reactos/subsys/system/cmd/console.c 2005-12-17 21:41:15 UTC (rev 20233)
+++ trunk/reactos/subsys/system/cmd/console.c 2005-12-17 21:51:36 UTC (rev 20234)
@@ -13,71 +13,71 @@
* 01-Jul-2005 (Brandon Turner) <turnerb7@msu.edu>)
* Added ConPrintfPaging and ConOutPrintfPaging
*/
-
-
-
+
+
+
#include <precomp.h>
#include "resource.h"
-
-
+
+
#define OUTPUT_BUFFER_SIZE 4096
-
-
+
+
UINT InputCodePage;
UINT OutputCodePage;
-
-
+
+
VOID ConInDisable (VOID)
{
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
DWORD dwMode;
-
+
GetConsoleMode (hInput, &dwMode);
dwMode &= ~ENABLE_PROCESSED_INPUT;
SetConsoleMode (hInput, dwMode);
}
-
-
+
+
VOID ConInEnable (VOID)
{
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
DWORD dwMode;
-
+
GetConsoleMode (hInput, &dwMode);
dwMode |= ENABLE_PROCESSED_INPUT;
SetConsoleMode (hInput, dwMode);
}
-
-
+
+
VOID ConInDummy (VOID)
{
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
INPUT_RECORD dummy;
DWORD dwRead;
-
+
#ifdef _DEBUG
if (hInput == INVALID_HANDLE_VALUE)
DebugPrintf (_T("Invalid input handle!!!\n"));
#endif /* _DEBUG */
ReadConsoleInput (hInput, &dummy, 1, &dwRead);
}
-
+
VOID ConInFlush (VOID)
{
FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
}
-
-
+
+
VOID ConInKey (PINPUT_RECORD lpBuffer)
{
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
DWORD dwRead;
-
+
#ifdef _DEBUG
if (hInput == INVALID_HANDLE_VALUE)
DebugPrintf (_T("Invalid input handle!!!\n"));
#endif /* _DEBUG */
-
+
do
{
ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
@@ -87,19 +87,19 @@
}
while (TRUE);
}
-
-
-
+
+
+
VOID ConInString (LPTSTR lpInput, DWORD dwLength)
{
DWORD dwOldMode;
DWORD dwRead;
HANDLE hFile;
-
+
LPTSTR p;
DWORD i;
PCHAR pBuf;
-
+
#ifdef _UNICODE
pBuf = (PCHAR)malloc(dwLength);
#else
@@ -108,11 +108,11 @@
ZeroMemory (lpInput, dwLength * sizeof(TCHAR));
hFile = GetStdHandle (STD_INPUT_HANDLE);
GetConsoleMode (hFile, &dwOldMode);
-
+
SetConsoleMode (hFile, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
-
+
ReadFile (hFile, (PVOID)pBuf, dwLength, &dwRead, NULL);
-
+
#ifdef _UNICODE
MultiByteToWideChar( InputCodePage, 0, pBuf, dwLength + 1, lpInput, dwLength + 1);
#endif
@@ -125,14 +125,14 @@
break;
}
}
-
+
#ifdef _UNICODE
free(pBuf);
#endif
-
+
SetConsoleMode (hFile, dwOldMode);
}
-
+
static VOID ConChar(TCHAR c, DWORD nStdHandle)
{
DWORD dwWritten;
@@ -153,18 +153,18 @@
&dwWritten,
NULL);
}
-
+
VOID ConOutChar (TCHAR c)
{
ConChar(c, STD_OUTPUT_HANDLE);
}
-
+
VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
{
DWORD dwWritten;
PCHAR pBuf;
INT len;
-
+
len = _tcslen(szText);
#ifdef _UNICODE
pBuf = malloc(len + 1);
@@ -186,35 +186,35 @@
free(pBuf);
#endif
}
-
+
VOID ConOutResPaging(BOOL NewPage, UINT resID)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
ConOutPrintfPaging(NewPage, szMsg);
}
-
+
VOID ConOutResPuts (UINT resID)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
-
+
ConPuts(szMsg, STD_OUTPUT_HANDLE);
}
-
+
VOID ConOutPuts (LPTSTR szText)
{
ConPuts(szText, STD_OUTPUT_HANDLE);
}
-
-
+
+
VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
{
INT len;
PCHAR pBuf;
TCHAR szOut[OUTPUT_BUFFER_SIZE];
DWORD dwWritten;
-
+
len = _vstprintf (szOut, szFormat, arg_ptr);
#ifdef _UNICODE
pBuf = malloc(len + 1);
@@ -222,67 +222,67 @@
#else
pBuf = szOut;
#endif
-
+
WriteFile (GetStdHandle (nStdHandle),
pBuf,
len,
&dwWritten,
NULL);
-
-
+
+
#ifdef UNICODE
free(pBuf);
#endif
}
-
-VOID ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
+
+INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
{
INT len;
PCHAR pBuf;
CONSOLE_SCREEN_BUFFER_INFO csbi;
TCHAR szOut[OUTPUT_BUFFER_SIZE];
DWORD dwWritten;
-
+
/* used to count number of lines since last pause */
static int LineCount = 0;
-
+
/* used to see how big the screen is */
int ScreenLines = 0;
-
+
/* the number of chars in a roow */
int ScreenCol = 0;
-
+
/* chars since end of line */
int CharEL = 0;
-
+
int i = 0;
-
+
if(NewPage == TRUE)
LineCount = 0;
-
+
/* rest LineCount and return if no string have been given */
if (szFormat == NULL)
- return;
-
-
+ return 0;
+
+
//get the size of the visual screen that can be printed too
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
{
// we assuming its a file handle
ConPrintf(szFormat, arg_ptr, nStdHandle);
- return;
+ return 0;
}
//subtract 2 to account for "press any key..." and for the blank line at the end of PagePrompt()
ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
ScreenCol = (csbi.srWindow.Right - csbi.srWindow.Left) + 1;
-
+
//make sure they didnt make the screen to small
if(ScreenLines<4)
{
ConPrintf(szFormat, arg_ptr, nStdHandle);
- return ;
+ return 0;
}
-
+
len = _vstprintf (szOut, szFormat, arg_ptr);
#ifdef _UNICODE
pBuf = malloc(len + 1);
@@ -290,10 +290,10 @@
#else
pBuf = szOut;
#endif
-
+
for(i = 0; i < len; i++)
{
-
+
if(pBuf[i] == _T('\n'))
{
LineCount++;
@@ -311,37 +311,38 @@
CharEL=0;
}
}
-
+
/* FIXME : write more that one char at time */
WriteFile (GetStdHandle (nStdHandle),&pBuf[i],sizeof(CHAR),&dwWritten,NULL);
if(LineCount >= ScreenLines)
{
if(_tcsnicmp(&pBuf[i], _T("\n"), 2)!=0)
WriteFile (GetStdHandle (nStdHandle),_T("\n"),sizeof(CHAR),&dwWritten,NULL);
-
+
if(PagePrompt() != PROMPT_YES)
{
- return;
+ return 1;
}
//reset the number of lines being printed
LineCount = 0;
CharEL=0;
}
-
+
}
-
+
#ifdef UNICODE
free(pBuf);
#endif
+ return 0;
}
-
+
VOID ConErrFormatMessage (DWORD MessageId, ...)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
DWORD ret;
LPTSTR text;
va_list arg_ptr;
-
+
va_start (arg_ptr, MessageId);
ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
@@ -350,7 +351,7 @@
(LPTSTR) &text,
0,
&arg_ptr);
-
+
va_end (arg_ptr);
if(ret > 0)
{
@@ -363,14 +364,14 @@
ConErrPrintf(szMsg);
}
}
-
+
VOID ConOutFormatMessage (DWORD MessageId, ...)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
DWORD ret;
LPTSTR text;
va_list arg_ptr;
-
+
va_start (arg_ptr, MessageId);
ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
@@ -379,7 +380,7 @@
(LPTSTR) &text,
0,
&arg_ptr);
-
+
va_end (arg_ptr);
if(ret > 0)
{
@@ -392,58 +393,60 @@
ConErrPrintf(szMsg);
}
}
-
+
VOID ConOutPrintf (LPTSTR szFormat, ...)
{
va_list arg_ptr;
-
+
va_start (arg_ptr, szFormat);
ConPrintf(szFormat, arg_ptr, STD_OUTPUT_HANDLE);
va_end (arg_ptr);
}
-
-VOID ConOutPrintfPaging (BOOL NewPage, LPTSTR szFormat, ...)
+
+INT ConOutPrintfPaging (BOOL NewPage, LPTSTR szFormat, ...)
{
+ INT iReturn;
va_list arg_ptr;
-
+
va_start (arg_ptr, szFormat);
- ConPrintfPaging(NewPage, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ iReturn = ConPrintfPaging(NewPage, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
va_end (arg_ptr);
+ return iReturn;
}
-
+
VOID ConErrChar (TCHAR c)
{
ConChar(c, STD_ERROR_HANDLE);
}
-
-
+
+
VOID ConErrResPuts (UINT resID)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE);
ConPuts(szMsg, STD_ERROR_HANDLE);
}
-
+
VOID ConErrPuts (LPTSTR szText)
{
ConPuts(szText, STD_ERROR_HANDLE);
}
-
-
+
+
VOID ConErrPrintf (LPTSTR szFormat, ...)
{
va_list arg_ptr;
-
+
va_start (arg_ptr, szFormat);
ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
va_end (arg_ptr);
}
-
+
#ifdef _DEBUG
VOID DebugPrintf (LPTSTR szFormat, ...)
{
va_list arg_ptr;
-
+
va_start (arg_ptr, szFormat);
ConPrintf(szFormat, arg_ptr, STD_ERROR_HANDLE);
va_end (arg_ptr);
@@ -456,69 +459,69 @@
#endif
}
#endif /* _DEBUG */
-
+
VOID SetCursorXY (SHORT x, SHORT y)
{
COORD coPos;
-
+
coPos.X = x;
coPos.Y = y;
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
}
-
-
+
+
VOID GetCursorXY (PSHORT x, PSHORT y)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
-
+
GetConsoleScreenBufferInfo (hConsole, &csbi);
-
+
*x = csbi.dwCursorPosition.X;
*y = csbi.dwCursorPosition.Y;
}
-
-
+
+
SHORT GetCursorX (VOID)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
-
+
GetConsoleScreenBufferInfo (hConsole, &csbi);
-
+
return csbi.dwCursorPosition.X;
}
-
-
+
+
SHORT GetCursorY (VOID)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
-
+
GetConsoleScreenBufferInfo (hConsole, &csbi);
-
+
return csbi.dwCursorPosition.Y;
}
-
-
+
+
VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
-
+
GetConsoleScreenBufferInfo (hConsole, &csbi);
-
+
if (maxx)
*maxx = csbi.dwSize.X;
if (maxy)
*maxy = csbi.dwSize.Y;
}
-
-
+
+
VOID SetCursorType (BOOL bInsert, BOOL bVisible)
{
CONSOLE_CURSOR_INFO cci;
-
+
cci.dwSize = bInsert ? 10 : 99;
cci.bVisible = bVisible;
-
+
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci);
}
-
+
/* EOF */
--- trunk/reactos/subsys/system/cmd/dir.c 2005-12-17 21:41:15 UTC (rev 20233)
+++ trunk/reactos/subsys/system/cmd/dir.c 2005-12-17 21:51:36 UTC (rev 20234)
@@ -1270,13 +1270,16 @@
/* Print the line */
if(lpFlags->bPause)
- ConOutPrintfPaging(FALSE,_T("%10s %-8s %*s%s %s\n"),
+ {
+ if (ConOutPrintfPaging(FALSE,_T("%10s %-8s %*s%s %s\n"),
szDate,
szTime,
iSizeFormat,
szSize,
szShortName,
- ptrFiles[i]->cFileName);
+ ptrFiles[i]->cFileName) == 1)
+ return ;
+ }
else
ConOutPrintf(_T("%10s %-8s %*s%s %s\n"),
szDate,
@@ -1463,13 +1466,18 @@
/* Print the line */
if(lpFlags->bPause)
- ConOutPrintfPaging(FALSE,_T("%-8s %-3s %*s %s %s\n"),
+ {
+ if (ConOutPrintfPaging(FALSE,_T("%-8s %-3s %*s %s %s\n"),
szName, /* The file's 8.3 name */
szExt, /* The file's 8.3 extension */
iSizeFormat, /* print format for size column */
szSize, /* The size of file or "<DIR>" for dirs */
szDate, /* The date of file/dir */
- szTime); /* The time of file/dir */
+ szTime) == 1) /* The time of file/dir */
+ {
+ return ;
+ }
+ }
else
ConOutPrintf(_T("%-8s %-3s %*s %s %s\n"),
szName, /* The file's 8.3 name */
@@ -1509,7 +1517,12 @@
_tcscpy(szFullName, lpCurPath);
_tcscat(szFullName, ptrFiles[i]->cFileName);
if(lpFlags->bPause)
- ConOutPrintfPaging(FALSE,_T("%s\n"), szFullName);
+ {
+ if (ConOutPrintfPaging(FALSE,_T("%s\n"), szFullName) == 1)
+ {
+ return ;
+ }
+ }
else
ConOutPrintf(_T("%s\n"), szFullName);
}
@@ -1517,7 +1530,12 @@
{
/* if we are not in recursive mode we print the file names */
if(lpFlags->bPause)
- ConOutPrintfPaging(FALSE,_T("%s\n"),ptrFiles[i]->cFileName);
+ {
+ if (ConOutPrintfPaging(FALSE,_T("%s\n"),ptrFiles[i]->cFileName) == 1)
+ {
+ return ;
+ }
+ }
else
ConOutPrintf(_T("%s\n"),ptrFiles[i]->cFileName);
}
@@ -1552,7 +1570,12 @@
{
LoadString(CMD_ModuleHandle, STRING_DIR_HELP7, szMsg, RC_STRING_MAX_SIZE);
if(lpFlags->bPause)
- ConOutPrintfPaging(FALSE,szMsg, szTemp);
+ {
+ if (ConOutPrintfPaging(FALSE,szMsg, szTemp) == 1)
+ {
+ return ;
+ }
+ }
else
ConOutPrintf(szMsg, szTemp);
}
@@ -1896,7 +1919,10 @@
/* Free array */
free(ptrFileArray);
+ if (CheckCtrlBreak(BREAK_INPUT))
+ return 1;
+
/* Add statistics to recursive statistics*/
recurse_dir_cnt += dwCountDirs;
recurse_file_cnt += dwCountFiles;
@@ -1924,7 +1950,10 @@
_tcscpy(szFullFileSpec, szFullPath);
_tcscat(szFullFileSpec, wfdFileInfo.cFileName);
/* We do the same for tha folder */
- DirList(szFullFileSpec, szFilespec, pLine,lpFlags);
+ if (DirList(szFullFileSpec, szFilespec, pLine,lpFlags) != 0)
+ {
+ return 1;
+ }
}
}
}while(FindNextFile(hRecSearch,&wfdFileInfo));