00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __MOFILEREADER_H_INCLUDED__
00034 #define __MOFILEREADER_H_INCLUDED__
00035
00036 #include <deque>
00037 #include <map>
00038 #include <fstream>
00039 #include <cstring>
00040 #include <string>
00041 #include <sstream>
00042
00043 #ifndef __MOFILECONFIG_H_INCLUDED__
00044 # include "moFileConfig.h"
00045 #endif
00046
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 #if defined(_MSC_VER) && ( defined(_EXPORT) || defined(MOFILE_IMPORT) )
00179 # pragma warning (disable:4251)
00180 #endif
00181
00182
00186 MO_BEGIN_NAMESPACE
00187
00188 const std::string g_css = \
00189 "\
00190 body {\
00191 background-color: black;\
00192 color: silver;\
00193 }\
00194 table {\
00195 width: 80%;}\
00196 th {\
00197 background-color: orange;\
00198 color: black;\
00199 }\
00200 hr { color: red;width: 80%; size: 5px; }\
00201 a:link{color: gold;}\
00202 a:visited{color: grey;}\
00203 a:hover{color:blue;}\
00204 .copyleft{\
00205 font-size: 12px; \
00206 text-align: center;\
00207 }\
00208 ";
00209
00217 struct moTranslationPairInformation
00218 {
00220 moTranslationPairInformation()
00221 : m_orLength(0), m_orOffset(0),
00222 m_trLength(0), m_trOffset(0)
00223 {}
00224
00226 int m_orLength;
00227
00229 int m_orOffset;
00230
00232 int m_trLength;
00233
00235 int m_trOffset;
00236 };
00237
00248 struct moFileInfo
00249 {
00251 typedef std::deque<moTranslationPairInformation> moTranslationPairList;
00252
00254 moFileInfo()
00255 : m_magicNumber(0), m_fileVersion(0), m_numStrings(0),
00256 m_offsetOriginal(0), m_offsetTranslation(0), m_sizeHashtable(0),
00257 m_offsetHashtable(0), m_reversed(false)
00258 {}
00259
00261 int m_magicNumber;
00262
00264 int m_fileVersion;
00265
00267 int m_numStrings;
00268
00270 int m_offsetOriginal;
00271
00273 int m_offsetTranslation;
00274
00276 int m_sizeHashtable;
00277
00279 int m_offsetHashtable;
00280
00284 bool m_reversed;
00285
00287 moTranslationPairList m_translationPairInformation;
00288 };
00289
00310 class MOEXPORT moFileReader
00311 {
00312 protected:
00314 typedef std::map<std::string, std::string> moLookupList;
00315
00316 public:
00317
00319 static const long _MagicNumber = 0x950412DE;
00320
00322 static const long _MagicReversed = 0xDE120495;
00323
00325 enum eErrorCode
00326 {
00328 EC_SUCCESS = 0,
00329
00331 EC_ERROR,
00332
00334 EC_FILENOTFOUND,
00335
00337 EC_FILEINVALID,
00338
00340 EC_TABLEEMPTY,
00341
00343 EC_MAGICNUMBER_NOMATCH,
00344
00349 EC_MAGICNUMBER_REVERSED,
00350 };
00351
00360 virtual eErrorCode ReadFile(const char* _filename);
00361
00366 virtual std::string Lookup( const char* _id ) const;
00367
00369 virtual const std::string& GetErrorDescription() const;
00370
00372 virtual void ClearTable();
00373
00378 virtual unsigned int GetNumStrings() const;
00379
00387 static eErrorCode ExportAsHTML(const std::string _infile, const std::string _filename = "", const std::string _css = g_css );
00388
00389 protected:
00391 std::string m_error;
00392
00397 unsigned long SwapBytes(unsigned long _in);
00398
00399 private:
00400
00401 moLookupList m_lookup;
00402
00403 void MakeHtmlConform(std::string& _inout);
00404 bool GetPoEditorString(const char* _buffer, std::string& _name, std::string& _value);
00405 void Trim(std::string& _in);
00406 };
00407
00421 class MOEXPORT moFileReaderSingleton : public moFileReader
00422 {
00423 private:
00424
00425
00426 moFileReaderSingleton();
00427 moFileReaderSingleton(const moFileReaderSingleton&);
00428 moFileReaderSingleton& operator=(const moFileReaderSingleton&);
00429
00430 public:
00434 static moFileReaderSingleton& GetInstance();
00435 };
00436
00441 inline moFileReader::eErrorCode moReadMoFile(const char* _filename)
00442 {
00443 moFileReader::eErrorCode r = moFileReaderSingleton::GetInstance().ReadFile(_filename);
00444 return r;
00445 }
00446
00451 inline std::string _(const char* id)
00452 {
00453 std::string r = moFileReaderSingleton::GetInstance().Lookup(id);
00454 return r;
00455 }
00456
00458 inline void moFileClearTable()
00459 {
00460 moFileReaderSingleton::GetInstance().ClearTable();
00461 }
00462
00464 inline std::string moFileGetErrorDescription()
00465 {
00466 std::string r = moFileReaderSingleton::GetInstance().GetErrorDescription();
00467 return r;
00468 }
00469
00471 inline int moFileGetNumStrings()
00472 {
00473 int r = moFileReaderSingleton::GetInstance().GetNumStrings();
00474 return r;
00475 }
00476
00477 #if defined(_MSC_VER)
00478 # pragma warning (default:4251)
00479 #endif
00480
00481 MO_END_NAMESPACE
00482
00483 #endif