diff --git a/.gitignore b/.gitignore index 9d79c41..82117d7 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,6 @@ test/* *.o *.save *.dbf -*.so \ No newline at end of file +*.so +build +.vscode \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a204c59 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.28) +project(dbf) +set(CMAKE_CXX_STANDARD 17) + +set(CMAKE_CXX_FLAGS -O3) + +include_directories(include) + +add_library(dbf SHARED src/DBaseColDef.cpp + src/DBaseField.cpp + src/DBaseFieldProperty.cpp + src/DBaseFile.cpp + src/DBaseHeader.cpp + src/DBaseRecord.cpp +) \ No newline at end of file diff --git a/include/DBaseFile.h b/include/DBaseFile.h index 9b2cfec..8f67123 100644 --- a/include/DBaseFile.h +++ b/include/DBaseFile.h @@ -50,6 +50,8 @@ struct DBaseFile unsigned int m_totalHeaderLength = 0; /**< Header contents (read raw from disk)*/ std::string m_headerData = ""; + /** */ + unsigned int m_dbcSize = 0; }; /**< \section Exceptions */ diff --git a/src/DBaseFile.cpp b/src/DBaseFile.cpp index 0588377..1398209 100644 --- a/src/DBaseFile.cpp +++ b/src/DBaseFile.cpp @@ -18,6 +18,8 @@ using namespace std; +constexpr unsigned int DBC_SIZE = 263; + /** \brief Constructs dBase structure from given file. * \param Name of the dBase file * \return True if succeded. Otherwise throws exception @@ -39,8 +41,13 @@ bool DBaseFile::openFile(const std::string fileName) { //Read file contents into heap memory readHeader(iFile); + // compatable with viso + if (m_header.m_fileType.find("Visual FoxPro") != std::string::npos) { + m_dbcSize = DBC_SIZE; + } + //Check header - m_colDefLength = m_header.m_numBytesInHeader - m_totalHeaderLength -1; + m_colDefLength = m_header.m_numBytesInHeader - m_fileHeaderLength - m_dbcSize -1; validateBlockSize(m_colDefBlockSize, m_colDefLength); if(!(m_headerData.empty())) { m_header.parse(m_headerData);} validateBlockSize(m_colDefBlockSize, m_colDefLength); @@ -65,7 +72,7 @@ void DBaseFile::readHeader(std::ifstream& iFile) { ///Read column definition void DBaseFile::readColDef(std::ifstream& iFile, DBaseHeader& iFileHeader) { //omit terminating byte at header end - unsigned int headerLengthWOTerminatingChar = iFileHeader.m_numBytesInHeader - 1; + unsigned int headerLengthWOTerminatingChar = iFileHeader.m_numBytesInHeader - 1 - (m_dbcSize + 1); iFile.seekg((m_fileHeaderLength), iFile.beg); std::string colDefBuf((headerLengthWOTerminatingChar - m_fileHeaderLength), ' '); iFile.read(&(colDefBuf.at(0)), (headerLengthWOTerminatingChar - m_fileHeaderLength));