diff --git a/Doxyfile.conf b/Doxyfile.conf index f0cc603..90a1546 100644 --- a/Doxyfile.conf +++ b/Doxyfile.conf @@ -13,7 +13,6 @@ OUTPUT_DIRECTORY = docs INPUT = include RECURSIVE = YES GENERATE_LATEX = NO -INLINE_SOURCES = YES GENERATE_TREEVIEW = YES UML_LOOK = YES MULTILINE_CPP_IS_BRIEF = YES diff --git a/include/moFileReader.hpp b/include/moFileReader.hpp index d59dbc0..c7e4f36 100644 --- a/include/moFileReader.hpp +++ b/include/moFileReader.hpp @@ -342,129 +342,10 @@ class moFileReader */ moFileReader::eErrorCode ParseData(const std::string &data) { - // Creating a file-description. - moFileInfo moInfo; - - // Reference to the List inside moInfo. - moFileInfo::moTranslationPairList &TransPairInfo = moInfo.m_translationPairInformation; - // Opening the file. std::stringstream stream(data); - // Read in all the 4 bytes of fire-magic, offsets and stuff... - stream.read((char *)&moInfo.m_magicNumber, 4); - stream.read((char *)&moInfo.m_fileVersion, 4); - stream.read((char *)&moInfo.m_numStrings, 4); - stream.read((char *)&moInfo.m_offsetOriginal, 4); - stream.read((char *)&moInfo.m_offsetTranslation, 4); - stream.read((char *)&moInfo.m_sizeHashtable, 4); - stream.read((char *)&moInfo.m_offsetHashtable, 4); - - if (stream.bad()) - { - m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; - printf("%s", m_error.c_str()); - return moFileReader::EC_FILEINVALID; - } - - // Checking the Magic Number - if (MagicNumber != moInfo.m_magicNumber) - { - if (MagicReversed != moInfo.m_magicNumber) - { - m_error = "The Magic Number does not match in all cases!"; - printf("%s", m_error.c_str()); - return moFileReader::EC_MAGICNUMBER_NOMATCH; - } - else - { - moInfo.m_reversed = true; - m_error = "Magic Number is reversed. We do not support this yet!"; - return moFileReader::EC_MAGICNUMBER_REVERSED; - } - } - - // Now we search all Length & Offsets of the original strings - for (int i = 0; i < moInfo.m_numStrings; i++) - { - moTranslationPairInformation _str; - stream.read((char *)&_str.m_orLength, 4); - stream.read((char *)&_str.m_orOffset, 4); - if (stream.bad()) - { - m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; - printf("%s", m_error.c_str()); - return moFileReader::EC_FILEINVALID; - } - - TransPairInfo.push_back(_str); - } - - // Get all Lengths & Offsets of the translated strings - // Be aware: The Descriptors already exist in our list, so we just mod. refs from the deque. - for (int i = 0; i < moInfo.m_numStrings; i++) - { - moTranslationPairInformation &_str = TransPairInfo[i]; - stream.read((char *)&_str.m_trLength, 4); - stream.read((char *)&_str.m_trOffset, 4); - if (stream.bad()) - { - m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; - printf("%s", m_error.c_str()); - return moFileReader::EC_FILEINVALID; - } - } - - // Normally you would read the hash-table here, but we don't use it. :) - - // Now to the interesting part, we read the strings-pairs now - for (int i = 0; i < moInfo.m_numStrings; i++) - { - // We need a length of +1 to catch the trailing \0. - int orLength = TransPairInfo[i].m_orLength + 1; - int trLength = TransPairInfo[i].m_trLength + 1; - - int orOffset = TransPairInfo[i].m_orOffset; - int trOffset = TransPairInfo[i].m_trOffset; - - // Original - char *original = new char[orLength]; - memset(original, 0, sizeof(char) * orLength); - - stream.seekg(orOffset); - stream.read(original, orLength); - - if (stream.bad()) - { - m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; - printf("%s", m_error.c_str()); - return moFileReader::EC_FILEINVALID; - } - - // Translation - char *translation = new char[trLength]; - memset(translation, 0, sizeof(char) * trLength); - - stream.seekg(trOffset); - stream.read(translation, trLength); - - if (stream.bad()) - { - m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; - printf("%s", m_error.c_str()); - return moFileReader::EC_FILEINVALID; - } - - // Store it in the map. - m_lookup[std::string(original)] = std::string(translation); - - // Cleanup... - delete[] original; - delete[] translation; - } - - // Done :) - return moFileReader::EC_SUCCESS; + return ReadStream(stream); } /** \brief Reads a .mo-file @@ -477,12 +358,6 @@ class moFileReader */ eErrorCode ReadFile(const char *filename) { - // Creating a file-description. - moFileInfo moInfo; - - // Reference to the List inside moInfo. - moFileInfo::moTranslationPairList &TransPairInfo = moInfo.m_translationPairInformation; - // Opening the file. std::ifstream stream(filename, std::ios_base::binary | std::ios_base::in); if (!stream.is_open()) @@ -491,6 +366,25 @@ class moFileReader return moFileReader::EC_FILENOTFOUND; } + eErrorCode res = ReadStream(stream); + stream.close(); + + return res; + } + + /** \brief Reads data from a stream + * \param[in] stream + * \return SUCCESS on success or one of the other error-codes in eErrorCode on error. + * + */ + template eErrorCode ReadStream(T &stream) + { + // Creating a file-description. + moFileInfo moInfo; + + // Reference to the List inside moInfo. + moFileInfo::moTranslationPairList &TransPairInfo = moInfo.m_translationPairInformation; + // Read in all the 4 bytes of fire-magic, offsets and stuff... stream.read((char *)&moInfo.m_magicNumber, 4); stream.read((char *)&moInfo.m_fileVersion, 4); @@ -502,7 +396,6 @@ class moFileReader if (stream.bad()) { - stream.close(); m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; return moFileReader::EC_FILEINVALID; } @@ -531,7 +424,6 @@ class moFileReader stream.read((char *)&_str.m_orOffset, 4); if (stream.bad()) { - stream.close(); m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; return moFileReader::EC_FILEINVALID; } @@ -548,7 +440,6 @@ class moFileReader stream.read((char *)&_str.m_trOffset, 4); if (stream.bad()) { - stream.close(); m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; return moFileReader::EC_FILEINVALID; } @@ -617,7 +508,6 @@ class moFileReader } // Done :) - stream.close(); return moFileReader::EC_SUCCESS; } @@ -681,7 +571,7 @@ class moFileReader static eErrorCode ExportAsHTML(const std::string &infile, const std::string &filename = "", const std::string &css = g_css) { // Read the file - moFileReader reader; + moFileReader reader; moFileReader::eErrorCode r = reader.ReadFile(infile.c_str()); if (r != moFileReader::EC_SUCCESS) { return r; } if (reader.m_lookup.empty()) { return moFileReader::EC_TABLEEMPTY; }