Codechange: Replace FOR_ALL_TARS with range-based for loops

pull/332/head
glx22 3 years ago committed by Loïc Guilloux
parent 7bcc472f73
commit 34215f7faa

@ -1345,12 +1345,12 @@ static uint ScanPath(FileScanner *fs, const char *extension, const char *path, s
* @param extension the extension of files to search for.
* @param tar the tar to search in.
*/
static uint ScanTar(FileScanner *fs, const char *extension, TarFileList::iterator tar)
static uint ScanTar(FileScanner *fs, const char *extension, const TarFileList::value_type &tar)
{
uint num = 0;
const auto &filename = (*tar).first;
const auto &filename = tar.first;
if (MatchesExtension(extension, filename.c_str()) && fs->AddFile(filename, 0, (*tar).second.tar_filename)) num++;
if (MatchesExtension(extension, filename.c_str()) && fs->AddFile(filename, 0, tar.second.tar_filename)) num++;
return num;
}
@ -1369,7 +1369,6 @@ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool r
this->subdir = sd;
Searchpath sp;
TarFileList::iterator tar;
uint num = 0;
FOR_ALL_SEARCHPATHS(sp) {
@ -1381,7 +1380,7 @@ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool r
}
if (tars && sd != NO_DIRECTORY) {
FOR_ALL_TARS(tar, sd) {
for (const auto &tar : _tar_filelist[sd]) {
num += ScanTar(this, extension, tar);
}
}

@ -249,16 +249,15 @@ GameStrings *LoadTranslations()
if (!tar_filename.empty() && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) {
/* The main script is in a tar file, so find all files that
* are in the same tar and add them to the langfile scanner. */
TarFileList::iterator tar;
FOR_ALL_TARS(tar, GAME_DIR) {
for (const auto &tar : _tar_filelist[GAME_DIR]) {
/* Not in the same tar. */
if (tar->second.tar_filename != iter->first) continue;
if (tar.second.tar_filename != iter->first) continue;
/* Check the path and extension. */
if (tar->first.size() <= ldir.size() || tar->first.compare(0, ldir.size(), ldir) != 0) continue;
if (tar->first.compare(tar->first.size() - 4, 4, ".txt") != 0) continue;
if (tar.first.size() <= ldir.size() || tar.first.compare(0, ldir.size(), ldir) != 0) continue;
if (tar.first.compare(tar.first.size() - 4, 4, ".txt") != 0) continue;
scanner.AddFile(tar->first, 0, tar_filename);
scanner.AddFile(tar.first, 0, tar_filename);
}
} else {
/* Scan filesystem */

@ -224,16 +224,15 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
/* The main script is in a tar file, so find all files that
* are in the same tar and add them to the MD5 checksumming. */
TarFileList::iterator tar;
FOR_ALL_TARS(tar, dir) {
for (const auto &tar : _tar_filelist[dir]) {
/* Not in the same tar. */
if (tar->second.tar_filename != iter->first) continue;
if (tar.second.tar_filename != iter->first) continue;
/* Check the extension. */
const char *ext = strrchr(tar->first.c_str(), '.');
const char *ext = strrchr(tar.first.c_str(), '.');
if (ext == nullptr || strcasecmp(ext, ".nut") != 0) continue;
checksum.AddFile(tar->first, 0, tar_filename);
checksum.AddFile(tar.first, 0, tar_filename);
}
} else {
char path[MAX_PATH];

@ -28,6 +28,4 @@ typedef std::map<std::string, TarFileListEntry> TarFileList;
extern std::array<TarList, NUM_SUBDIRS> _tar_list;
extern TarFileList _tar_filelist[NUM_SUBDIRS];
#define FOR_ALL_TARS(tar, sd) for (tar = _tar_filelist[sd].begin(); tar != _tar_filelist[sd].end(); tar++)
#endif /* TAR_TYPE_H */

Loading…
Cancel
Save