2005-05-07 21:24:31 +00:00
|
|
|
/*
|
1999-09-27 22:13:59 +00:00
|
|
|
* MORE.C - external command.
|
|
|
|
*
|
|
|
|
* clone from 4nt more command
|
|
|
|
*
|
1999-10-03 22:12:57 +00:00
|
|
|
* 26 Sep 1999 - Paolo Pantaleo <paolopan@freemail.it>
|
2005-05-07 21:24:31 +00:00
|
|
|
* started
|
2003-10-23 21:36:43 +00:00
|
|
|
* Oct 2003 - Timothy Schepens <tischepe at fastmail dot fm>
|
|
|
|
* use window size instead of buffer size.
|
1999-09-27 22:13:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
|
|
|
|
DWORD len;
|
|
|
|
LPTSTR msg = "--- continue ---";
|
|
|
|
|
|
|
|
|
|
|
|
/*handle for file and console*/
|
|
|
|
HANDLE hStdIn;
|
|
|
|
HANDLE hStdOut;
|
|
|
|
HANDLE hStdErr;
|
|
|
|
HANDLE hKeyboard;
|
|
|
|
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
GetScreenSize (PSHORT maxx, PSHORT maxy)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo (hStdOut, &csbi);
|
2003-10-23 21:36:43 +00:00
|
|
|
*maxx = csbi.srWindow.Right;
|
|
|
|
*maxy = csbi.srWindow.Bottom;
|
1999-09-27 22:13:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-11-05 20:41:17 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
VOID ConOutPuts (LPTSTR szText)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL);
|
|
|
|
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 22:13:59 +00:00
|
|
|
static VOID
|
|
|
|
ConInKey (VOID)
|
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
DWORD dwRead;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ReadConsoleInput (hKeyboard, &ir, 1, &dwRead);
|
|
|
|
if ((ir.EventType == KEY_EVENT) &&
|
|
|
|
(ir.Event.KeyEvent.bKeyDown == TRUE))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
WaitForKey (VOID)
|
|
|
|
{
|
|
|
|
DWORD dwWritten;
|
|
|
|
|
|
|
|
WriteFile (hStdErr,msg , len, &dwWritten, NULL);
|
|
|
|
|
|
|
|
ConInKey();
|
|
|
|
|
|
|
|
WriteFile (hStdErr, _T("\n"), 1, &dwWritten, NULL);
|
|
|
|
|
|
|
|
// FlushConsoleInputBuffer (hConsoleIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//INT CommandMore (LPTSTR cmd, LPTSTR param)
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
SHORT maxx,maxy;
|
|
|
|
SHORT line_count=0,ch_count=0;
|
2003-02-24 23:16:13 +00:00
|
|
|
INT i, last;
|
1999-09-27 22:13:59 +00:00
|
|
|
|
|
|
|
/*reading/writing buffer*/
|
|
|
|
TCHAR *buff;
|
|
|
|
|
|
|
|
/*bytes written by WriteFile and ReadFile*/
|
|
|
|
DWORD dwRead,dwWritten;
|
|
|
|
|
|
|
|
/*ReadFile() return value*/
|
|
|
|
BOOL bRet;
|
|
|
|
|
|
|
|
len = _tcslen (msg);
|
|
|
|
hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
hStdErr = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
|
2003-02-24 23:16:13 +00:00
|
|
|
if (argc > 1 && _tcsncmp (argv[1], _T("/?"), 2) == 0)
|
1999-11-05 20:41:17 +00:00
|
|
|
{
|
|
|
|
ConOutPuts(_T("Help text still missing!!"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hKeyboard = CreateFile ("CONIN$", GENERIC_READ,
|
|
|
|
0,NULL,OPEN_ALWAYS,0,0);
|
|
|
|
|
1999-09-27 22:13:59 +00:00
|
|
|
GetScreenSize(&maxx,&maxy);
|
|
|
|
|
2003-02-24 23:16:13 +00:00
|
|
|
buff=malloc(4096);
|
1999-09-27 22:13:59 +00:00
|
|
|
|
|
|
|
FlushConsoleInputBuffer (hKeyboard);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2003-02-24 23:16:13 +00:00
|
|
|
bRet = ReadFile(hStdIn,buff,4096,&dwRead,NULL);
|
1999-09-27 22:13:59 +00:00
|
|
|
|
2003-02-24 23:16:13 +00:00
|
|
|
for(last=i=0;i<dwRead && bRet;i++)
|
1999-09-27 22:13:59 +00:00
|
|
|
{
|
|
|
|
ch_count++;
|
2003-02-24 23:16:13 +00:00
|
|
|
if(buff[i] == _T('\n') || ch_count == maxx)
|
1999-09-27 22:13:59 +00:00
|
|
|
{
|
|
|
|
ch_count=0;
|
|
|
|
line_count++;
|
2003-10-23 21:36:43 +00:00
|
|
|
if (line_count == maxy)
|
1999-09-27 22:13:59 +00:00
|
|
|
{
|
|
|
|
line_count = 0;
|
2003-02-24 23:16:13 +00:00
|
|
|
WriteFile(hStdOut,&buff[last], i-last+1, &dwWritten, NULL);
|
|
|
|
last=i+1;
|
1999-09-27 22:13:59 +00:00
|
|
|
FlushFileBuffers (hStdOut);
|
|
|
|
WaitForKey ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-02-24 23:16:13 +00:00
|
|
|
if (last<dwRead && bRet)
|
|
|
|
WriteFile(hStdOut,&buff[last], dwRead-last, &dwWritten, NULL);
|
|
|
|
|
1999-09-27 22:13:59 +00:00
|
|
|
}
|
|
|
|
while(dwRead>0 && bRet);
|
|
|
|
|
|
|
|
free (buff);
|
|
|
|
CloseHandle (hKeyboard);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-03 20:57:13 +00:00
|
|
|
/* EOF */
|