Brandon Turner turnerb7(a)msu.edu
Added ConPrintfPaging and ConOutPrintfPaging
Added /p back in using ConOutPrintfPaging
Me
correct small mistake in en.rc adding newline
for dir_help text, so it looking bit better when it
printout
Modified: trunk/reactos/subsys/system/cmd/En.rc
Modified: trunk/reactos/subsys/system/cmd/cmd.h
Modified: trunk/reactos/subsys/system/cmd/console.c
Modified: trunk/reactos/subsys/system/cmd/dir.c
_____
Modified: trunk/reactos/subsys/system/cmd/En.rc
--- trunk/reactos/subsys/system/cmd/En.rc 2005-07-01 16:04:07 UTC
(rev 16370)
+++ trunk/reactos/subsys/system/cmd/En.rc 2005-07-01 18:20:10 UTC
(rev 16371)
@@ -199,8 +199,8 @@
Switches may be preset in the DIRCMD environment variable. Override\n\
preset switches by prefixing any switch with - (hyphen)--for example,
/-W.\n"
-STRING_DIR_HELP2, " Volume in drive %c is %s"
-STRING_DIR_HELP3, " Volume in drive %c has no label"
+STRING_DIR_HELP2, " Volume in drive %c is %s\n"
+STRING_DIR_HELP3, " Volume in drive %c has no label.\n"
STRING_DIR_HELP4, " Volume Serial Number is %04X-%04X\n"
STRING_DIR_HELP5, "\n Total Files Listed:\n%16i File(s)% 14s
bytes\n"
STRING_DIR_HELP6, "%16i Dir(s)% 15s bytes\n"
_____
Modified: trunk/reactos/subsys/system/cmd/cmd.h
--- trunk/reactos/subsys/system/cmd/cmd.h 2005-07-01 16:04:07 UTC
(rev 16370)
+++ trunk/reactos/subsys/system/cmd/cmd.h 2005-07-01 18:20:10 UTC
(rev 16371)
@@ -147,6 +147,7 @@
VOID ConOutChar (TCHAR);
VOID ConOutPuts (LPTSTR);
VOID ConOutPrintf (LPTSTR, ...);
+VOID ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
VOID ConErrChar (TCHAR);
VOID ConErrPuts (LPTSTR);
VOID ConErrPrintf (LPTSTR, ...);
_____
Modified: trunk/reactos/subsys/system/cmd/console.c
--- trunk/reactos/subsys/system/cmd/console.c 2005-07-01 16:04:07 UTC
(rev 16370)
+++ trunk/reactos/subsys/system/cmd/console.c 2005-07-01 18:20:10 UTC
(rev 16371)
@@ -9,6 +9,9 @@
*
* 03-Apr-2005 (Magnus Olsen) <magnus(a)greatlord.com>)
* Remove all hardcode string to En.rc
+ *
+ * 01-Jul-2005 (Brandon Turner) <turnerb7(a)msu.edu>)
+ * Added ConPrintfPaging and ConOutPrintfPaging
*/
@@ -222,6 +225,92 @@
#endif
}
+VOID 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;
+ static int LineCount = 0; //used to count number of lines since
last pause
+ int ScreenLines = 0; //used to see how big the screen is
+ int ScreenCol = 0; //the number of chars in a roow
+ int CharEL = 0; //chars since end of line
+ int i = 0;
+
+ if(NewPage == TRUE)
+ LineCount = 0;
+
+ //get the size of the visual screen that can be printed too
+ GetConsoleScreenBufferInfo(hConsole, &csbi);
+ //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 - 2;
+ ScreenCol = csbi.srWindow.Right + 1;
+
+ //make sure they didnt make the screen to small
+ if(ScreenLines<2)
+ ConPrintf(szFormat, arg_ptr, nStdHandle);
+ //if more lines have been printed then screen size it is time to
stop
+ if(LineCount >= ScreenLines)
+ {
+ if(PagePrompt() != PROMPT_YES)
+ {
+ return;
+ }
+ //reset the number of lines being printed
+ LineCount = 0;
+ }
+
+ len = _vstprintf (szOut, szFormat, arg_ptr);
+#ifdef _UNICODE
+ pBuf = malloc(len + 1);
+ len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1,
pBuf, len + 1, NULL, NULL) - 1;
+#else
+ pBuf = szOut;
+#endif
+ WriteFile (GetStdHandle (nStdHandle),
+ pBuf,
+ len,
+ &dwWritten,
+ NULL);
+
+
+
+ if(len < ScreenCol)
+ {
+ //if it is smaller then a row then just check for \n
+ for(i = 0; i < len; i++)
+ if(szOut[i] == '\n')
+ LineCount++;
+
+ }
+ else
+ {
+ //if it is bigger then a row check for \n and a string
longer then a row can handle
+ for(i = 0; i < len; i++)
+ {
+ if(szOut[i] == '\n')
+ {
+ CharEL = 0;
+ LineCount++;
+ }
+ else
+ {
+ CharEL++;
+ if(CharEL > ScreenCol)
+ {
+ CharEL = 0;
+ LineCount++;
+ }
+ }
+ }
+ }
+
+#ifdef UNICODE
+ free(pBuf);
+#endif
+}
+
VOID ConOutFormatMessage (DWORD MessageId, ...)
{
TCHAR szMsg[RC_STRING_MAX_SIZE];
@@ -260,6 +349,15 @@
va_end (arg_ptr);
}
+VOID ConOutPrintfPaging (BOOL NewPage, LPTSTR szFormat, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, szFormat);
+ ConPrintfPaging(NewPage, szFormat, arg_ptr, STD_OUTPUT_HANDLE);
+ va_end (arg_ptr);
+}
+
VOID ConErrChar (TCHAR c)
{
ConChar(c, STD_ERROR_HANDLE);
_____
Modified: trunk/reactos/subsys/system/cmd/dir.c
--- trunk/reactos/subsys/system/cmd/dir.c 2005-07-01 16:04:07 UTC
(rev 16370)
+++ trunk/reactos/subsys/system/cmd/dir.c 2005-07-01 18:20:10 UTC
(rev 16371)
@@ -125,6 +125,8 @@
* the code is rewritten. /p is removed, to be rewriten in
* the main cmd code.
*
+ * 1-Jul-2004 (Brandon Turner <turnerb7(a)msu.edu>)
+ * Added /p back in using ConOutPrintfPaging
*/
#include "precomp.h"
@@ -847,20 +849,35 @@
if (szVolName[0] != _T('\0'))
{
LoadString(CMD_ModuleHandle, STRING_DIR_HELP2, szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg, szRootName[0], szVolName);
+ //needs to have first paramter as TRUE because
+ //this is the first output and need to clear the static
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(TRUE,szMsg, szRootName[0],
szVolName);
+ else
+ ConOutPrintf(szMsg, szRootName[0], szVolName);
+
}
else
{
LoadString(CMD_ModuleHandle, STRING_DIR_HELP3, szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg, szRootName[0]);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(TRUE,szMsg, szRootName[0]);
+ else
+ ConOutPrintf(szMsg, szRootName[0]);
}
/* print the volume serial number if the return was successful */
LoadString(CMD_ModuleHandle, STRING_DIR_HELP4, (LPTSTR) szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg,
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,szMsg,
HIWORD(dwSerialNr),
LOWORD(dwSerialNr));
+ else
+ ConOutPrintf(szMsg,
+ HIWORD(dwSerialNr),
+ LOWORD(dwSerialNr));
+
return TRUE;
}
@@ -1094,7 +1111,10 @@
ConvertULargeInteger(u64Bytes, szBuffer,
sizeof(szBuffer), lpFlags->bTSeperator);
LoadString(CMD_ModuleHandle, STRING_DIR_HELP5, szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg,ulFiles, szBuffer);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,szMsg,ulFiles, szBuffer);
+ else
+ ConOutPrintf(szMsg,ulFiles, szBuffer);
}
/* Print total directories and freespace */
@@ -1102,7 +1122,10 @@
GetUserDiskFreeSpace(szRoot, &uliFree);
ConvertULargeInteger(uliFree, szBuffer, sizeof(szBuffer),
lpFlags->bTSeperator);
LoadString(CMD_ModuleHandle, STRING_DIR_HELP6, (LPTSTR) szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg,ulDirs, szBuffer);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,szMsg,ulDirs, szBuffer);
+ else
+ ConOutPrintf(szMsg,ulDirs, szBuffer);
return 0;
}
@@ -1197,13 +1220,22 @@
DirPrintFileDateTime(szDate, szTime, ptrFiles[i], lpFlags);
/* Print the line */
- ConOutPrintf(_T("%10s %-8s %*s%s %s\n"),
- szDate,
- szTime,
- iSizeFormat,
- szSize,
- szShortName,
- ptrFiles[i]->cFileName);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("%10s %-8s %*s%s %s\n"),
+ szDate,
+ szTime,
+ iSizeFormat,
+ szSize,
+ szShortName,
+
ptrFiles[i]->cFileName);
+ else
+ ConOutPrintf(_T("%10s %-8s %*s%s %s\n"),
+ szDate,
+ szTime,
+ iSizeFormat,
+ szSize,
+ szShortName,
+
ptrFiles[i]->cFileName);
}
}
@@ -1277,10 +1309,16 @@
else
_stprintf(szTempFname, _T("%s"), ptrFiles[temp]->cFileName);
- ConOutPrintf(_T("%-*s"), iLongestName + 1 , szTempFname);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("%-*s"), iLongestName + 1
, szTempFname);
+ else
+ ConOutPrintf(_T("%-*s"), iLongestName + 1 ,
szTempFname);
}
- ConOutPrintf(_T("\n"));
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("\n"));
+ else
+ ConOutPrintf(_T("\n"));
}
}
else
@@ -1293,18 +1331,29 @@
else
_stprintf(szTempFname, _T("%s"), ptrFiles[i]->cFileName);
- ConOutPrintf(_T("%-*s"), iLongestName + 1, szTempFname );
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("%-*s"), iLongestName + 1,
szTempFname );
+ else
+ ConOutPrintf(_T("%-*s"), iLongestName + 1, szTempFname
);
/*
* We print a new line at the end of each column
* except for the case that it is the last item.
*/
- if (!((i + 1) % iColumns) && (i < (dwCount - 1)))
- ConOutPrintf(_T("\n"));
+ if (!((i + 1) % iColumns) && (i < (dwCount - 1)))
+ {
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("\n"));
+ else
+ ConOutPrintf(_T("\n"));
+ }
}
/* Add a new line after the last item */
- ConOutPrintf(_T("\n"));
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("\n"));
+ else
+ ConOutPrintf(_T("\n"));
}
}
@@ -1364,13 +1413,22 @@
DirPrintFileDateTime(szDate,szTime,ptrFiles[i],lpFlags);
/* Print the line */
- ConOutPrintf(_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
*/
+ if(lpFlags->bPause)
+ 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 */
+ else
+ ConOutPrintf(_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 */
}
}
@@ -1401,12 +1459,18 @@
/* at recursive mode we print full path of file
*/
_tcscpy(szFullName, lpCurPath);
_tcscat(szFullName, ptrFiles[i]->cFileName);
- ConOutPrintf(_T("%s\n"), szFullName);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,_T("%s\n"),
szFullName);
+ else
+ ConOutPrintf(_T("%s\n"), szFullName);
}
else
{
/* if we are not in recursive mode we print the
file names */
- ConOutPrintf(_T("%s\n"),ptrFiles[i]->cFileName);
+ if(lpFlags->bPause)
+
ConOutPrintfPaging(FALSE,_T("%s\n"),ptrFiles[i]->cFileName);
+ else
+
ConOutPrintf(_T("%s\n"),ptrFiles[i]->cFileName);
}
}
}
@@ -1438,7 +1502,10 @@
if (!(lpFlags->bBareFormat ) && !((lpFlags->bRecursive) &&
(dwCount <= 0)))
{
LoadString(CMD_ModuleHandle, STRING_DIR_HELP7, szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg, szTemp);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,szMsg, szTemp);
+ else
+ ConOutPrintf(szMsg, szTemp);
}
if (lpFlags->bBareFormat)
@@ -1790,7 +1857,11 @@
{
ConvertULargeInteger(u64CountBytes, szBytes, 20,
lpFlags->bTSeperator);
LoadString(CMD_ModuleHandle, STRING_DIR_HELP8, szMsg,
RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg,dwCountFiles, szBytes);
+ if(lpFlags->bPause)
+ ConOutPrintfPaging(FALSE,szMsg,dwCountFiles,
szBytes);
+ else
+ ConOutPrintf(szMsg,dwCountFiles, szBytes);
+
}
/* Add statistics to recursive statistics*/
@@ -1899,7 +1970,7 @@
/* <Debug :>
Uncomment this to show the final state of switch flags*/
-/*
+#ifdef _DEBUG
ConOutPrintf("Attributes mask/value
%x/%x\n",stFlags.stAttribs.dwAttribMask,stFlags.stAttribs.dwAttribVal
);
ConOutPrintf("(B) Bare format : %i\n", stFlags.bBareFormat );
ConOutPrintf("(C) Thousand : %i\n", stFlags.bTSeperator );
@@ -1917,7 +1988,7 @@
ConOutPrintf("(T) Time field : %i\n",
stFlags.stTimeField.eTimeField );
ConOutPrintf("(X) Short names : %i\n", stFlags.bShortName );
ConOutPrintf("Parameter : %s\n", param );
-*/
+#endif
/* print the header */
if (!stFlags.bBareFormat)