A little refactoring

This commit is contained in:
Rangi42
2025-07-18 14:17:23 -04:00
parent e7d63f5f6b
commit 4a2f9fc744

View File

@@ -92,12 +92,13 @@ static void readFileStackNode(
FILE *file, std::vector<FileStackNode> &fileNodes, uint32_t nodeID, char const *fileName FILE *file, std::vector<FileStackNode> &fileNodes, uint32_t nodeID, char const *fileName
) { ) {
FileStackNode &node = fileNodes[nodeID]; FileStackNode &node = fileNodes[nodeID];
uint32_t parentID;
uint32_t parentID;
tryReadLong( tryReadLong(
parentID, file, "%s: Cannot read node #%" PRIu32 "'s parent ID: %s", fileName, nodeID parentID, file, "%s: Cannot read node #%" PRIu32 "'s parent ID: %s", fileName, nodeID
); );
node.parent = parentID != UINT32_MAX ? &fileNodes[parentID] : nullptr; node.parent = parentID != UINT32_MAX ? &fileNodes[parentID] : nullptr;
tryReadLong( tryReadLong(
node.lineNo, file, "%s: Cannot read node #%" PRIu32 "'s line number: %s", fileName, nodeID node.lineNo, file, "%s: Cannot read node #%" PRIu32 "'s line number: %s", fileName, nodeID
); );
@@ -206,9 +207,7 @@ static void readPatch(
uint32_t patchID, uint32_t patchID,
std::vector<FileStackNode> const &fileNodes std::vector<FileStackNode> const &fileNodes
) { ) {
uint32_t nodeID, rpnSize; uint32_t nodeID;
PatchType type;
tryReadLong( tryReadLong(
nodeID, nodeID,
file, file,
@@ -218,6 +217,7 @@ static void readPatch(
patchID patchID
); );
patch.src = &fileNodes[nodeID]; patch.src = &fileNodes[nodeID];
tryReadLong( tryReadLong(
patch.lineNo, patch.lineNo,
file, file,
@@ -250,6 +250,8 @@ static void readPatch(
sectName.c_str(), sectName.c_str(),
patchID patchID
); );
PatchType type;
tryGetc( tryGetc(
PatchType, PatchType,
type, type,
@@ -260,6 +262,8 @@ static void readPatch(
patchID patchID
); );
patch.type = type; patch.type = type;
uint32_t rpnSize;
tryReadLong( tryReadLong(
rpnSize, rpnSize,
file, file,
@@ -270,9 +274,7 @@ static void readPatch(
); );
patch.rpnExpression.resize(rpnSize); patch.rpnExpression.resize(rpnSize);
size_t nbElementsRead = fread(patch.rpnExpression.data(), 1, rpnSize, file); if (fread(patch.rpnExpression.data(), 1, rpnSize, file) != rpnSize) {
if (nbElementsRead != rpnSize) {
fatal( fatal(
"%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s", "%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
fileName, fileName,
@@ -366,8 +368,7 @@ static void readSection(
if (sect_HasData(section.type)) { if (sect_HasData(section.type)) {
if (section.size) { if (section.size) {
section.data.resize(section.size); section.data.resize(section.size);
if (size_t nbRead = fread(section.data.data(), 1, section.size, file); if (fread(section.data.data(), 1, section.size, file) != section.size) {
nbRead != section.size) {
fatal( fatal(
"%s: Cannot read \"%s\"'s data: %s", "%s: Cannot read \"%s\"'s data: %s",
fileName, fileName,