33#define CON_STREAM_WRITE ConStreamWrite
35#define CP_SHIFTJIS 932
42#define IsCJKCodePage(CodePage) \
43 ((CodePage) == CP_SHIFTJIS || (CodePage) == CP_HANGUL || \
45 (CodePage) == CP_BIG5 || (CodePage) == CP_GB2312)
88 if (Pager->CurrentLine)
91 if (Pager->CachedLine)
94 Pager->CachedLine =
NULL;
95 Pager->cchCachedLine = 0;
98 Pager->CurrentLine =
NULL;
105 if (Pager->CachedLine)
117 for (; ich <
cch; ++ich)
119 if (TextBuff[ich] ==
TEXT(
'\n'))
127 cchLine = (ich - ichStart);
144 (ich >=
cch) && (TextBuff[ich - 1] !=
TEXT(
'\n')));
147 if (bCacheLine && !Pager->CachedLine)
151 cchLine *
sizeof(
TCHAR));
152 Pager->cchCachedLine = 0;
154 if (!Pager->CachedLine)
160 else if (Pager->CachedLine)
164 (
PVOID)Pager->CachedLine,
165 (Pager->cchCachedLine + cchLine) *
sizeof(
TCHAR));
169 Pager->CachedLine =
NULL;
170 Pager->cchCachedLine = 0;
175 Pager->CachedLine =
ptr;
177 if (Pager->CachedLine)
182 cchLine *
sizeof(
TCHAR));
183 Pager->cchCachedLine += cchLine;
197 if (Pager->CachedLine)
199 Pager->iEndLine = Pager->cchCachedLine;
200 Pager->CurrentLine = Pager->CachedLine;
204 Pager->iEndLine = cchLine;
205 Pager->CurrentLine = &TextBuff[ichStart];
209 if ((Pager->iEndLine > 0) && (Pager->CurrentLine[Pager->iEndLine - 1] ==
TEXT(
'\n')))
224 const DWORD PageColumns = Pager->PageColumns;
225 const DWORD ScrollRows = Pager->ScrollRows;
227 BOOL bFinitePaging = ((PageColumns > 0) && (Pager->PageRows > 0));
228 LONG nTabWidth = Pager->nTabWidth;
234 DWORD iColumn = Pager->iColumn;
238 UINT nWidthOfChar = 1;
246 nTabWidth = PageColumns - 1;
248 nTabWidth =
min(nTabWidth, PageColumns - 1);
260 Line = Pager->CurrentLine;
261 ichStart = Pager->ichCurr;
262 iEndLine = Pager->iEndLine;
267 if (bFinitePaging && (Pager->iLine >= ScrollRows))
270 if (!
Line || (ichStart >= iEndLine))
276 Line = Pager->CurrentLine;
277 ichStart = Pager->ichCurr;
278 iEndLine = Pager->iEndLine;
288 Pager->iColumn = iColumn;
289 if (Pager->PagerLine && Pager->PagerLine(Pager, &
Line[ichStart], iEndLine - ichStart))
291 iColumn = Pager->iColumn;
294 Pager->nSpacePending = 0;
302 if (Pager->nSpacePending > 0)
305 while (Pager->nSpacePending > 0)
309 --(Pager->nSpacePending);
313 if ((PageColumns > 0) && (iColumn % PageColumns == 0))
318 if (!bFinitePaging || (PageColumns < Pager->
Screen->csbi.dwSize.X))
333 for (ich = ichStart; ich < iEndLine; ++ich)
366 if ((PageColumns > 0) && IsCJK)
368 IsDoubleWidthCharTrailing = (nWidthOfChar == 2) &&
369 ((iColumn + 1) % PageColumns == 0);
370 if (IsDoubleWidthCharTrailing)
379 iColumn += nWidthOfChar;
382 if ((PageColumns > 0) && (iColumn % PageColumns == 0))
390 if (ich - ichStart > 0)
415 Pager->nSpacePending = 0;
433 Pager->nSpacePending = nTabWidth - (iColumn % nTabWidth);
444 while (Pager->iLine < ScrollRows)
448 Pager->iColumn = iColumn;
449 if (Pager->PagerLine && Pager->PagerLine(Pager,
TEXT(
"\n"), 1))
470 Pager->nSpacePending = 0;
479 if (IsDoubleWidthCharTrailing)
481 IsDoubleWidthCharTrailing =
FALSE;
487 if ((PageColumns > 0) && (iColumn % PageColumns == 0))
490 if (!bFinitePaging || (PageColumns < Pager->
Screen->csbi.dwSize.X))
507 Pager->ichCurr = ichStart;
508 Pager->iColumn = iColumn;
512 if (bFinitePaging && (Pager->iLine >= ScrollRows))
568 Pager->PageColumns = csbi.
dwSize.
X;
574 Pager->PageColumns = 0;
580 if (bIsConsole && (Pager->PageRows >= 2))
583 Pager->ScrollRows = Pager->PageRows - 1;
588 Pager->ScrollRows = 0;
592 Pager->CachedLine =
NULL;
593 Pager->cchCachedLine = 0;
596 Pager->CurrentLine =
NULL;
599 Pager->nSpacePending = 0;
610 if (!Pager->CachedLine)
622 if (bIsConsole && (Pager->PageRows >= 2))
625 Pager->ScrollRows = Pager->PageRows - 1;
637 Pager->PageColumns = csbi.
dwSize.
X;
static LPTSTR ExpandTab(LPCTSTR line)
#define ERROR_NOT_ENOUGH_MEMORY
#define HeapFree(x, y, z)
#define WideCharToMultiByte
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static DWORD DWORD void LPSTR DWORD cch
static BOOL __stdcall PagePrompt(PCON_PAGER Pager, DWORD Done, DWORD Total)
Console/terminal screen management.
BOOL ConGetScreenInfo(IN PCON_SCREEN Screen, OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi)
INT WINAPI K32LoadStringW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, OUT LPWSTR lpBuffer, IN INT nBufferMax)
PULONG MinorVersion OPTIONAL
#define RtlCopyMemory(Destination, Source, Length)