Some format/textual edits to code

* line indents.
* remove trailing spaces.
* use nullptr instead of NULL for pointers.

Edited the error messages of get_ini_config.
This commit is contained in:
NovaRain
2023-06-19 12:14:31 +08:00
parent 14f6de0329
commit ae7921fe26
10 changed files with 77 additions and 73 deletions
+13 -13
View File
@@ -18,9 +18,9 @@
#include "Config.h"
#include "Main.h"
#include "main.h"
#include "FalloutEngine\Fallout2.h"
#include "Utils.h"
#include "FalloutEngine/Fallout2.h"
using namespace fo;
@@ -34,7 +34,7 @@ const Config::Data& Config::data()
bool Config::read(const char* filePath, bool isDb)
{
if (filePath == NULL) {
if (filePath == nullptr) {
return false;
}
@@ -43,21 +43,21 @@ bool Config::read(const char* filePath, bool isDb)
if (isDb) {
DbFile* stream = func::db_fopen(filePath, "rb");
if (stream == NULL) return false;
if (stream == nullptr) return false;
while (func::db_fgets(string, sizeof(string), stream) != NULL) {
while (func::db_fgets(string, sizeof(string), stream) != nullptr) {
parseLine(string);
}
func::db_fclose(stream);
} else {
FILE* stream = fopen(filePath, "rt");
// CE: Return `false` if file does not exists on the file system.
if (stream == NULL) {
// CE: Return false if file does not exist on the file system.
if (stream == nullptr) {
return false;
}
while (fgets(string, sizeof(string), stream) != NULL) {
while (fgets(string, sizeof(string), stream) != nullptr) {
parseLine(string);
}
fclose(stream);
@@ -71,13 +71,13 @@ bool Config::read(const char* filePath, bool isDb)
// Both key and value are trimmed.
bool Config::parseKeyValue(char* string, std::string& key, std::string& value)
{
if (string == NULL) {
if (string == nullptr) {
return false;
}
// Find equals character.
char* pch = strchr(string, '=');
if (pch == NULL) {
if (pch == nullptr) {
return false;
}
@@ -99,7 +99,7 @@ bool Config::parseLine(char* string)
// Find comment marker and truncate the string.
pch = strchr(string, ';');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
}
@@ -114,7 +114,7 @@ bool Config::parseLine(char* string)
// Find closing bracket.
pch = strchr(sectionKey, ']');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
trim(sectionKey);
_lastSection = sectionKey;
@@ -167,7 +167,7 @@ bool Config::getDouble(const char* sectionKey, const char* key, double& outValue
const std::string* value;
if (!getString(sectionKey, key, value)) return false;
outValue = strtod(value->c_str(), NULL);
outValue = strtod(value->c_str(), nullptr);
return true;
}
+3 -3
View File
@@ -18,11 +18,11 @@
#include "IniReader.h"
#include "main.h"
#include "FalloutEngine\Fallout2.h"
#include "Modules\LoadGameHook.h"
#include "Config.h"
#include "Main.h"
#include "Utils.h"
#include "FalloutEngine/Fallout2.h"
#include "Modules/LoadGameHook.h"
namespace sfall
{
-1
View File
@@ -140,4 +140,3 @@ void LoggingInit() {
}
}
+1 -1
View File
@@ -485,7 +485,7 @@ static void DebugModePatch() {
MakeCall(0x4C703F, debug_log_hack);
BlockCall(0x4C7044); // just nop code
}
// replace calling debug_printf_ with _debug_func, to avoid buffer overflow with messages longer than 260-bytes.
// replace calling debug_printf_ with _debug_func, to avoid buffer overflow with messages longer than 260 bytes
MakeCall(0x45540F, op_display_msg_hack);
MakeCall(0x45CB4E, op_debug_msg_hack);
+1 -1
View File
@@ -29,7 +29,7 @@ namespace sfall
namespace script
{
#define ARRAY_MAX_STRING (1024) // maximum length of string to be stored as array key or value (including null-terminator)
#define ARRAY_MAX_STRING (1024) // maximum length of string to be stored as array key or value (including null terminator)
#define ARRAY_MAX_SIZE (100000) // maximum number of array elements,
// so total maximum memory/disk footprint of one array is: 16 + (ARRAY_MAX_STRING + 8) * ARRAY_MAX_SIZE
@@ -23,6 +23,7 @@
#include "..\..\ScriptExtender.h"
#include "..\Arrays.h"
#include <memory>
#include <unordered_map>
namespace sfall
@@ -181,7 +182,7 @@ void mf_get_ini_sections(OpcodeContext& ctx) {
}
const auto& data = config->data();
size_t numSections = config->data().size();
int arrayId = CreateTempArray(numSections, 0);
DWORD arrayId = CreateTempArray(numSections, 0);
size_t i = 0;
for (auto sectIt = data.cbegin(); sectIt != data.cend(); ++sectIt) {
arrays[arrayId].val[i].set(sectIt->first.c_str(), sectIt->first.size());
@@ -198,7 +199,7 @@ static void CopyConfigSectionToArray(DWORD arrayId, const Config::Section& secti
void mf_get_ini_section(OpcodeContext& ctx) {
auto sectionName = ctx.arg(1).strValue();
int arrayId = CreateTempArray(-1, 0); // associative
DWORD arrayId = CreateTempArray(-1, 0); // associative
ctx.setReturn(arrayId);
Config* config = IniReader::instance().getIniConfig(GetIniFilePathFromArg(ctx.arg(0)).c_str());
@@ -218,7 +219,7 @@ void mf_get_ini_config(OpcodeContext& ctx) {
: GetIniFilePathFromArg(ctx.arg(0)));
if (filePath.size() == 0) {
ctx.printOpcodeError("Invalid INI path: %s", ctx.arg(0).strValue());
ctx.printOpcodeError("%s() - invalid config file path: %s", ctx.getMetaruleName(), ctx.arg(0).strValue());
ctx.setReturn(0);
return;
}
@@ -242,17 +243,16 @@ void mf_get_ini_config(OpcodeContext& ctx) {
if (isDb) {
configUniq = std::make_unique<Config>();
if (!configUniq->read(filePath.c_str(), isDb)) {
ctx.printOpcodeError("Could not read config file from DAT: %s", filePath.c_str());
ctx.printOpcodeError("%s() - cannot read config file from DAT: %s", ctx.getMetaruleName(), filePath.c_str());
ctx.setReturn(0);
return;
}
config = configUniq.get();
}
else {
} else {
// Request config from IniReader (to take advantage of it's cache).
config = IniReader::instance().getIniConfig(filePath.c_str());
if (config == nullptr) {
ctx.printOpcodeError("Could not read config file: %s", filePath.c_str());
ctx.printOpcodeError("%s() - cannot read config file: %s", ctx.getMetaruleName(), filePath.c_str());
ctx.setReturn(0);
return;
}
@@ -266,7 +266,7 @@ void mf_get_ini_config(OpcodeContext& ctx) {
SetArray(arrayId, sectIt->first.c_str(), subArrayId, false);
}
// Save new array ID to cache and return it.
cache.emplace(filePath, arrayId);
cache.emplace(std::move(filePath), arrayId);
ctx.setReturn(arrayId);
}
+4 -3
View File
@@ -55,10 +55,11 @@ struct ci_less
}
};
bool operator() (const std::string &s1, const std::string &s2) const {
return std::lexicographical_compare
(s1.begin (), s1.end (), // source range
return std::lexicographical_compare(
s1.begin (), s1.end (), // source range
s2.begin (), s2.end (), // dest range
nocase_compare ()); // comparison
nocase_compare () // comparison
);
}
};
+8 -4
View File
@@ -452,9 +452,11 @@
<ClInclude Include="HLSL\L8PixelShader.h">
<Filter>HLSL</Filter>
</ClInclude>
<ClInclude Include="Config.h" />
<ClInclude Include="Modules\Scripting\Handlers\IniFiles.h" />
<ClInclude Include="ConsoleWindow.h" />
<ClInclude Include="Config.h" />
<ClInclude Include="Modules\Scripting\Handlers\IniFiles.h">
<Filter>Modules\Scripting\Handlers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
@@ -827,9 +829,11 @@
<ClCompile Include="Modules\SubModules\DirectDraw.cpp">
<Filter>Modules\SubModules</Filter>
</ClCompile>
<ClCompile Include="Config.cpp" />
<ClCompile Include="Modules\Scripting\Handlers\IniFiles.cpp" />
<ClCompile Include="ConsoleWindow.cpp" />
<ClCompile Include="Config.cpp" />
<ClCompile Include="Modules\Scripting\Handlers\IniFiles.cpp">
<Filter>Modules\Scripting\Handlers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc" />