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,71 +1094,43 @@ DirPrintWideList(LPWIN32_FIND_DATA ptrFiles[], /* [IN] Files' Info */
if (!(iColumns)) if (!(iColumns))
iColumns = 1; iColumns = 1;
/* Print Column sorted */ /* Calculate the lines that will be printed */
if (lpFlags->bWideListColSort) iLines = (USHORT)((dwCount + iColumns - 1) / iColumns);
for (i = 0; i < iLines; i++)
{ {
/* Calculate the lines that will be printed */ for (j = 0; j < iColumns; j++)
// iLines = ceil((float)dwCount/(float)iColumns);
iLines = (USHORT)(dwCount / iColumns);
for (i = 0;i < iLines;i++)
{ {
for (j = 0; j < iColumns; j++) if (lpFlags->bWideListColSort)
{ {
/* Print Column sorted */
temp = (j * iLines) + i; temp = (j * iLines) + i;
if (temp >= dwCount) }
break; else
{
if (ptrFiles[temp]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) /* Print Line sorted */
_stprintf(szTempFname, _T("[%s]"), ptrFiles[temp]->cFileName); temp = (i * iColumns) + j;
else
_stprintf(szTempFname, _T("%s"), ptrFiles[temp]->cFileName);
if(lpFlags->bPause)
ConOutPrintfPaging(FALSE,_T("%-*s"), iLongestName + 1 , szTempFname);
else
ConOutPrintf(_T("%-*s"), iLongestName + 1 , szTempFname);
} }
if(lpFlags->bPause) if (temp >= dwCount)
ConOutPrintfPaging(FALSE,_T("\n")); break;
else
ConOutPrintf(_T("\n")); if (ptrFiles[temp]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
} _stprintf(szTempFname, _T("[%s]"), ptrFiles[temp]->cFileName);
}
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 else
_stprintf(szTempFname, _T("%s"), ptrFiles[i]->cFileName); _stprintf(szTempFname, _T("%s"), ptrFiles[temp]->cFileName);
if(lpFlags->bPause) if(lpFlags->bPause)
ConOutPrintfPaging(FALSE,_T("%-*s"), iLongestName + 1, szTempFname ); ConOutPrintfPaging(FALSE,_T("%-*s"), iLongestName + 1 , szTempFname);
else else
ConOutPrintf(_T("%-*s"), iLongestName + 1, szTempFname ); 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 */ /* Add a new line after the last item in the column */
if(lpFlags->bPause) if(lpFlags->bPause)
ConOutPrintfPaging(FALSE,_T("\n")); ConOutPrintfPaging(FALSE,_T("\n"));
else else
ConOutPrintf(_T("\n")); ConOutPrintf(_T("\n"));
} }
} }