ddnet/src/tools/map_resave.cpp
heinrich5991 17402cc43f Rename all variables for strict camel-casing of abbreviations
This is the strict version, ID → Id, UI → Ui, except DDNet which stays
DDNet.

This would fix #7750.

Done using a naive rename script (for bash, use `shopt -s globstar`):

```fish
sed -i \
	-e 's/\([a-z]_\?\)ID/\1Id/g' \
	-e 's/\([^ ]\)\<UI\>/\1Ui/g' \
	-e 's/UI()/Ui()/g' \
	-e 's/\<CUI\>/CUi/g' \
	-e 's/\([\ta-z.(&]\|[,=|] \)ID\>/\1Id/g' \
	-e 's/\<ID\>\([^ ").]\)/Id\1/g' \
	-e 's/\<ID\([0-9]\)/Id\1/g' \
	-e 's/\<ID\>\( [<=>:+*/-]\)/Id\1/g' \
	-e 's/int ID/int Id/g' \
	-e 's/\([a-z]_\?\)GPU/\1Gpu/g' \
	-e 's/\([a-z]_\?\)IP/\1Ip/g' \
	-e 's/\([a-z]_\?\)CID/\1Cid/g' \
	-e 's/\([a-z]_\?\)MySQL/\1Mysql/g' \
	-e 's/MySql/Mysql/g' \
	-e 's/\([a-xz]_\?\)SQL/\1Sql/g' \
	-e 's/DPMode/DpMode/g' \
	-e 's/TTWGraphics/TTwGraphics/g' \
	\
	-e 's/Ipointer/IPointer/g' \
	-e 's/\.vendorId/.vendorID/g' \
	-e 's/\.windowId/.windowID/g' \
	-e 's/SDL_GetWindowFromId/SDL_GetWindowFromID/g' \
	-e 's/SDL_AudioDeviceId/SDL_AudioDeviceID/g' \
	-e 's/SDL_JoystickId/SDL_JoystickID/g' \
	-e 's/SDL_JoystickInstanceId/SDL_JoystickInstanceID/g' \
	-e 's/AVCodecId/AVCodecID/g' \
	src/**/*.cpp src/**/*.h {datasrc,scripts}/**/*.py
git checkout -- src/engine/external
```

I like this option because it presents clear rules.

Still needs fixups because of the naive replacement, I'd do this if we
want this merged.
2024-03-05 15:44:09 +01:00

80 lines
1.9 KiB
C++

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/logger.h>
#include <base/system.h>
#include <engine/shared/datafile.h>
#include <engine/storage.h>
static const char *TOOL_NAME = "map_resave";
static int ResaveMap(const char *pSourceMap, const char *pDestinationMap, IStorage *pStorage)
{
CDataFileReader Reader;
if(!Reader.Open(pStorage, pSourceMap, IStorage::TYPE_ABSOLUTE))
{
log_error(TOOL_NAME, "Failed to open source map '%s' for reading", pSourceMap);
return -1;
}
CDataFileWriter Writer;
if(!Writer.Open(pStorage, pDestinationMap))
{
log_error(TOOL_NAME, "Failed to open destination map '%s' for writing", pDestinationMap);
Reader.Close();
return -1;
}
// add all items
for(int Index = 0; Index < Reader.NumItems(); Index++)
{
int Type, Id;
CUuid Uuid;
const void *pPtr = Reader.GetItem(Index, &Type, &Id, &Uuid);
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type == ITEMTYPE_EX)
{
continue;
}
int Size = Reader.GetItemSize(Index);
Writer.AddItem(Type, Id, Size, pPtr, &Uuid);
}
// add all data
for(int Index = 0; Index < Reader.NumData(); Index++)
{
const void *pPtr = Reader.GetData(Index);
int Size = Reader.GetDataSize(Index);
Writer.AddData(Size, pPtr);
}
Reader.Close();
Writer.Finish();
log_info(TOOL_NAME, "Resaved '%s' to '%s'", pSourceMap, pDestinationMap);
return 0;
}
int main(int argc, const char **argv)
{
CCmdlineFix CmdlineFix(&argc, &argv);
log_set_global_logger_default();
if(argc != 3)
{
log_error(TOOL_NAME, "Usage: %s <source map> <destination map>", TOOL_NAME);
return -1;
}
IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_BASIC, argc, argv);
if(!pStorage)
{
log_error(TOOL_NAME, "Error creating basic storage");
return -1;
}
return ResaveMap(argv[1], argv[2], pStorage);
}