Fix bug where DIR /D wouldn't always show all files; merge duplicated code between /W and /D

svn path=/trunk/; revision=38131
This commit is contained in:
Jeffrey Morlan 2008-12-16 23:51:20 +00:00
parent a99a144adb
commit 82f0f59917

View file

@ -1094,18 +1094,24 @@ DirPrintWideList(LPWIN32_FIND_DATA ptrFiles[], /* [IN] Files' Info */
if (!(iColumns)) if (!(iColumns))
iColumns = 1; iColumns = 1;
/* Print Column sorted */
if (lpFlags->bWideListColSort)
{
/* Calculate the lines that will be printed */ /* Calculate the lines that will be printed */
// iLines = ceil((float)dwCount/(float)iColumns); iLines = (USHORT)((dwCount + iColumns - 1) / iColumns);
iLines = (USHORT)(dwCount / iColumns);
for (i = 0; i < iLines; i++) for (i = 0; i < iLines; i++)
{ {
for (j = 0; j < iColumns; j++) for (j = 0; j < iColumns; j++)
{ {
if (lpFlags->bWideListColSort)
{
/* Print Column sorted */
temp = (j * iLines) + i; temp = (j * iLines) + i;
}
else
{
/* Print Line sorted */
temp = (i * iColumns) + j;
}
if (temp >= dwCount) if (temp >= dwCount)
break; break;
@ -1120,41 +1126,7 @@ DirPrintWideList(LPWIN32_FIND_DATA ptrFiles[], /* [IN] Files' Info */
ConOutPrintf(_T("%-*s"), iLongestName + 1 , szTempFname); ConOutPrintf(_T("%-*s"), iLongestName + 1 , szTempFname);
} }
if(lpFlags->bPause) /* Add a new line after the last item in the column */
ConOutPrintfPaging(FALSE,_T("\n"));
else
ConOutPrintf(_T("\n"));
}
}
else
{
/* Print Line sorted */
for (i = 0; i < dwCount; i++)
{
if (ptrFiles[i]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
_stprintf(szTempFname, _T("[%s]"), ptrFiles[i]->cFileName);
else
_stprintf(szTempFname, _T("%s"), ptrFiles[i]->cFileName);
if(lpFlags->bPause)
ConOutPrintfPaging(FALSE,_T("%-*s"), iLongestName + 1, szTempFname );
else
ConOutPrintf(_T("%-*s"), iLongestName + 1, szTempFname );
/*
* We print a new line at the end of each column
* except for the case that it is the last item.
*/
if (!((i + 1) % iColumns) && (i < (dwCount - 1)))
{
if(lpFlags->bPause)
ConOutPrintfPaging(FALSE,_T("\n"));
else
ConOutPrintf(_T("\n"));
}
}
/* Add a new line after the last item */
if(lpFlags->bPause) if(lpFlags->bPause)
ConOutPrintfPaging(FALSE,_T("\n")); ConOutPrintfPaging(FALSE,_T("\n"));
else else