Calculate the screen size correctly. Allow a file name input.
Modified: trunk/rosapps/cmdutils/more/more.c
_____
Modified: trunk/rosapps/cmdutils/more/more.c
--- trunk/rosapps/cmdutils/more/more.c 2005-10-25 19:54:15 UTC (rev
18775)
+++ trunk/rosapps/cmdutils/more/more.c 2005-10-26 12:47:22 UTC (rev
18776)
@@ -15,7 +15,7 @@
DWORD len;
-LPTSTR msg = "--- continue ---";
+LPTSTR msg = _T("--- continue ---");
/*handle for file and console*/
@@ -31,8 +31,8 @@
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo (hStdOut, &csbi);
- *maxx = csbi.srWindow.Right;
- *maxy = csbi.srWindow.Bottom;
+ *maxx = (csbi.srWindow.Right - csbi.srWindow.Left) + 1;
+ *maxy = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
}
@@ -85,6 +85,8 @@
SHORT maxx,maxy;
SHORT line_count=0,ch_count=0;
INT i, last;
+ HANDLE hFile = INVALID_HANDLE_VALUE;
+ TCHAR szFullPath[MAX_PATH];
/*reading/writing buffer*/
TCHAR *buff;
@@ -106,18 +108,32 @@
return 0;
}
- hKeyboard = CreateFile ("CONIN$", GENERIC_READ,
+ hKeyboard = CreateFile (_T("CONIN$"), GENERIC_READ,
0,NULL,OPEN_ALWAYS,0,0);
GetScreenSize(&maxx,&maxy);
buff=malloc(4096);
- FlushConsoleInputBuffer (hKeyboard);
+ FlushConsoleInputBuffer (hKeyboard);
+ if(argc > 1)
+ {
+ GetFullPathName(argv[1], MAX_PATH, szFullPath, NULL);
+ hFile = CreateFile (szFullPath, GENERIC_READ,
+ 0,NULL,OPEN_ALWAYS,0,0);
+ }
+
do
{
- bRet = ReadFile(hStdIn,buff,4096,&dwRead,NULL);
+ if(hFile != INVALID_HANDLE_VALUE)
+ {
+ bRet = ReadFile(hFile,buff,4096,&dwRead,NULL);
+ }
+ else
+ {
+ bRet = ReadFile(hStdIn,buff,4096,&dwRead,NULL);
+ }
for(last=i=0;i<dwRead && bRet;i++)
{
@@ -144,6 +160,7 @@
free (buff);
CloseHandle (hKeyboard);
+ CloseHandle (hFile);
return 0;
}