From c0bb8be37ab44889fb569f3430be47255e2f9c9a Mon Sep 17 00:00:00 2001 From: Todd Jeffreys Date: Mon, 7 Oct 2024 10:58:25 -0600 Subject: [PATCH] Fix some linux issues --- assets/BUILD | 5 +++++ btrieve/BtrieveDatabase.cc | 26 ++++++-------------------- btrieve/BtrieveDatabase_test.cc | 2 +- btrieve/SqliteDatabase.cc | 4 ++++ 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/assets/BUILD b/assets/BUILD index 6c3c005..97bec46 100644 --- a/assets/BUILD +++ b/assets/BUILD @@ -3,8 +3,13 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "test_dats", srcs = [ + "GALTELA.DAT", "MBBSEMU.DAT", "MBBSEMU.DB", + "MBBSEMU.DB.V2", + "MULTIACS.DAT", "VARIABLE.DAT", + "WCCACMS2.DAT", + "WGSMENU2.DAT", ], ) diff --git a/btrieve/BtrieveDatabase.cc b/btrieve/BtrieveDatabase.cc index eb07af3..835814f 100644 --- a/btrieve/BtrieveDatabase.cc +++ b/btrieve/BtrieveDatabase.cc @@ -66,19 +66,6 @@ static inline uint32_t getPageFromVariableLengthRecordPointer( static_cast(data[2]) << 8; } -static uint16_t getPageOffsetFromFragmentArray( - std::basic_string_view arrayEntry, bool& nextPointerExists) { - if (arrayEntry[0] == 0xFF && arrayEntry[1] == 0xFF) { - nextPointerExists = false; - return 0xFFFF; - } - - uint16_t offset = static_cast(arrayEntry[0]) | - (static_cast(arrayEntry[1]) & 0x7F) << 8; - nextPointerExists = (arrayEntry[1] & 0x80) != 0; - return offset; -} - static void append(std::vector& vector, std::basic_string_view data) { size_t vectorSize = vector.size(); @@ -110,7 +97,7 @@ BtrieveDatabase::FCRDATA BtrieveDatabase::validateDatabase( // find the valid FCR in v6 if (v6) { - uint8_t* wholePage = reinterpret_cast(_alloca(pageLength)); + uint8_t* wholePage = reinterpret_cast(alloca(pageLength)); fseek_s(f, pageLength, SEEK_SET); fread_s(wholePage, pageLength, f); @@ -220,7 +207,7 @@ bool BtrieveDatabase::isUnusedRecord(std::basic_string_view data) { return true; } // first two bytes are usage count, which will be non-zero if used - uint16_t usageCount = data[0] << 8 || data[1]; + uint16_t usageCount = data[0] << 8 | data[1]; return usageCount == 0; } else if (data.size() >= 4 && data.substr(4).find_first_not_of(static_cast(0)) == @@ -347,7 +334,7 @@ BtrieveError BtrieveDatabase::parseDatabase( bool BtrieveDatabase::loadPAT(FILE* f, std::string& acsName, std::vector& acs) { - uint8_t* pat1 = reinterpret_cast(_alloca(pageLength * 2)); + uint8_t* pat1 = reinterpret_cast(alloca(pageLength * 2)); uint8_t* pat2 = pat1 + pageLength; // pat2 is sequentially after pat1 fseek_s(f, pageLength * 2, SEEK_SET); // starts on third page @@ -367,7 +354,6 @@ bool BtrieveDatabase::loadPAT(FILE* f, std::string& acsName, uint16_t usageCount2 = toUint16(pat2 + 4); // scan page type code to find ACS/Index/etc pages uint8_t* activePat = (usageCount1 > usageCount2) ? pat1 : pat2; - uint16_t sequenceNumber = activePat[2] << 8 | activePat[3]; // enumerate all pages for (int i = 8; i < pageLength; i += 4) { @@ -409,7 +395,7 @@ bool BtrieveDatabase::loadACSAtPhysicalOffset(FILE* f, std::string& acsName, uint32_t physicalOffset) { static const uint8_t ACS_PAGE_HEADER[] = {0, 0, 1, 0, 0, 0, 0xAC}; - char* acsPage = reinterpret_cast(_alloca(pageLength)); + char* acsPage = reinterpret_cast(alloca(pageLength)); fseek_s(f, physicalOffset, SEEK_SET); fread_s(acsPage, pageLength, f); @@ -572,7 +558,7 @@ static inline int32_t getVRecordPage(VRECPTR* x) { void BtrieveDatabase::getVariableLengthData( FILE* f, std::basic_string_view recordData, std::vector& stream) { - uint8_t* const data = reinterpret_cast(_alloca(pageLength)); + uint8_t* const data = reinterpret_cast(alloca(pageLength)); const unsigned int filePosition = ftell(f); VRECPTR Vrec = *reinterpret_cast(recordData.data() + recordLength); @@ -649,7 +635,7 @@ int32_t BtrieveDatabase::logicalPageToPhysicalOffset(FILE* f, ret += (pageLength / 4u); } - uint8_t* pat1 = reinterpret_cast(_alloca(pageLength * 2)); + uint8_t* pat1 = reinterpret_cast(alloca(pageLength * 2)); uint8_t* pat2 = pat1 + pageLength; const uint32_t physicalOffset = ret * pageLength; diff --git a/btrieve/BtrieveDatabase_test.cc b/btrieve/BtrieveDatabase_test.cc index 2f35b16..21df73c 100644 --- a/btrieve/BtrieveDatabase_test.cc +++ b/btrieve/BtrieveDatabase_test.cc @@ -136,7 +136,7 @@ TEST(BtrieveDatabase, LoadsVariableDatV6) { BtrieveDatabase database; std::unordered_map expectedData; - for (int i = 0; i < sizeof(variableData) / sizeof(variableData[0]); ++i) { + for (size_t i = 0; i < sizeof(variableData) / sizeof(variableData[0]); ++i) { expectedData[variableData[i].key] = variableData[i].recordLength; } diff --git a/btrieve/SqliteDatabase.cc b/btrieve/SqliteDatabase.cc index e761261..a8d3d1c 100644 --- a/btrieve/SqliteDatabase.cc +++ b/btrieve/SqliteDatabase.cc @@ -11,6 +11,10 @@ #include "SqliteUtil.h" #include "sqlite/sqlite3.h" +#ifndef WIN32 +#include +#endif + namespace btrieve { static const unsigned int CURRENT_VERSION = 3;