1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-21 12:00:06 +00:00

texassemble/texconv/texdiag updated with improved -flist support (#239)

This commit is contained in:
Chuck Walbourn 2021-06-08 15:00:22 -07:00 committed by GitHub
parent ac071b3425
commit 848e37625a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 264 additions and 90 deletions

View File

@ -20,17 +20,21 @@
#define NOHELP
#pragma warning(pop)
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <cwctype>
#include <fstream>
#include <iterator>
#include <list>
#include <locale>
#include <memory>
#include <new>
#include <set>
#include <string>
#include <utility>
#include <vector>
@ -472,6 +476,90 @@ namespace
}
}
void ProcessFileList(std::wifstream& inFile, std::list<SConversion>& files)
{
std::list<SConversion> flist;
std::set<std::wstring> excludes;
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
if (flist.empty())
{
wprintf(L"WARNING: Ignoring the line '%ls' in -flist\n", fname);
}
else
{
if (wcspbrk(fname, L"?*") != nullptr)
{
std::list<SConversion> removeFiles;
SearchForFiles(&fname[1], removeFiles, false);
for (auto it : removeFiles)
{
_wcslwr_s(it.szSrc);
excludes.insert(it.szSrc);
}
}
else
{
std::wstring name = (fname + 1);
std::transform(name.begin(), name.end(), name.begin(), towlower);
excludes.insert(name);
}
}
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
SearchForFiles(fname, flist, false);
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
flist.push_back(conv);
}
inFile.ignore(1000, '\n');
}
inFile.close();
if (!excludes.empty())
{
// Remove any excluded files
for (auto it = flist.begin(); it != flist.end();)
{
std::wstring name = it->szSrc;
std::transform(name.begin(), name.end(), name.begin(), towlower);
auto item = it;
++it;
if (excludes.find(name) != excludes.end())
{
flist.erase(item);
}
}
}
if (flist.empty())
{
wprintf(L"WARNING: No file names found in -flist\n");
}
else
{
files.splice(files.end(), flist);
}
}
void PrintFormat(DXGI_FORMAT Format)
{
for (auto pFormat = g_pFormats; pFormat->name; pFormat++)
@ -1070,37 +1158,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf(L"Error opening -flist file %ls\n", pValue);
return 1;
}
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
wprintf(L"Command-line arguments not supported in -flist file\n");
return 1;
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
wprintf(L"Wildcards not supported in -flist file\n");
return 1;
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
conversion.push_back(conv);
}
inFile.ignore(1000, '\n');
}
inFile.close();
ProcessFileList(inFile, conversion);
}
break;

View File

@ -27,12 +27,14 @@
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <cwctype>
#include <fstream>
#include <iterator>
#include <list>
#include <locale>
#include <memory>
#include <new>
#include <set>
#include <string>
#include <wrl\client.h>
@ -617,6 +619,90 @@ namespace
}
}
void ProcessFileList(std::wifstream& inFile, std::list<SConversion>& files)
{
std::list<SConversion> flist;
std::set<std::wstring> excludes;
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
if (flist.empty())
{
wprintf(L"WARNING: Ignoring the line '%ls' in -flist\n", fname);
}
else
{
if (wcspbrk(fname, L"?*") != nullptr)
{
std::list<SConversion> removeFiles;
SearchForFiles(&fname[1], removeFiles, false, nullptr);
for (auto it : removeFiles)
{
_wcslwr_s(it.szSrc);
excludes.insert(it.szSrc);
}
}
else
{
std::wstring name = (fname + 1);
std::transform(name.begin(), name.end(), name.begin(), towlower);
excludes.insert(name);
}
}
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
SearchForFiles(fname, flist, false, nullptr);
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
flist.push_back(conv);
}
inFile.ignore(1000, '\n');
}
inFile.close();
if (!excludes.empty())
{
// Remove any excluded files
for (auto it = flist.begin(); it != flist.end();)
{
std::wstring name = it->szSrc;
std::transform(name.begin(), name.end(), name.begin(), towlower);
auto item = it;
++it;
if (excludes.find(name) != excludes.end())
{
flist.erase(item);
}
}
}
if (flist.empty())
{
wprintf(L"WARNING: No file names found in -flist\n");
}
else
{
files.splice(files.end(), flist);
}
}
void PrintFormat(DXGI_FORMAT Format)
{
for (auto pFormat = g_pFormats; pFormat->name; pFormat++)
@ -1771,37 +1857,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf(L"Error opening -flist file %ls\n", pValue);
return 1;
}
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
wprintf(L"Command-line arguments not supported in -flist file\n");
return 1;
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
wprintf(L"Wildcards not supported in -flist file\n");
return 1;
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
conversion.push_back(conv);
}
inFile.ignore(1000, '\n');
}
inFile.close();
ProcessFileList(inFile, conversion);
}
break;

View File

@ -26,11 +26,14 @@
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <cwctype>
#include <fstream>
#include <iterator>
#include <list>
#include <locale>
#include <memory>
#include <set>
#include <string>
#include <new>
#include <vector>
@ -477,6 +480,90 @@ namespace
}
}
void ProcessFileList(std::wifstream& inFile, std::list<SConversion>& files)
{
std::list<SConversion> flist;
std::set<std::wstring> excludes;
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
if (flist.empty())
{
wprintf(L"WARNING: Ignoring the line '%ls' in -flist\n", fname);
}
else
{
if (wcspbrk(fname, L"?*") != nullptr)
{
std::list<SConversion> removeFiles;
SearchForFiles(&fname[1], removeFiles, false);
for (auto it : removeFiles)
{
_wcslwr_s(it.szSrc);
excludes.insert(it.szSrc);
}
}
else
{
std::wstring name = (fname + 1);
std::transform(name.begin(), name.end(), name.begin(), towlower);
excludes.insert(name);
}
}
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
SearchForFiles(fname, flist, false);
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
flist.push_back(conv);
}
inFile.ignore(1000, '\n');
}
inFile.close();
if (!excludes.empty())
{
// Remove any excluded files
for (auto it = flist.begin(); it != flist.end();)
{
std::wstring name = it->szSrc;
std::transform(name.begin(), name.end(), name.begin(), towlower);
auto item = it;
++it;
if (excludes.find(name) != excludes.end())
{
flist.erase(item);
}
}
}
if (flist.empty())
{
wprintf(L"WARNING: No file names found in -flist\n");
}
else
{
files.splice(files.end(), flist);
}
}
void PrintFormat(DXGI_FORMAT Format)
{
for (auto pFormat = g_pFormats; pFormat->name; pFormat++)
@ -3296,37 +3383,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf(L"Error opening -flist file %ls\n", pValue);
return 1;
}
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
wprintf(L"Command-line arguments not supported in -flist file\n");
return 1;
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
wprintf(L"Wildcards not supported in -flist file\n");
return 1;
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
conversion.push_back(conv);
}
inFile.ignore(1000, '\n');
}
inFile.close();
ProcessFileList(inFile, conversion);
}
break;