[CMD]: Fix few comments & use ARRAYSIZE(str) instead of sizeof(str)/sizeof(str[0]) for strings.

svn path=/trunk/; revision=75993
This commit is contained in:
Hermès Bélusca-Maïto 2017-09-30 09:13:04 +00:00
parent b6d999dbe4
commit 5e41079086
4 changed files with 40 additions and 39 deletions

View file

@ -84,7 +84,7 @@ static BOOLEAN StringsLoaded = FALSE;
static VOID LoadStrings(VOID)
{
LoadString(CMD_ModuleHandle, STRING_DELETE_WIPE, szDeleteWipe, ARRAYSIZE(szDeleteWipe));
GetModuleFileName(NULL, CMDPath, MAX_PATH);
GetModuleFileName(NULL, CMDPath, ARRAYSIZE(CMDPath));
StringsLoaded = TRUE;
}

View file

@ -389,10 +389,10 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & s
ptrEnd = Line;
/* Copy it to the entries list */
temp = cmd_alloc((ptrEnd - ptrStart + 1) * sizeof (TCHAR));
temp = cmd_alloc((ptrEnd - ptrStart + 1) * sizeof(TCHAR));
if (!temp)
return FALSE;
memcpy(temp, ptrStart, (ptrEnd - ptrStart) * sizeof (TCHAR));
memcpy(temp, ptrStart, (ptrEnd - ptrStart) * sizeof(TCHAR));
temp[ptrEnd - ptrStart] = _T('\0');
StripQuotes(temp);
if (!add_entry(entries, params, temp))
@ -419,7 +419,7 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & s
continue;
}
/* Process parameter switch */
switch(cCurSwitch)
switch (cCurSwitch)
{
case _T('A'): /* Switch parameters for /A (attributes filter) */
if (cCurChar == _T('-'))
@ -583,7 +583,7 @@ PrintDirectoryHeader(LPTSTR szPath, LPDIRSWITCHFLAGS lpFlags)
if (lpFlags->bBareFormat)
return TRUE;
if (GetFullPathName(szPath, sizeof(szFullDir) / sizeof(TCHAR), szFullDir, &pszFilePart) == 0)
if (GetFullPathName(szPath, ARRAYSIZE(szFullDir), szFullDir, &pszFilePart) == 0)
{
ErrorMessage(GetLastError(), _T("Failed to build full directory path"));
return FALSE;
@ -593,7 +593,7 @@ PrintDirectoryHeader(LPTSTR szPath, LPDIRSWITCHFLAGS lpFlags)
*pszFilePart = _T('\0');
/* get the media ID of the drive */
if (!GetVolumePathName(szFullDir, szRootName, sizeof(szRootName) / sizeof(TCHAR)) ||
if (!GetVolumePathName(szFullDir, szRootName, ARRAYSIZE(szRootName)) ||
!GetVolumeInformation(szRootName, szVolName, 80, &dwSerialNr,
NULL, NULL, NULL, 0))
{
@ -780,7 +780,7 @@ PrintSummary(LPTSTR szPath,
/* Take this code offline to fix /S does not print double info */
if (TotalSummary && lpFlags->bRecursive)
{
ConvertULargeInteger(u64Bytes, szBuffer, sizeof(szBuffer), lpFlags->bTSeparator);
ConvertULargeInteger(u64Bytes, szBuffer, ARRAYSIZE(szBuffer), lpFlags->bTSeparator);
LoadString(CMD_ModuleHandle, STRING_DIR_HELP5, szMsg, ARRAYSIZE(szMsg));
DirPrintf(lpFlags, szMsg, ulFiles, szBuffer);
}
@ -798,7 +798,7 @@ PrintSummary(LPTSTR szPath,
if (!lpFlags->bRecursive || TotalSummary)
{
GetUserDiskFreeSpace(szPath, &uliFree);
ConvertULargeInteger(uliFree.QuadPart, szBuffer, sizeof(szBuffer), lpFlags->bTSeparator);
ConvertULargeInteger(uliFree.QuadPart, szBuffer, ARRAYSIZE(szBuffer), lpFlags->bTSeparator);
LoadString(CMD_ModuleHandle, STRING_DIR_HELP6, szMsg, ARRAYSIZE(szMsg));
DirPrintf(lpFlags, szMsg, ulDirs, szBuffer);
}
@ -1136,7 +1136,7 @@ DirPrintFiles(PDIRFINDINFO ptrFiles[], /* [IN] Files' Info */
/* Condition to print header:
We are not printing in bare format
and if we are in recursive mode... we must have results */
if (!(lpFlags->bBareFormat ) && !((lpFlags->bRecursive) && (dwCount <= 0)))
if (!lpFlags->bBareFormat && !(lpFlags->bRecursive && (dwCount <= 0)))
{
LoadString(CMD_ModuleHandle, STRING_DIR_HELP7, szMsg, ARRAYSIZE(szMsg));
if (DirPrintf(lpFlags, szMsg, szTemp))
@ -1186,11 +1186,11 @@ CompareFiles(PDIRFINDINFO lpFile1, /* [IN] A pointer to WIN32_FIND_DATA of
long iComp = 0; /* The comparison result */
/* Calculate criteria by order given from user */
for (i = 0;i < lpFlags->stOrderBy.sCriteriaCount;i++)
for (i = 0; i < lpFlags->stOrderBy.sCriteriaCount; i++)
{
/* Calculate criteria */
switch(lpFlags->stOrderBy.eCriteria[i])
switch (lpFlags->stOrderBy.eCriteria[i])
{
case ORDER_SIZE: /* Order by size /o:s */
/* concat the 32bit integers to a 64bit */
@ -1223,7 +1223,7 @@ CompareFiles(PDIRFINDINFO lpFile1, /* [IN] A pointer to WIN32_FIND_DATA of
case ORDER_TIME: /* Order by file's time /o:t */
/* We compare files based on the time field selected by /t */
switch(lpFlags->stTimeField.eTimeField)
switch (lpFlags->stTimeField.eTimeField)
{
case TF_CREATIONDATE:
/* concat the 32bit integers to a 64bit */
@ -1323,7 +1323,7 @@ static INT
DirList(LPTSTR szPath, /* [IN] The path that dir starts */
LPDIRSWITCHFLAGS lpFlags) /* [IN] The flags of the listing */
{
BOOL fPoint; /* If szPath is a file with extension fPoint will be True*/
BOOL fPoint; /* If szPath is a file with extension fPoint will be True */
HANDLE hSearch; /* The handle of the search */
HANDLE hRecSearch; /* The handle for searching recursively */
HANDLE hStreams; /* The handle for alternate streams */
@ -1331,7 +1331,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
PDIRFINDINFO * ptrFileArray; /* An array of pointers with all the files */
PDIRFINDLISTNODE ptrStartNode; /* The pointer to the first node */
PDIRFINDLISTNODE ptrNextNode; /* A pointer used for relatives references */
TCHAR szFullPath[MAX_PATH]; /* The full path that we are listing with trailing \ */
TCHAR szFullPath[MAX_PATH]; /* The full path that we are listing with trailing '\' */
TCHAR szSubPath[MAX_PATH];
LPTSTR pszFilePart;
DWORD dwCount; /* A counter of files found in directory */
@ -1355,7 +1355,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
fPoint= FALSE;
/* Create szFullPath */
if (GetFullPathName(szPath, sizeof(szFullPath) / sizeof(TCHAR), szFullPath, &pszFilePart) == 0)
if (GetFullPathName(szPath, ARRAYSIZE(szFullPath), szFullPath, &pszFilePart) == 0)
{
_tcscpy (szFullPath, szPath);
pszFilePart = NULL;
@ -1381,7 +1381,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
ptrStartNode->stInfo.ptrHead = NULL;
ptrNextNode = ptrStartNode;
/*Checking ir szPath is a File with/wout extension*/
/* Checking if szPath is a File with/wout extension */
if (szPath[_tcslen(szPath) - 1] == _T('.'))
fPoint= TRUE;
@ -1391,7 +1391,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
{
do
{
/*If retrieved FileName has extension,and szPath doesnt have extension then JUMP the retrieved FileName*/
/* If retrieved FileName has extension,and szPath doesnt have extension then JUMP the retrieved FileName */
if (_tcschr(wfdFileInfo.cFileName,_T('.'))&&(fPoint==TRUE))
{
continue;
@ -1600,15 +1600,16 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
if (CheckCtrlBreak(BREAK_INPUT))
return 1;
/* Add statistics to recursive statistics*/
/* Add statistics to recursive statistics */
recurse_dir_cnt += dwCountDirs;
recurse_file_cnt += dwCountFiles;
recurse_bytes += u64CountBytes;
/* Do the recursive job if requested
the recursive is be done on ALL(independent of their attribs)
directories of the current one.*/
/*
* Do the recursive job if requested.
* The recursion is done on ALL (independent of their attributes)
* directories of the current one.
*/
if (lpFlags->bRecursive)
{
/* The new search is involving any *.* file */
@ -1638,7 +1639,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
return 1;
}
}
} while(FindNextFile(hRecSearch, &wfdFileInfo));
} while (FindNextFile(hRecSearch, &wfdFileInfo));
}
FindClose(hRecSearch);
}
@ -1718,7 +1719,7 @@ CommandDir(LPTSTR rest)
if (stFlags.bPause)
ConOutPrintfPaging(TRUE, _T(""));
for(loop = 0; loop < (UINT)entries; loop++)
for (loop = 0; loop < (UINT)entries; loop++)
{
if (CheckCtrlBreak(BREAK_INPUT))
{
@ -1757,14 +1758,14 @@ CommandDir(LPTSTR rest)
ChangedVolume = TRUE;
if (!stFlags.bBareFormat &&
GetVolumePathName(params[loop], path, sizeof(path) / sizeof(TCHAR)))
GetVolumePathName(params[loop], path, ARRAYSIZE(path)))
{
if (!_tcscmp(path, prev_volume))
ChangedVolume = FALSE;
else
_tcscpy(prev_volume, path);
}
else if (GetFullPathName(params[loop], sizeof(path) / sizeof(TCHAR), path, &pszFilePart) != 0)
else if (GetFullPathName(params[loop], ARRAYSIZE(path), path, &pszFilePart) != 0)
{
if (pszFilePart != NULL)
*pszFilePart = _T('\0');
@ -1784,7 +1785,7 @@ CommandDir(LPTSTR rest)
}
/* do the actual dir */
if (DirList (params[loop], &stFlags))
if (DirList(params[loop], &stFlags))
{
nErrorLevel = 1;
goto cleanup;

View file

@ -22,33 +22,33 @@ INT nTimeFormat;
INT nNumberGroups;
VOID InitLocale (VOID)
VOID InitLocale(VOID)
{
TCHAR szBuffer[256];
/* date settings */
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDATE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDATE, szBuffer, ARRAYSIZE(szBuffer));
cDateSeparator = szBuffer[0];
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR));
/* time settings */
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIME, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, szBuffer, ARRAYSIZE(szBuffer));
cTimeSeparator = szBuffer[0];
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR));
/* number settings */
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szBuffer, ARRAYSIZE(szBuffer));
cThousandSeparator = szBuffer[0];
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szBuffer, ARRAYSIZE(szBuffer));
cDecimalSeparator = szBuffer[0];
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SGROUPING, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, szBuffer, ARRAYSIZE(szBuffer));
nNumberGroups = _ttoi(szBuffer);
#if 0
/* days of week */
for (i = 0; i < 7; i++)
{
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
_tcscpy (aszDayNames[(i+1)%7], szBuffer); /* little hack */
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i, szBuffer, ARRAYSIZE(szBuffer));
_tcscpy(aszDayNames[(i+1)%7], szBuffer); /* little hack */
}
#endif
}
@ -62,7 +62,7 @@ GetDateString(VOID)
INT len;
GetLocalTime(&t);
len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, sizeof(szDate) / sizeof(szDate[0]));
len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, ARRAYSIZE(szDate));
szDate[len - 1] = _T(' ');
FormatDate(&szDate[len], &t, TRUE);
return szDate;

View file

@ -37,7 +37,7 @@ INT CommandMsgbox (LPTSTR param)
UINT uType = U_TYPE_INIT;
/* set default title to window title */
GetConsoleTitle(buff, 128);
GetConsoleTitle(buff, ARRAYSIZE(buff));
title = buff;
if (_tcsncmp (param, _T("/?"), 2) == 0)