Skip to content

Commit

Permalink
add a flat file containing strings to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Poggicek committed Oct 8, 2024
1 parent cf4ee3e commit 8037096
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/main/dumpers/concommands/concommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void WriteValueLine(ConVar* pCvar, std::ofstream& stream)
void FixNewlineTabbing(std::string& str)
{
auto it = str.begin();
while ((it = std::find(it, str.end(), '\n')) != str.end()) {
while ((it = std::find(it, str.end(), '\n')) != str.end())
{
if (it + 1 == str.end() || *(it + 1) != '\t')
it = str.insert(it + 1, '\t') + 1;
else
Expand All @@ -227,6 +228,25 @@ void FixNewlineTabbing(std::string& str)
str.pop_back();
}

std::string EscapeDescription(std::string str)
{
for (auto it = str.begin(); it != str.end(); it++) {
if (*it == '\n')
{
*it = '\\';
it = str.insert(it + 1, 'n');
}
else if (*it == '\t')
{
*it = '\\';
it = str.insert(it + 1, 't');
}
}

return str;
}


void DumpConVars()
{
ConVarHandle hCvarHandle;
Expand Down Expand Up @@ -261,14 +281,16 @@ void DumpConVars()
if (cvar->m_pszHelpString[0])
{
helpString = cvar->m_pszHelpString;
Globals::stringsIgnoreStream << EscapeDescription(helpString) << "\n";
FixNewlineTabbing(helpString);
}

output << cvar->m_pszName;
WriteValueLine(cvar, output);
output << "\n\t" << helpString;

output << "\n" << std::endl;

Globals::stringsIgnoreStream << cvar->m_pszName << "\n";
}
}

Expand Down Expand Up @@ -308,14 +330,16 @@ void DumpCommands()
if (command->m_pszHelpString[0])
{
helpString = command->m_pszHelpString;
Globals::stringsIgnoreStream << EscapeDescription(helpString) << "\n";
FixNewlineTabbing(helpString);
}

output << command->m_pszName << " (";
WriteFlags(command->m_nFlags, output);
output << ")\n\t" << helpString;

output << "\n" << std::endl;

Globals::stringsIgnoreStream << command->m_pszName << "\n";
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/dumpers/schemas/schemas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void DumpClasses(CSchemaSystemTypeScope* typeScope, std::filesystem::path schema
std::ofstream output((schemaPath / classInfo->m_pszProjectName / sanitizedFileName).replace_extension(".h"));

output << "class " << classInfo->m_pszName;
Globals::stringsIgnoreStream << classInfo->m_pszName << "\n";

if (classInfo->m_nBaseClassCount > 0)
output << " : public " << classInfo->m_pBaseClasses[0].m_pClass->m_pszName;
Expand All @@ -65,6 +66,7 @@ void DumpClasses(CSchemaSystemTypeScope* typeScope, std::filesystem::path schema
const auto& field = classInfo->m_pFields[k];

output << "\t" << field.m_pType->m_sTypeName.String() << " " << field.m_pszName << ";\n";
Globals::stringsIgnoreStream << field.m_pszName << "\n";
}

output << "};\n";
Expand Down Expand Up @@ -95,6 +97,7 @@ void DumpEnums(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPa
std::ofstream output((schemaPath / enumInfo->m_pszProjectName / sanitizedFileName).replace_extension(".h"));

output << "enum " << enumInfo->m_pszName << " : ";
Globals::stringsIgnoreStream << enumInfo->m_pszName << "\n";

switch (enumInfo->m_nAlignment)
{
Expand All @@ -121,6 +124,7 @@ void DumpEnums(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPa
const auto& field = enumInfo->m_pEnumerators[k];

output << "\t" << field.m_pszName << " = " << field.m_nValue << ",\n";
Globals::stringsIgnoreStream << field.m_pszName << "\n";
}

output << "};\n";
Expand Down
2 changes: 2 additions & 0 deletions src/main/globalvariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

#include <string>
#include <filesystem>
#include <fstream>

namespace Globals {

inline std::string modName;
inline std::filesystem::path outputPath;
inline std::ofstream stringsIgnoreStream;

} // namespace Interfaces
2 changes: 2 additions & 0 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int main(int argc, char** argv)
return 0;
}

Globals::stringsIgnoreStream = std::ofstream(Globals::outputPath / ".stringsignore");

InitializeCoreModules();
InitializeAppSystems();

Expand Down

0 comments on commit 8037096

Please sign in to comment.