/* * MORE.C - external command. * * clone from 4nt more command * * 26 Sep 1999 - Paolo Pantaleo * started * Oct 2003 - Timothy Schepens * use window size instead of buffer size. */ #include #include #include 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); *maxx = csbi.srWindow.Right; *maxy = csbi.srWindow.Bottom; } 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); } 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; INT i, last; /*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); if (argc > 1 && _tcsncmp (argv[1], _T("/?"), 2) == 0) { ConOutPuts(_T("Help text still missing!!")); return 0; } hKeyboard = CreateFile ("CONIN$", GENERIC_READ, 0,NULL,OPEN_ALWAYS,0,0); GetScreenSize(&maxx,&maxy); buff=malloc(4096); FlushConsoleInputBuffer (hKeyboard); do { bRet = ReadFile(hStdIn,buff,4096,&dwRead,NULL); for(last=i=0;i0 && bRet); free (buff); CloseHandle (hKeyboard); return 0; } /* EOF */