code review for command-line tool

This commit is contained in:
Chuck Walbourn
2021-04-24 19:57:56 -07:00
parent 29c99117f2
commit 32faa3bec4
3 changed files with 125 additions and 122 deletions

View File

@@ -73,7 +73,7 @@ namespace
CMD_MAX
};
enum OPTIONS
enum OPTIONS : uint32_t
{
OPT_RECURSIVE = 1,
OPT_FILELIST,
@@ -102,7 +102,7 @@ namespace
OPT_MAX
};
static_assert(OPT_MAX <= 32, "dwOptions is a DWORD bitfield");
static_assert(OPT_MAX <= 32, "dwOptions is a unsigned int bitfield");
struct SConversion
{
@@ -111,8 +111,8 @@ namespace
struct SValue
{
LPCWSTR pName;
DWORD dwValue;
const wchar_t* name;
uint32_t value;
};
//////////////////////////////////////////////////////////////////////////////
@@ -383,12 +383,12 @@ namespace
#pragma prefast(disable : 26018, "Only used with static internal arrays")
#endif
DWORD LookupByName(const wchar_t *pName, const SValue *pArray)
uint32_t LookupByName(const wchar_t *pName, const SValue *pArray)
{
while (pArray->pName)
while (pArray->name)
{
if (!_wcsicmp(pName, pArray->pName))
return pArray->dwValue;
if (!_wcsicmp(pName, pArray->name))
return pArray->value;
pArray++;
}
@@ -472,11 +472,11 @@ namespace
void PrintFormat(DXGI_FORMAT Format)
{
for (const SValue *pFormat = g_pFormats; pFormat->pName; pFormat++)
for (auto pFormat = g_pFormats; pFormat->name; pFormat++)
{
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
if (static_cast<DXGI_FORMAT>(pFormat->value) == Format)
{
wprintf(L"%ls", pFormat->pName);
wprintf(L"%ls", pFormat->name);
break;
}
}
@@ -543,9 +543,9 @@ namespace
void PrintList(size_t cch, const SValue *pValue)
{
while (pValue->pName)
while (pValue->name)
{
size_t cchName = wcslen(pValue->pName);
size_t cchName = wcslen(pValue->name);
if (cch + cchName + 2 >= 80)
{
@@ -553,7 +553,7 @@ namespace
cch = 6;
}
wprintf(L"%ls ", pValue->pName);
wprintf(L"%ls ", pValue->name);
cch += cchName + 2;
pValue++;
}
@@ -678,7 +678,7 @@ namespace
PrintList(13, g_pFeatureLevels);
}
HRESULT SaveImageFile(const Image& img, DWORD fileType, const wchar_t* szOutputFile)
HRESULT SaveImageFile(const Image& img, uint32_t fileType, const wchar_t* szOutputFile)
{
switch (fileType)
{
@@ -844,11 +844,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
TEX_FILTER_FLAGS dwFilter = TEX_FILTER_DEFAULT;
TEX_FILTER_FLAGS dwSRGB = TEX_FILTER_DEFAULT;
TEX_FILTER_FLAGS dwFilterOpts = TEX_FILTER_DEFAULT;
DWORD fileType = WIC_CODEC_BMP;
DWORD maxSize = 16384;
DWORD maxCube = 16384;
DWORD maxArray = 2048;
DWORD maxVolume = 2048;
uint32_t fileType = WIC_CODEC_BMP;
uint32_t maxSize = 16384;
uint32_t maxCube = 16384;
uint32_t maxArray = 2048;
uint32_t maxVolume = 2048;
// DXTex's Open Alpha onto Surface always loaded alpha from the blue channel
uint32_t permuteElements[4] = { 0, 1, 2, 6 };
@@ -872,7 +872,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 0;
}
DWORD dwCommand = LookupByName(argv[1], g_pCommands);
uint32_t dwCommand = LookupByName(argv[1], g_pCommands);
switch (dwCommand)
{
case CMD_CUBE:
@@ -893,7 +893,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
DWORD dwOptions = 0;
uint32_t dwOptions = 0;
std::list<SConversion> conversion;
for (int iArg = 2; iArg < argc; iArg++)
@@ -910,7 +910,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (*pValue)
*pValue++ = 0;
DWORD dwOption = LookupByName(pArg, g_pOptions);
uint32_t dwOption = LookupByName(pArg, g_pOptions);
if (!dwOption || (dwOptions & (1 << dwOption)))
{