2 * MORE.C - external command.
4 * clone from 4nt more command
6 * 26 Sep 1999 - Paolo Pantaleo <paolopan@freemail.it>
16 LPTSTR msg
= "--- continue ---";
19 /*handle for file and console*/
27 GetScreenSize (PSHORT maxx
, PSHORT maxy
)
29 CONSOLE_SCREEN_BUFFER_INFO csbi
;
31 GetConsoleScreenBufferInfo (hStdOut
, &csbi
);
34 *maxx
= csbi
.dwSize
.X
;
36 *maxy
= csbi
.dwSize
.Y
;
41 VOID
ConOutPuts (LPTSTR szText
)
45 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE
), szText
, _tcslen(szText
), &dwWritten
, NULL
);
46 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE
), "\n", 1, &dwWritten
, NULL
);
58 ReadConsoleInput (hKeyboard
, &ir
, 1, &dwRead
);
59 if ((ir
.EventType
== KEY_EVENT
) &&
60 (ir
.Event
.KeyEvent
.bKeyDown
== TRUE
))
72 WriteFile (hStdErr
,msg
, len
, &dwWritten
, NULL
);
76 WriteFile (hStdErr
, _T("\n"), 1, &dwWritten
, NULL
);
78 // FlushConsoleInputBuffer (hConsoleIn);
82 //INT CommandMore (LPTSTR cmd, LPTSTR param)
83 int main (int argc
, char **argv
)
86 SHORT line_count
=0,ch_count
=0;
89 /*reading/writing buffer*/
92 /*bytes written by WriteFile and ReadFile*/
93 DWORD dwRead
,dwWritten
;
95 /*ReadFile() return value*/
99 hStdIn
= GetStdHandle(STD_INPUT_HANDLE
);
100 hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
101 hStdErr
= GetStdHandle(STD_ERROR_HANDLE
);
103 if (_tcsncmp (argv
[1], _T("/?"), 2) == 0)
105 ConOutPuts(_T("Help text still missing!!"));
109 hKeyboard
= CreateFile ("CONIN$", GENERIC_READ
,
110 0,NULL
,OPEN_ALWAYS
,0,0);
112 GetScreenSize(&maxx
,&maxy
);
116 FlushConsoleInputBuffer (hKeyboard
);
120 bRet
= ReadFile(hStdIn
,buff
,1,&dwRead
,NULL
);
122 if (dwRead
>0 && bRet
)
123 WriteFile(hStdOut
,buff
,dwRead
,&dwWritten
,NULL
);
125 for(i
=0;i
<dwRead
;i
++)
128 if(buff
[i
] == _T('\x0a') || ch_count
== maxx
)
132 if (line_count
== maxy
-1)
135 FlushFileBuffers (hStdOut
);
141 while(dwRead
>0 && bRet
);
144 CloseHandle (hKeyboard
);