Fix minior bug in ConPrintfPaging so it count line right and do pause on the screen before it getting full. Fix the row size calc code. Move in page break code to the for. Write one char at time. Need to be fixed so it can write more that one char at time.

svn path=/trunk/; revision=16481
This commit is contained in:
Magnus Olsen 2005-07-07 11:26:38 +00:00
parent e64361f015
commit be0b8327dd

View file

@ -222,11 +222,14 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
#else #else
pBuf = szOut; pBuf = szOut;
#endif #endif
WriteFile (GetStdHandle (nStdHandle), WriteFile (GetStdHandle (nStdHandle),
pBuf, pBuf,
len, len,
&dwWritten, &dwWritten,
NULL); NULL);
#ifdef UNICODE #ifdef UNICODE
free(pBuf); free(pBuf);
#endif #endif
@ -239,33 +242,40 @@ VOID ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdH
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
TCHAR szOut[OUTPUT_BUFFER_SIZE]; TCHAR szOut[OUTPUT_BUFFER_SIZE];
DWORD dwWritten; 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 /* used to count number of lines since last pause */
int ScreenCol = 0; //the number of chars in a roow static int LineCount = 0;
int CharEL = 0; //chars since end of line
/* 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; int i = 0;
if(NewPage == TRUE) if(NewPage == TRUE)
LineCount = 0; LineCount = 0;
/* rest LineCount and return if no string have been given */
if (szFormat == NULL)
return;
//get the size of the visual screen that can be printed too //get the size of the visual screen that can be printed too
GetConsoleScreenBufferInfo(hConsole, &csbi); GetConsoleScreenBufferInfo(hConsole, &csbi);
//subtract 2 to account for "press any key..." and for the blank line at the end of PagePrompt() //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; ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
ScreenCol = csbi.srWindow.Right + 1; ScreenCol = (csbi.srWindow.Right - csbi.srWindow.Left) + 1;
//make sure they didnt make the screen to small //make sure they didnt make the screen to small
if(ScreenLines<2) if(ScreenLines<4)
{
ConPrintf(szFormat, arg_ptr, nStdHandle); ConPrintf(szFormat, arg_ptr, nStdHandle);
//if more lines have been printed then screen size it is time to stop return ;
if(LineCount >= ScreenLines)
{
if(PagePrompt() != PROMPT_YES)
{
return;
}
//reset the number of lines being printed
LineCount = 0;
} }
len = _vstprintf (szOut, szFormat, arg_ptr); len = _vstprintf (szOut, szFormat, arg_ptr);
@ -275,42 +285,44 @@ VOID ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdH
#else #else
pBuf = szOut; pBuf = szOut;
#endif #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++) for(i = 0; i < len; i++)
{ {
if(szOut[i] == '\n')
if(szOut[i] == _T('\n'))
{ {
CharEL = 0;
LineCount++; LineCount++;
CharEL=0;
} }
else else
{ {
CharEL++; CharEL++;
if(CharEL > ScreenCol) if (CharEL>=ScreenCol)
{ {
CharEL = 0; if (i+1<len)
LineCount++; {
if(szOut[i+1] != _T('\n')) LineCount++;
}
CharEL=0;
} }
} }
/* FIXME : write more that one char at time */
WriteFile (GetStdHandle (nStdHandle),&pBuf[i],sizeof(TCHAR),&dwWritten,NULL);
if(LineCount >= ScreenLines)
{
if(_tcsncicmp(&szOut[i],_T("\n"),2)!=0)
WriteFile (GetStdHandle (nStdHandle),_T("\n"),sizeof(TCHAR),&dwWritten,NULL);
if(PagePrompt() != PROMPT_YES)
{
return;
} }
//reset the number of lines being printed
LineCount = 0;
CharEL=0;
}
} }
#ifdef UNICODE #ifdef UNICODE