Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite of CInifile #1543

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Layers/xrRender/ModelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void CModelPool::Prefetch()
for (auto I = sect.Data.cbegin(); I != sect.Data.cend(); ++I)
{
const CInifile::Item& item = *I;
dxRender_Visual* V = Create(item.first.c_str());
dxRender_Visual* V = Create(item.name.c_str());
Delete(V, FALSE);
}
Logging(TRUE);
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool is_enough_address_space_available() { return true; }

int get_texture_load_lod(LPCSTR fn)
{
CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list");
const CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list");
auto it_ = sect.Data.cbegin();
auto it_e_ = sect.Data.cend();

Expand All @@ -38,7 +38,7 @@ int get_texture_load_lod(LPCSTR fn)

for (; it != it_e; ++it)
{
if (strstr(fn, it->first.c_str()))
if (strstr(fn, it->name.c_str()))
{
if (psTextureLOD < 1)
{
Expand Down
24 changes: 12 additions & 12 deletions src/Layers/xrRender/TextureDescrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ void CTextureDescrMngr::LoadLTX(pcstr initial, bool listTHM)
const auto processAssociation = [&](const CInifile::Item& item)
{
if (listTHM)
Msg("\t\t%s = %s", item.first.c_str(), item.second.c_str());
Msg("\t\t%s = %s", item.name.c_str(), item.value.c_str());

lock.Enter();
texture_desc& desc = m_texture_details[item.first];
cl_dt_scaler*& dts = m_detail_scalers[item.first];
texture_desc& desc = m_texture_details[item.name];
cl_dt_scaler*& dts = m_detail_scalers[item.name];
lock.Leave();

if (desc.m_assoc)
Expand All @@ -68,19 +68,19 @@ void CTextureDescrMngr::LoadLTX(pcstr initial, bool listTHM)
string_path T;
float s;

const int res = sscanf(*item.second, "%[^,],%f", T, &s);
R_ASSERT4(res == 2, "Bad texture association", item.first.c_str(), fname);
const int res = sscanf(*item.value, "%[^,],%f", T, &s);
R_ASSERT4(res == 2, "Bad texture association", item.name.c_str(), fname);
desc.m_assoc->detail_name = T;
if (dts)
dts->scale = s;
else
dts = xr_new<cl_dt_scaler>(s);

if (strstr(item.second.c_str(), "usage[diffuse_or_bump]"))
if (strstr(item.value.c_str(), "usage[diffuse_or_bump]"))
desc.m_assoc->usage.set(texture_assoc::flDiffuseDetail | texture_assoc::flBumpDetail);
else if (strstr(item.second.c_str(), "usage[bump]"))
else if (strstr(item.value.c_str(), "usage[bump]"))
desc.m_assoc->usage.set(texture_assoc::flBumpDetail);
else if (strstr(item.second.c_str(), "usage[diffuse]"))
else if (strstr(item.value.c_str(), "usage[diffuse]"))
desc.m_assoc->usage.set(texture_assoc::flDiffuseDetail);
};
xr_parallel_for_each(data.Data, processAssociation);
Expand All @@ -97,10 +97,10 @@ void CTextureDescrMngr::LoadLTX(pcstr initial, bool listTHM)
const auto processSpecification = [&](const CInifile::Item& item)
{
if (listTHM)
Msg("\t\t%s = %s", item.first.c_str(), item.second.c_str());
Msg("\t\t%s = %s", item.name.c_str(), item.value.c_str());

lock.Enter();
texture_desc& desc = m_texture_details[item.first];
texture_desc& desc = m_texture_details[item.name];
lock.Leave();

if (desc.m_spec)
Expand All @@ -110,8 +110,8 @@ void CTextureDescrMngr::LoadLTX(pcstr initial, bool listTHM)

string_path bmode;
const int res =
sscanf(item.second.c_str(), "bump_mode[%[^]]], material[%f]", bmode, &desc.m_spec->m_material);
R_ASSERT4(res == 2, "Bad texture specification", item.first.c_str(), fname);
sscanf(item.value.c_str(), "bump_mode[%[^]]], material[%f]", bmode, &desc.m_spec->m_material);
R_ASSERT4(res == 2, "Bad texture specification", item.name.c_str(), fname);
if ((bmode[0] == 'u') && (bmode[1] == 's') && (bmode[2] == 'e') && (bmode[3] == ':'))
{
// bump-map specified
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderDX11/dx11Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void fix_texture_name(pstr fn)

int get_texture_load_lod(LPCSTR fn)
{
CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list");
const CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list");
auto it_ = sect.Data.cbegin();
auto it_e_ = sect.Data.cend();

Expand All @@ -29,7 +29,7 @@ int get_texture_load_lod(LPCSTR fn)

for (; it != it_e; ++it)
{
if (strstr(fn, it->first.c_str()))
if (strstr(fn, it->name.c_str()))
{
if (psTextureLOD < 1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderGL/glTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ void fix_texture_name(pstr fn)

int get_texture_load_lod(LPCSTR fn)
{
CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list");
const CInifile::Sect& sect = pSettings->r_section("reduce_lod_texture_list");

for (const auto& item : sect.Data)
{
if (strstr(fn, item.first.c_str()))
if (strstr(fn, item.name.c_str()))
{
if (psTextureLOD < 1)
return 0;
Expand Down
16 changes: 8 additions & 8 deletions src/utils/mp_configs_verifyer/configs_dump_verifyer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ LPCSTR configs_verifyer::get_section_diff(CInifile::Sect* sect_ptr, CInifile& ac

for (auto cit = sect_ptr->Data.cbegin(), ciet = sect_ptr->Data.cend(); cit != ciet; ++cit)
{
shared_str const& tmp_value = cit->second;
shared_str const& tmp_value = cit->value;
shared_str real_value;
if (tmp_active_param)
{
if (active_params.line_exist(sect_ptr->Name.c_str(), cit->first))
if (active_params.line_exist(sect_ptr->Name.c_str(), cit->name))
{
real_value = active_params.r_string(sect_ptr->Name.c_str(), cit->first.c_str());
real_value = active_params.r_string(sect_ptr->Name.c_str(), cit->name.c_str());
if (tmp_value != real_value)
{
pcstr tmp_key_str = nullptr;
STRCONCAT(tmp_key_str, sect_ptr->Name.c_str(), "::", cit->first.c_str());
STRCONCAT(tmp_key_str, sect_ptr->Name.c_str(), "::", cit->name.c_str());
STRCONCAT(diff_str, tmp_key_str, " = ", tmp_value.c_str(), ",right = ", real_value.c_str());
strncpy_s(dst_diff, diff_str, sizeof(dst_diff) - 1);
dst_diff[sizeof(dst_diff) - 1] = 0;
Expand All @@ -112,18 +112,18 @@ LPCSTR configs_verifyer::get_section_diff(CInifile::Sect* sect_ptr, CInifile& ac
continue;
}
}
if (!pSettings->line_exist(sect_ptr->Name, cit->first))
if (!pSettings->line_exist(sect_ptr->Name, cit->name))
{
STRCONCAT(diff_str, "line ", sect_ptr->Name.c_str(), "::", cit->first.c_str(), " not found");
STRCONCAT(diff_str, "line ", sect_ptr->Name.c_str(), "::", cit->name.c_str(), " not found");
strncpy_s(dst_diff, diff_str, sizeof(dst_diff) - 1);
dst_diff[sizeof(dst_diff) - 1] = 0;
return dst_diff;
}
real_value = pSettings->r_string(sect_ptr->Name.c_str(), cit->first.c_str());
real_value = pSettings->r_string(sect_ptr->Name.c_str(), cit->name.c_str());
if (tmp_value != real_value)
{
pcstr tmp_key_str = nullptr;
STRCONCAT(tmp_key_str, sect_ptr->Name.c_str(), "::", cit->first.c_str());
STRCONCAT(tmp_key_str, sect_ptr->Name.c_str(), "::", cit->name.c_str());
STRCONCAT(diff_str, tmp_key_str, " = ", tmp_value.c_str(), ",right = ", real_value.c_str());
strncpy_s(dst_diff, diff_str, sizeof(dst_diff) - 1);
dst_diff[sizeof(dst_diff) - 1] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/mp_configs_verifyer/mp_config_sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ bool mp_config_sections::dump_one(CMemoryWriter& dest)
return false;

R_ASSERT(pSettings->section_exist(m_current_dump_sect->c_str()));
CInifile::Sect& tmp_sect = pSettings->r_section(m_current_dump_sect->c_str());
const CInifile::Sect& tmp_sect = pSettings->r_section(m_current_dump_sect->c_str());

m_tmp_dumper.sections().push_back(&tmp_sect);
m_tmp_dumper.sections().push_back(const_cast<CInifile::Sect*>(&tmp_sect));
m_tmp_dumper.save_as(dest);
m_tmp_dumper.sections().pop_back();
++m_current_dump_sect;
Expand Down
14 changes: 7 additions & 7 deletions src/utils/xrCompress/xrCompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void xrCompressor::OpenPack(LPCSTR tgt_folder, int num)
W.w_string(buff);
for (const auto& it : S.Data)
{
xr_sprintf(buff, "%s = %s", it.first.c_str(), it.second.c_str());
xr_sprintf(buff, "%s = %s", it.name.c_str(), it.value.c_str());
W.w_string(buff);
}
W.seek(0);
Expand Down Expand Up @@ -470,15 +470,15 @@ bool xrCompressor::IsFolderAccepted(const CInifile& ltx, LPCSTR path, bool& recu
const auto& ef_sect = ltx.r_section("exclude_folders");
for (const auto& it : ef_sect.Data)
{
recurse = CInifile::isBool(it.second.c_str());
recurse = CInifile::isBool(it.value.c_str());
if (recurse)
{
if (path == strstr(path, it.first.c_str()))
if (path == strstr(path, it.name.c_str()))
return false;
}
else
{
if (0 == xr_strcmp(path, it.first.c_str()))
if (0 == xr_strcmp(path, it.name.c_str()))
return false;
}
}
Expand All @@ -501,11 +501,11 @@ void xrCompressor::ProcessLTX(CInifile& ltx)
const CInifile::Sect& if_sect = ltx.r_section("include_folders");
for (const auto& it : if_sect.Data)
{
const BOOL ifRecurse = CInifile::isBool(it.second.c_str());
const BOOL ifRecurse = CInifile::isBool(it.value.c_str());
const u32 folder_mask = FS_ListFolders | (ifRecurse ? 0 : FS_RootOnly);

string_path path;
const LPCSTR _path = 0 == xr_strcmp(it.first.c_str(), ".\\") ? "" : it.first.c_str();
const LPCSTR _path = 0 == xr_strcmp(it.name.c_str(), ".\\") ? "" : it.name.c_str();
xr_strcpy(path, _path);
const size_t path_len = xr_strlen(path);
if ((0 != path_len) && (path[path_len - 1] != '\\'))
Expand Down Expand Up @@ -556,7 +556,7 @@ void xrCompressor::ProcessLTX(CInifile& ltx)
{
const CInifile::Sect& if_sect = ltx.r_section("include_files");
for (const auto& it : if_sect.Data)
files_list->push_back(xr_strdup(it.first.c_str()));
files_list->push_back(xr_strdup(it.name.c_str()));
}

PerformWork();
Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/Animation/SkeletonMotions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ void CPartition::load(IKinematics* V, LPCSTR model_name)
for (; it != it_e; ++it)
{
const CInifile::Item& I = *it;
if (I.first == part_name)
if (I.name == part_name)
{
P[i].Name = I.second;
P[i].Name = I.value;
}
else
{
u32 bid = V->LL_BoneID(I.first.c_str());
u32 bid = V->LL_BoneID(I.name.c_str());
P[i].bones.push_back(bid);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/xrCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ target_sources_grouped(
os_clipboard.h
)

target_sources_grouped(
TARGET xrCore
NAME "Parsing"
FILES
ParsingUtils.cpp
ParsingUtils.hpp
)

target_sources_grouped(
TARGET xrCore
NAME "PCH"
Expand Down
95 changes: 95 additions & 0 deletions src/xrCore/ParsingUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "stdafx.h"

#include "ParsingUtils.hpp"

ParseIncludeResult ParseInclude(pstr string, pcstr& out_include_name)
{
VERIFY(string);

// Skip any whitespace characters
string = ParseAllSpaces(string);

// Check for #include
static constexpr pcstr IncludeTag = "#include";
if (std::strncmp(string, IncludeTag, 8) != 0)
return ParseIncludeResult::NoInclude;

string += 8;

// Skip any whitespace characters
string = ParseAllSpaces(string);

// Check that after the tag there is a quote
if (*string != '\"')
return ParseIncludeResult::Error;

// Mark the start of the include name
++string;
out_include_name = string;

string = ParseUntil(string, '\"');

// Check for unterminated or empty include name
if (*string == '\0' || out_include_name == string)
return ParseIncludeResult::Error;

// Check for unreasonably long include names
const size_t size = string - out_include_name;
if (size > 1024)
return ParseIncludeResult::Error;

// NOTE(Andre): Yes this might look scary but it's perfectly fine. Since the include name is already in the string
// we are parsing and its not used afterwards we simply replace the closing quote with a null byte and we have a
// valid c-string pointed to by 'out_include_name' and safe ourselves the need to copy the string.
*string = '\0';

return ParseIncludeResult::Success;
}

pcstr ParseAllSpaces(pcstr string)
{
VERIFY(string);

while (*string != '\0' && std::isspace(*string))
++string;

return string;
}

pstr ParseAllSpaces(pstr string) { return const_cast<pstr>(ParseAllSpaces(reinterpret_cast<pcstr>(string))); }

pcstr ParseUntil(pcstr string, const char character)
{
VERIFY(string);

while (*string != '\0' && *string != character)
++string;

return string;
}

pstr ParseUntil(pstr string, const char character)
{
return const_cast<pstr>(ParseUntil(reinterpret_cast<pcstr>(string), character));
}

void StringCopyLowercase(pstr destination, pcstr src, std::size_t size)
{
VERIFY(destination);
VERIFY(src);

for (std::size_t i = 0; *src != '\0' && i < size; ++i)
{
*destination = std::tolower(*src);
++src;
++destination;
}

// Ensure the string is null-terminated
*destination = '\0';
}

void StringCopyLowercase(pstr destination, shared_str src, std::size_t size)
{
StringCopyLowercase(destination, *src, size);
}
33 changes: 33 additions & 0 deletions src/xrCore/ParsingUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "xr_types.h"
#include "xrstring.h"

enum class ParseIncludeResult
{
Success, /// There is a valid #include and 'out_include_name' contains the filename
Error, /// There is a #include but there is some problem
NoInclude, /// There is no #include on this line
};

// Given a string of the form: '#include "filename"' we try to parse filename into 'out_include_name'
// Note that the file name is parsed inplace to avoid copying the string
ParseIncludeResult ParseInclude(pstr string, pcstr& out_include_name);

// Starting from the beginning of the string skips all characters for which 'std::isspace' is 'true'.
// Returns the first position where 'std::isspace' is 'false'.
pcstr ParseAllSpaces(pcstr string);

pstr ParseAllSpaces(pstr string);

// Starting from the begging of the string skips all characters until 'character' is found
// or until the end of the string is reached.
// Returns the first position where 'character' is found or the end of string if 'character' is not found
pcstr ParseUntil(pcstr string, const char character);

pstr ParseUntil(pstr string, const char character);

// Copies 'size' characters from 'src' to 'destination' and converts it to lowercase
void StringCopyLowercase(pstr destination, pcstr src, std::size_t size);

void StringCopyLowercase(pstr destination, shared_str src, std::size_t size);
Loading
Loading