2 * MORE.C - external command.
4 * clone from 4nt more command
6 * 26 Sep 1999 - Paolo Pantaleo <paolopan@freemail.it>
8 * Oct 2003 - Timothy Schepens <tischepe at fastmail dot fm>
9 * use window size instead of buffer size.
18 LPTSTR msg
= "--- continue ---";
21 /*handle for file and console*/
29 GetScreenSize (PSHORT maxx
, PSHORT maxy
)
31 CONSOLE_SCREEN_BUFFER_INFO csbi
;
33 GetConsoleScreenBufferInfo (hStdOut
, &csbi
);
34 *maxx
= csbi
.srWindow
.Right
;
35 *maxy
= csbi
.srWindow
.Bottom
;
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 (argc
> 1 && _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
,4096,&dwRead
,NULL
);
122 for(last
=i
=0;i
<dwRead
&& bRet
;i
++)
125 if(buff
[i
] == _T('\n') || ch_count
== maxx
)
129 if (line_count
== maxy
)
132 WriteFile(hStdOut
,&buff
[last
], i
-last
+1, &dwWritten
, NULL
);
134 FlushFileBuffers (hStdOut
);
139 if (last
<dwRead
&& bRet
)
140 WriteFile(hStdOut
,&buff
[last
], dwRead
-last
, &dwWritten
, NULL
);
143 while(dwRead
>0 && bRet
);
146 CloseHandle (hKeyboard
);