refactor(Tools): restyle tools with astyle (#3705)

This commit is contained in:
Kargatum
2020-11-18 09:49:56 +07:00
committed by GitHub
parent 4457e85079
commit 85927685f2
30 changed files with 152 additions and 152 deletions

View File

@@ -98,7 +98,7 @@ static const char* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koK
void CreateDir( const std::string& Path )
{
if(chdir(Path.c_str()) == 0)
if (chdir(Path.c_str()) == 0)
{
int ret = chdir("../");
if (ret < 0)
@@ -124,7 +124,7 @@ void CreateDir( const std::string& Path )
bool FileExists( const char* FileName )
{
int fp = _open(FileName, OPEN_FLAGS);
if(fp != -1)
if (fp != -1)
{
_close(fp);
return true;
@@ -148,41 +148,41 @@ void Usage(char* prg)
void HandleArgs(int argc, char* arg[])
{
for(int c = 1; c < argc; ++c)
for (int c = 1; c < argc; ++c)
{
// i - input path
// o - output path
// e - extract only MAP(1)/DBC(2) - standard both(3)
// f - use float to int conversion
// h - limit minimum height
if(arg[c][0] != '-')
if (arg[c][0] != '-')
Usage(arg[0]);
switch(arg[c][1])
switch (arg[c][1])
{
case 'i':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
strcpy(input_path, arg[(c++) + 1]);
else
Usage(arg[0]);
break;
case 'o':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
strcpy(output_path, arg[(c++) + 1]);
else
Usage(arg[0]);
break;
case 'f':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
CONF_allow_float_to_int = atoi(arg[(c++) + 1]) != 0;
else
Usage(arg[0]);
break;
case 'e':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
{
CONF_extract = atoi(arg[(c++) + 1]);
if(!(CONF_extract > 0 && CONF_extract < 4))
if (!(CONF_extract > 0 && CONF_extract < 4))
Usage(arg[0]);
}
else
@@ -199,7 +199,7 @@ uint32 ReadBuild(int locale)
//printf("Read %s file... ", filename.c_str());
MPQFile m(filename.c_str());
if(m.isEof())
if (m.isEof())
{
printf("Fatal error: Not found %s file!\n", filename.c_str());
exit(1);
@@ -234,7 +234,7 @@ uint32 ReadMapDBC()
printf("Read Map.dbc file... ");
DBCFile dbc("DBFilesClient\\Map.dbc");
if(!dbc.open())
if (!dbc.open())
{
printf("Fatal error: Invalid Map.dbc file format!\n");
exit(1);
@@ -242,7 +242,7 @@ uint32 ReadMapDBC()
size_t map_count = dbc.getRecordCount();
map_ids = new map_id[map_count];
for(uint32 x = 0; x < map_count; ++x)
for (uint32 x = 0; x < map_count; ++x)
{
map_ids[x].id = dbc.getRecord(x).getUInt(0);
strcpy(map_ids[x].name, dbc.getRecord(x).getString(1));
@@ -255,7 +255,7 @@ void ReadLiquidTypeTableDBC()
{
printf("Read LiquidType.dbc file...");
DBCFile dbc("DBFilesClient\\LiquidType.dbc");
if(!dbc.open())
if (!dbc.open())
{
printf("Fatal error: Invalid LiquidType.dbc file format!\n");
exit(1);
@@ -266,7 +266,7 @@ void ReadLiquidTypeTableDBC()
LiqType = new uint16[liqTypeMaxId + 1];
memset(LiqType, 0xff, (liqTypeMaxId + 1) * sizeof(uint16));
for(uint32 x = 0; x < liqTypeCount; ++x)
for (uint32 x = 0; x < liqTypeCount; ++x)
LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
printf("Done! (%u LiqTypes loaded)\n", (uint32)liqTypeCount);
@@ -522,7 +522,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
}
for (int y = 0; y <= ADT_GRID_SIZE; y++)
{
for(int x = 0; x <= ADT_GRID_SIZE; x++)
for (int x = 0; x <= ADT_GRID_SIZE; x++)
{
float h = V9[y][x];
if (maxHeight < h) maxHeight = h;
@@ -690,7 +690,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
{
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
{
for(int j = 0; j < ADT_CELLS_PER_GRID; j++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_liquid_header* h = h2o->getLiquidData(i, j);
if (!h)
@@ -768,7 +768,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
bool fullType = false;
for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
{
for(int x = 0; x < ADT_CELLS_PER_GRID; x++)
for (int x = 0; x < ADT_CELLS_PER_GRID; x++)
{
if (liquid_flags[y][x] != type)
{
@@ -796,7 +796,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
minHeight = 20000;
for (int y = 0; y < ADT_GRID_SIZE; y++)
{
for(int x = 0; x < ADT_GRID_SIZE; x++)
for (int x = 0; x < ADT_GRID_SIZE; x++)
{
if (liquid_show[y][x])
{
@@ -953,7 +953,7 @@ void ExtractMapsFromMpq(uint32 build)
CreateDir(path);
printf("Convert map files\n");
for(uint32 z = 0; z < map_count; ++z)
for (uint32 z = 0; z < map_count; ++z)
{
printf("Extract %s (%d/%u) \n", map_ids[z].name, z + 1, map_count);
// Loadup map grid data
@@ -965,9 +965,9 @@ void ExtractMapsFromMpq(uint32 build)
continue;
}
for(uint32 y = 0; y < WDT_MAP_SIZE; ++y)
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
{
for(uint32 x = 0; x < WDT_MAP_SIZE; ++x)
for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
{
if (!wdt.main->adt_list[y][x].exist)
continue;
@@ -986,13 +986,13 @@ void ExtractMapsFromMpq(uint32 build)
bool ExtractFile( char const* mpq_name, std::string const& filename )
{
FILE* output = fopen(filename.c_str(), "wb");
if(!output)
if (!output)
{
printf("Can't create the output file '%s'\n", filename.c_str());
return false;
}
MPQFile m(mpq_name);
if(!m.isEof())
if (!m.isEof())
fwrite(m.getPointer(), 1, m.getSize(), output);
fclose(output);
@@ -1006,7 +1006,7 @@ void ExtractDBCFiles(int locale, bool basicLocale)
std::set<std::string> dbcfiles;
// get DBC file list
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
{
vector<string> files;
(*i)->GetFileListTo(files);
@@ -1018,7 +1018,7 @@ void ExtractDBCFiles(int locale, bool basicLocale)
std::string path = output_path;
path += "/dbc/";
CreateDir(path);
if(!basicLocale)
if (!basicLocale)
{
path += langs[locale];
path += "/";
@@ -1040,7 +1040,7 @@ void ExtractDBCFiles(int locale, bool basicLocale)
string filename = path;
filename += (iter->c_str() + strlen("DBFilesClient\\"));
if(FileExists(filename.c_str()))
if (FileExists(filename.c_str()))
continue;
if (ExtractFile(iter->c_str(), filename))
@@ -1056,14 +1056,14 @@ void LoadLocaleMPQFiles(int const locale)
sprintf(filename, "%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]);
new MPQArchive(filename);
for(int i = 1; i < 5; ++i)
for (int i = 1; i < 5; ++i)
{
char ext[3] = "";
if(i > 1)
if (i > 1)
sprintf(ext, "-%i", i);
sprintf(filename, "%s/Data/%s/patch-%s%s.MPQ", input_path, langs[locale], langs[locale], ext);
if(FileExists(filename))
if (FileExists(filename))
new MPQArchive(filename);
}
}
@@ -1072,17 +1072,17 @@ void LoadCommonMPQFiles()
{
char filename[512];
int count = sizeof(CONF_mpq_list) / sizeof(char*);
for(int i = 0; i < count; ++i)
for (int i = 0; i < count; ++i)
{
sprintf(filename, "%s/Data/%s", input_path, CONF_mpq_list[i]);
if(FileExists(filename))
if (FileExists(filename))
new MPQArchive(filename);
}
}
inline void CloseMPQFiles()
{
for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end(); ++j) (*j)->close();
for (ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end(); ++j) (*j)->close();
gOpenArchives.clear();
}
@@ -1107,7 +1107,7 @@ int main(int argc, char* arg[])
//Open MPQs
LoadLocaleMPQFiles(i);
if((CONF_extract & EXTRACT_DBC) == 0)
if ((CONF_extract & EXTRACT_DBC) == 0)
{
FirstLocale = i;
build = ReadBuild(FirstLocale);
@@ -1116,7 +1116,7 @@ int main(int argc, char* arg[])
}
//Extract DBC files
if(FirstLocale < 0)
if (FirstLocale < 0)
{
FirstLocale = i;
build = ReadBuild(FirstLocale);
@@ -1131,7 +1131,7 @@ int main(int argc, char* arg[])
}
}
if(FirstLocale < 0)
if (FirstLocale < 0)
{
printf("No locales detected\n");
return 0;

View File

@@ -24,8 +24,8 @@ bool isHole(int holes, int i, int j)
{
int testi = i / 2;
int testj = j / 4;
if(testi > 3) testi = 3;
if(testj > 3) testj = 3;
if (testi > 3) testi = 3;
if (testj > 3) testj = 3;
return (holes & holetab_h[testi] & holetab_v[testj]) != 0;
}

View File

@@ -21,33 +21,33 @@ bool DBCFile::open()
char header[4];
unsigned int na, nb, es, ss;
if(f.read(header, 4) != 4) // Number of records
if (f.read(header, 4) != 4) // Number of records
return false;
if(header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
if (header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
return false;
if(f.read(&na, 4) != 4) // Number of records
if (f.read(&na, 4) != 4) // Number of records
return false;
if(f.read(&nb, 4) != 4) // Number of fields
if (f.read(&nb, 4) != 4) // Number of fields
return false;
if(f.read(&es, 4) != 4) // Size of a record
if (f.read(&es, 4) != 4) // Size of a record
return false;
if(f.read(&ss, 4) != 4) // String size
if (f.read(&ss, 4) != 4) // String size
return false;
recordSize = es;
recordCount = na;
fieldCount = nb;
stringSize = ss;
if(fieldCount * 4 != recordSize)
if (fieldCount * 4 != recordSize)
return false;
data = new unsigned char[recordSize * recordCount + stringSize];
stringTable = data + recordSize * recordCount;
size_t data_size = recordSize * recordCount + stringSize;
if(f.read(data, data_size) != data_size)
if (f.read(data, data_size) != data_size)
return false;
f.close();
return true;
@@ -68,9 +68,9 @@ size_t DBCFile::getMaxId()
assert(data);
size_t maxId = 0;
for(size_t i = 0; i < getRecordCount(); ++i)
for (size_t i = 0; i < getRecordCount(); ++i)
{
if(maxId < getRecord(i).getUInt(0))
if (maxId < getRecord(i).getUInt(0))
maxId = getRecord(i).getUInt(0);
}
return maxId;

View File

@@ -30,7 +30,7 @@ bool FileLoader::loadFile(std::string const& fileName, bool log)
{
free();
MPQFile mf(fileName.c_str());
if(mf.isEof())
if (mf.isEof())
{
if (log)
printf("No such file %s\n", fileName.c_str());

View File

@@ -14,9 +14,9 @@ MPQArchive::MPQArchive(const char* filename)
{
int result = libmpq__archive_open(&mpq_a, filename, -1);
printf("Opening %s\n", filename);
if(result)
if (result)
{
switch(result)
switch (result)
{
case LIBMPQ_ERROR_OPEN :
printf("Error opening archive '%s': Does file really exist?\n", filename);
@@ -54,12 +54,12 @@ MPQFile::MPQFile(const char* filename):
pointer(0),
size(0)
{
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
{
mpq_archive* mpq_a = (*i)->mpq_a;
uint32_t filenum;
if(libmpq__file_number(mpq_a, filename, &filenum)) continue;
if (libmpq__file_number(mpq_a, filename, &filenum)) continue;
libmpq__off_t transferred;
libmpq__file_unpacked_size(mpq_a, filenum, &size);

View File

@@ -30,7 +30,7 @@ public:
void GetFileListTo(vector<string>& filelist)
{
uint32_t filenum;
if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
if (libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
libmpq__off_t size, transferred;
libmpq__file_unpacked_size(mpq_a, filenum, &size);