+ import from github
This commit is contained in:
		
							
								
								
									
										20
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| The MIT License (MIT) | ||||
|  | ||||
| Copyright (c) 2013 scorcher24 | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||||
| this software and associated documentation files (the "Software"), to deal in | ||||
| the Software without restriction, including without limitation the rights to | ||||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||||
| the Software, and to permit persons to whom the Software is furnished to do so, | ||||
| subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| mofilereader | ||||
| ============ | ||||
|  | ||||
| This API lets you read .mo-Files and use their content just as you would do with GNUs gettext. It is implemented in C++ with a very liberal license, allowing the programmer to use it in modern programs, without the need of linking against gettext and libiconv. | ||||
|  | ||||
| You will need cmake to build it as a seperate application or library, or just include the few files into your project. Any C++ Compiler should suffice.  | ||||
| This only fully supports utf-8, as I don't want this to be extensive.  | ||||
|  | ||||
| Optionally, you can also build an executable that is able to dump any .mo file to .html to peek into the contents of this file.  | ||||
|  | ||||
| Please report any issues you encounter, I can't fix them if I don't know about them! | ||||
|  | ||||
| If you find this useful, you can buy me a beer here: https://pledgie.com/campaigns/26908 | ||||
							
								
								
									
										54
									
								
								build/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								build/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| #------------------------------------------------------- | ||||
| # moFileReader Main Build Script | ||||
| # | ||||
| # Defined Variables: | ||||
| #   - COMPILE_DLL  | ||||
| #     - ON  : Compiles the code as a shared Library | ||||
| #     - OFF : Compiles the code as a static Library | ||||
| #   - BUILD_DEBUG | ||||
| #     - ON  : Compiles Debug-Information into the output | ||||
| #     - OFF : Optimizes the compilation with O2. | ||||
| # | ||||
| # Run cmake with -DVARNAME=ON/OFF to benefit from those | ||||
| # possible settings. | ||||
| #------------------------------------------------------- | ||||
| cmake_minimum_required(VERSION 2.6) | ||||
| project(moFileReader) | ||||
|  | ||||
| # Set Output Directories. | ||||
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../bin) | ||||
| set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../lib) | ||||
| set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ../lib) | ||||
|  | ||||
|  | ||||
| # The main include directory | ||||
| include_directories(BEFORE ../include) | ||||
|  | ||||
| # executable build directory | ||||
| add_subdirectory(bin) | ||||
|  | ||||
| # Let the user choose between static lib and dll | ||||
| # To use it, call cmake -DCOMPILE_DLL=ON | ||||
| option(COMPILE_DLL "Set this to ON if you want to compile the library as an DLL. When this is OFF, a static library is created (default)." OFF) | ||||
|  | ||||
| # Dependency | ||||
| link_directories(../lib) | ||||
|  | ||||
| if ( NOT COMPILE_DLL ) | ||||
|  | ||||
|     # Static build | ||||
|     add_library(moFileReader.static STATIC ../src/moFileReader.cpp ../src/mo.cpp) | ||||
|  | ||||
| else ( COMPILE_DLL ) | ||||
|  | ||||
|     # DLL | ||||
|     add_definitions(-D_USRDLL -DMOFILE_EXPORTS) | ||||
|     add_library(moFileReader SHARED ../src/moFileReader.cpp ../src/mo.cpp) | ||||
|  | ||||
| endif () | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
							
								
								
									
										22
									
								
								build/bin/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								build/bin/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../../bin) | ||||
| set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../../lib) | ||||
| set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ../../lib) | ||||
|  | ||||
| add_executable(moReader ../../src/mo.cpp) | ||||
|  | ||||
| if ( NOT COMPILE_DLL ) | ||||
|  | ||||
| add_definitions(-D_CONSOLE) | ||||
| add_dependencies(moReader moFileReader.static) | ||||
| target_link_libraries(moReader moFileReader.static) | ||||
|  | ||||
| else ( COMPILE_DLL ) | ||||
|  | ||||
| add_definitions(-D_CONSOLE -DMOFILE_IMPORT) | ||||
| add_dependencies(moReader moFileReader) | ||||
| target_link_libraries(moReader moFileReader) | ||||
|  | ||||
| endif () | ||||
|  | ||||
|  | ||||
|  | ||||
							
								
								
									
										70
									
								
								include/moFileConfig.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								include/moFileConfig.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | ||||
| /* | ||||
|  * moFileReader - A simple .mo-File-Reader | ||||
|  * Copyright (C) 2009 Domenico Gentner (scorcher24@gmail.com) | ||||
|  * All rights reserved.                           | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
|  * modification, are permitted provided that the following conditions | ||||
|  * are met: | ||||
|  * | ||||
|  *   1. Redistributions of source code must retain the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer. | ||||
|  * | ||||
|  *   2. Redistributions in binary form must reproduce the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer in the | ||||
|  *      documentation and/or other materials provided with the distribution. | ||||
|  * | ||||
|  *   3. The names of its contributors may not be used to endorse or promote  | ||||
|  *      products derived from this software without specific prior written  | ||||
|  *      permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
|  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
|  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
|  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||||
|  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||||
|  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||||
|  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||||
|  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||||
|  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||||
|  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||
|  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
| #ifndef __MOFILECONFIG_H_INCLUDED__ | ||||
| #define __MOFILECONFIG_H_INCLUDED__ | ||||
|  | ||||
| //------------------------------------------------------------- | ||||
| // Defines an export-macro when compiling as dll on woe32. | ||||
| //------------------------------------------------------------- | ||||
| #if defined(MOFILE_EXPORTS) && defined (WIN32) | ||||
| #   define MOEXPORT __declspec(dllexport)  | ||||
| #elif defined (MOFILE_IMPORT) && defined(WIN32)  | ||||
| #   define MOEXPORT __declspec(dllimport)  | ||||
| #else | ||||
| #   define MOEXPORT | ||||
| #endif | ||||
|  | ||||
| //------------------------------------------------------------- | ||||
| // Path-Seperators are different on other OS. | ||||
| //------------------------------------------------------------- | ||||
| #ifdef WIN32 | ||||
| #   define moPATHSEP std::string("\\") | ||||
| #else | ||||
| #   define moPATHSEP std::string("/") | ||||
| #endif | ||||
|  | ||||
| //------------------------------------------------------------- | ||||
| // Defines the beginning of the namespace moFileLib. | ||||
| //------------------------------------------------------------- | ||||
| #define MO_BEGIN_NAMESPACE namespace moFileLib{ | ||||
|  | ||||
| //------------------------------------------------------------- | ||||
| // Ends the current namespace. | ||||
| //------------------------------------------------------------- | ||||
| #define MO_END_NAMESPACE   } | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif /* __MOFILECONFIG_H_INCLUDED__ */ | ||||
|  | ||||
|  | ||||
							
								
								
									
										493
									
								
								include/moFileReader.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										493
									
								
								include/moFileReader.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,493 @@ | ||||
| /* | ||||
|  * moFileReader - A simple .mo-File-Reader | ||||
|  * Copyright (C) 2009 Domenico Gentner (scorcher24@gmail.com) | ||||
|  * All rights reserved.                           | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
|  * modification, are permitted provided that the following conditions | ||||
|  * are met: | ||||
|  * | ||||
|  *   1. Redistributions of source code must retain the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer. | ||||
|  * | ||||
|  *   2. Redistributions in binary form must reproduce the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer in the | ||||
|  *      documentation and/or other materials provided with the distribution. | ||||
|  * | ||||
|  *   3. The names of its contributors may not be used to endorse or promote  | ||||
|  *      products derived from this software without specific prior written  | ||||
|  *      permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
|  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
|  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
|  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||||
|  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||||
|  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||||
|  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||||
|  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||||
|  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||||
|  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||
|  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
| #ifndef __MOFILEREADER_H_INCLUDED__ | ||||
| #define __MOFILEREADER_H_INCLUDED__ | ||||
|  | ||||
| #include <deque> | ||||
| #include <map> | ||||
| #include <fstream> | ||||
| #include <cstring> // this is for memset when compiling with gcc. | ||||
| #include <string> | ||||
| #include <sstream> | ||||
|  | ||||
| #ifndef __MOFILECONFIG_H_INCLUDED__ | ||||
| #   include "moFileConfig.h" | ||||
| #endif | ||||
|  | ||||
| /** \mainpage moFileReaderSDK | ||||
|   *  | ||||
|   * | ||||
|   * <h2>Compilation with Visual C++ (Express and better)</h2> | ||||
|   * | ||||
|   * We provide a project for Visual C++ 2008. You can select 3 Types of Compilation: | ||||
|   * | ||||
|   * <h3>Executable (Release or Debug)</h3> | ||||
|   * | ||||
|   * This will compile the code as an executable which can lookup strings from every .mo-File you load with it. | ||||
|   * This can be handy if you want to have a peek into a file or test something etc. I recommend building the  | ||||
|   * release-executable only if you just want to use it. | ||||
|   * | ||||
|   * <h3>Dynamic Loaded Library ( ReleaseDLL )</h3> | ||||
|   * | ||||
|   * This may be overkill, but perhaps you like it modular. This Configuration will create a dll and an import-library. | ||||
|   * Do not forget to link against the import-library and please define MOFILE_IMPORT in your preprocessor-settings,  | ||||
|   *  otherwise you will receive a bunch of linker-errors.  | ||||
|   * You will find all files in the directory "lib" in the Solutions Directory. | ||||
|   * | ||||
|   * <h3>Static Library ( ReleaseLIB )</h3> | ||||
|   * | ||||
|   * This will compile the code as a static library with no Entry-Point. This is the recommended usage.  | ||||
|   * But please do not forget to link against moFileReader.static.lib. Otherwise you will receive linker-errors. | ||||
|   * | ||||
|   * <h2>Compilation via cmake</h2> | ||||
|   * | ||||
|   * - Make sure you have cmake installed and in your path. If not, go to http://www.cmake.org and get it.  | ||||
|   * - Switch to a Shell or commandline | ||||
|   * - Run cmake in $INSTALLDIR\\build. See cmake --help for possible generators. Here are the available Options: | ||||
|   *     - COMPILE_DLL Setting this to ON will compile the library as a shared module. By default, a static library is built. | ||||
|   *     . | ||||
|   *   Example: | ||||
|   *   \code | ||||
|   *   cmake -G"MinGW Makefiles" -DCOMPILE_DLL=ON | ||||
|   *   cmake -G"Visual Studio 9 2008" | ||||
|   *   // etc | ||||
|   *   \endcode | ||||
|   * | ||||
|   * cmake will compile the library and moReader[.exe]-binary, which can do lookups in moFiles and export moFiles as HTML. | ||||
|   * See moReader[.exe] --help for details.  | ||||
|   * You will find the libraries in %%projectdir%%/lib and the binary in %%projectdir%%/bin | ||||
|   * | ||||
|   * <h2>Compilation via provided batch-files (woe32 only)</h2> | ||||
|   * | ||||
|   * - Call compile_vc.bat or compile_mingw.bat with one of these options: | ||||
|   *     - DLL - Compiles as dynamic loaded module. | ||||
|   *     - LIB - Compiles as static library. | ||||
|   *     - EXE - Compiles the executable. | ||||
|   * | ||||
|   * <h2>None of those?</h2> | ||||
|   * | ||||
|   * The last option is to simply add moFileReader.cpp, moFileReader.h and moFileConfig.h to your project. Thats all you have to do.  | ||||
|   * You can safely exclude mo.cpp, since this file keeps the entry-points of the .exe and .dll only. | ||||
|   * | ||||
|   * <h2>Usage</h2> | ||||
|   * | ||||
|   * This is moFileReader, a simple gettext-replacement. The usage of this library is, hopefully, fairly simple: | ||||
|   * \code | ||||
|   * | ||||
|   * // Instanciate the class | ||||
|   * moFileLib::moFileReader reader; | ||||
|   * | ||||
|   * // Load a .mo-File. | ||||
|   * if ( reader.ReadFile("myTranslationFile.mo") != moFileLib::moFileReader::EC_SUCCESS ) | ||||
|   * { | ||||
|   *    // Error Handling | ||||
|   * } | ||||
|   * | ||||
|   * // Now, you can lookup the strings you stored in the .mo-File: | ||||
|   * std::cout << reader.Lookup("MyTranslationString") << std::endl;   | ||||
|   * | ||||
|   * \endcode | ||||
|   * Thats all! This small code has no dependencies, except the C/C++-runtime of your compiler, | ||||
|   * so it should work on all machines where a C++-runtime is provided. | ||||
|   * | ||||
|   * \note We do not yet support .mo-Files with reversed magic-numbers, since I don't have | ||||
|   *       a file to test it and I hate to release stuff I wasn't able to test.  | ||||
|   *       If you can provide such a file with reversed bytes, please compile %%projectdir%%/bin/i18n/de/moTest.po with | ||||
|   *       gettext or poEdit and send it to scorcher24 [at] gmail [dot] com. | ||||
|   * | ||||
|   * <h2>Changelog</h2> | ||||
|   *  | ||||
|   * - Version 0.1.2 | ||||
|   *     - Generic improvements to the documentation. | ||||
|   *     - Generic improvements to the code | ||||
|   *     - Fixed a bug in mo.cpp which caused the application not to print the help | ||||
|   *       message if only --export or --lookup where missing. | ||||
|   *     - Added -h, --help and -? to moReader[.exe]. It will print the help-screen. | ||||
|   *     - Added --version and -v to moReader[.exe]. It will print some informations about the program. | ||||
|   *     - Added --license to moReader[.exe]. This will print its license.  | ||||
|   *     - --export gives now a feedback about success or failure.    | ||||
|   *     - The HTML-Dump-Method outputs now the whole table from the empty msgid in a nice html-table, not only a few hardcoded.  | ||||
|   *     - I had an issue-report that the Error-Constants can collide with foreign code under certain conditions,  | ||||
|   *       so I added a patch which renamed the error-constants to more compatible names.  | ||||
|   * | ||||
|   * - Version 0.1.1 | ||||
|   *     - Added the ability to export mo's as HTML. | ||||
|   *     - Fixed a bug causing a crash when passing an invalid value to moFileReader::Lookup(). | ||||
|   *     - Added a new file, moFileConfig.h, holding the macros for the project. | ||||
|   *     - Added the ability to be configured by cmake. | ||||
|   *     - Added some more inline-functions, which really enhance the singleton. | ||||
|   * | ||||
|   * - Version 0.1.0 | ||||
|   *     - Initial Version and release to http://googlecode.com | ||||
|   * | ||||
|   * | ||||
|   * <h2>Credits</h2> | ||||
|   * | ||||
|   * Gettext is part of the GNU-Tools and (C) by the <a href="http://fsf.org">Free Software Foundation</a>.\n | ||||
|   * Visual C++ Express is a registered Trademark of Microsoft, One Microsoft Way, Redmond, USA.\n | ||||
|   * moFileReader is using NSIS for creating the setup-package. \n | ||||
|   * All other Trademarks are property of their respective owners. \n | ||||
|   * \n | ||||
|   * Thanks for using this piece of OpenSource-Software.\n | ||||
|   * If you (dis)like it or have suggestions, questions, patches etc, please don't hesitate to write to my email-adress: scorcher24 [at] gmail [dot] com. | ||||
|   * Submit patches and/or bugs on http://mofilereader.googlecode.com. You must register with googlemail to sign in. | ||||
|   * Send your flames, dumb comments etc to /dev/null, thank you.  | ||||
|   */ | ||||
|  | ||||
|  | ||||
|  | ||||
| /* | ||||
|     About Warning 4251: | ||||
|     http://support.microsoft.com/default.aspx?scid=KB;EN-US;16. | ||||
|  | ||||
|     I am aware of this warning and know how to deal with it.  | ||||
|     To avoid that derived projects are influenced by this warning | ||||
|     I have deactivated it for your convinience. | ||||
|     Note: This warning only occurs, when using this code as a DLL. | ||||
| */ | ||||
| #if defined(_MSC_VER) && ( defined(_EXPORT) || defined(MOFILE_IMPORT) ) | ||||
| #   pragma warning (disable:4251) | ||||
| #endif /* _MSC_VER */ | ||||
|  | ||||
|  | ||||
| /** \namespace moFileLib | ||||
|   * \brief This is the only namespace of this small sourcecode. | ||||
|   */ | ||||
| MO_BEGIN_NAMESPACE | ||||
|  | ||||
| const std::string g_css = \ | ||||
| "\ | ||||
| body {\ | ||||
|     background-color: black;\ | ||||
|     color: silver;\ | ||||
| }\ | ||||
| table {\ | ||||
| width: 80%;}\ | ||||
| th {\ | ||||
| background-color: orange;\ | ||||
| color: black;\ | ||||
| }\ | ||||
| hr { color: red;width: 80%; size: 5px; }\ | ||||
| a:link{color: gold;}\ | ||||
| a:visited{color: grey;}\ | ||||
| a:hover{color:blue;}\ | ||||
| .copyleft{\ | ||||
|     font-size: 12px; \ | ||||
|     text-align: center;\ | ||||
| }\ | ||||
| "; | ||||
|  | ||||
| /** | ||||
|   * \brief Keeps the Description of translated and original strings. | ||||
|   * | ||||
|   * | ||||
|   * To load a String from the file, we need its offset and its length. | ||||
|   * This struct helps us grouping this information. | ||||
|   */ | ||||
| struct moTranslationPairInformation | ||||
| { | ||||
|     /// \brief Constructor | ||||
|     moTranslationPairInformation()  | ||||
|         : m_orLength(0), m_orOffset(0),  | ||||
|           m_trLength(0), m_trOffset(0) | ||||
|     {} | ||||
|  | ||||
|     /// \brief Length of the Original String | ||||
|     int m_orLength; | ||||
|  | ||||
|     /// \brief Offset of the Original String (absolute) | ||||
|     int m_orOffset; | ||||
|  | ||||
|     /// \brief Length of the Translated String | ||||
|     int m_trLength; | ||||
|  | ||||
|     /// \brief Offset of the Translated String (absolute) | ||||
|     int m_trOffset; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|   * \brief Describes the "Header" of a .mo-File. | ||||
|   * | ||||
|   *  | ||||
|   * The File info keeps the header of a .mo-file and  | ||||
|   * a list of the string-descriptions. | ||||
|   * The typedef is for the type of the string-list. | ||||
|   * The constructor ensures, that all members get a nice | ||||
|   * initial value. | ||||
|   */      | ||||
| struct moFileInfo | ||||
| { | ||||
|     /// \brief Type for the list of all Translation-Pair-Descriptions. | ||||
|     typedef std::deque<moTranslationPairInformation> moTranslationPairList; | ||||
|  | ||||
|     /// \brief Constructor | ||||
|     moFileInfo() | ||||
|         : m_magicNumber(0), m_fileVersion(0), m_numStrings(0), | ||||
|           m_offsetOriginal(0), m_offsetTranslation(0), m_sizeHashtable(0),  | ||||
|           m_offsetHashtable(0), m_reversed(false) | ||||
|     {} | ||||
|  | ||||
|     /// \brief The Magic Number, compare it to g_MagicNumber. | ||||
|     int m_magicNumber;           | ||||
|      | ||||
|     /// \brief The File Version, 0 atm according to the manpage. | ||||
|     int m_fileVersion;           | ||||
|  | ||||
|     /// \brief Number of Strings in the .mo-file. | ||||
|     int m_numStrings;            | ||||
|  | ||||
|     /// \brief Offset of the Table of the Original Strings | ||||
|     int m_offsetOriginal;        | ||||
|  | ||||
|     /// \brief Offset of the Table of the Translated Strings | ||||
|     int m_offsetTranslation;     | ||||
|  | ||||
|     /// \brief Size of 1 Entry in the Hashtable. | ||||
|     int m_sizeHashtable;        | ||||
|  | ||||
|     /// \brief The Offset of the Hashtable. | ||||
|     int m_offsetHashtable;       | ||||
|  | ||||
|     /** \brief Tells you if the bytes are reversed | ||||
|       * \note When this is true, the bytes are reversed and the Magic number is like g_MagicReversed | ||||
|       */ | ||||
|     bool m_reversed;             | ||||
|  | ||||
|     /// \brief A list containing offset and length of the strings in the file. | ||||
|     moTranslationPairList m_translationPairInformation;    | ||||
| }; | ||||
|  | ||||
| /**  | ||||
|   * \brief This class is a gettext-replacement. | ||||
|   * | ||||
|   * | ||||
|   * The usage is quite simple:\n | ||||
|   * Tell the class which .mo-file it shall load via  | ||||
|   * moFileReader::ReadFile(). The method will attempt to load | ||||
|   * the file, all translations will be stored in memory. | ||||
|   * Afterwards you can lookup the strings with moFileReader::Lookup() just | ||||
|   * like you would do with gettext. | ||||
|   * Additionally, you can call moFileReader::ReadFile() for as much files as you  | ||||
|   * like. But please be aware, that if there are duplicated keys (original strings), | ||||
|   * that they will replace each other in the lookup-table. There is no check done, if a  | ||||
|   * key already exists. | ||||
|   * | ||||
|   * \note If you add "Lookup" to the keywords of the gettext-parser (like poEdit), | ||||
|   * it will recognize the Strings loaded with an instance of this class. | ||||
|   * \note I strongly recommend poEdit from Vaclav Slavik for editing .po-Files, | ||||
|   *       get it at http://poedit.net for various systems :). | ||||
|   */ | ||||
| class MOEXPORT moFileReader | ||||
| { | ||||
| protected: | ||||
|     /// \brief Type for the map which holds the translation-pairs later. | ||||
|     typedef std::map<std::string, std::string> moLookupList; | ||||
|  | ||||
| public: | ||||
|  | ||||
|     /// \brief The Magic Number describes the endianess of bytes on the system.    | ||||
|     static const long MagicNumber   = 0x950412DE; | ||||
|  | ||||
|     /// \brief If the Magic Number is Reversed, we need to swap the bytes.      | ||||
|     static const long MagicReversed = 0xDE120495; | ||||
|  | ||||
|     /// \brief The possible errorcodes for methods of this class | ||||
|     enum eErrorCode | ||||
|     { | ||||
|         /// \brief Indicated success | ||||
|         EC_SUCCESS = 0, | ||||
|  | ||||
|         /// \brief Indicates an error | ||||
|         EC_ERROR, | ||||
|  | ||||
|         /// \brief The given File was not found. | ||||
|         EC_FILENOTFOUND, | ||||
|  | ||||
|         /// \brief The file is invalid. | ||||
|         EC_FILEINVALID, | ||||
|  | ||||
|         /// \brief Empty Lookup-Table (returned by ExportAsHTML()) | ||||
|         EC_TABLEEMPTY, | ||||
|  | ||||
|         /// \brief The magic number did not match  | ||||
|         EC_MAGICNUMBER_NOMATCH,  | ||||
|  | ||||
|         /** | ||||
|           * \brief The magic number is reversed. | ||||
|           * \note This is an error until the class supports it. | ||||
|           */ | ||||
|         EC_MAGICNUMBER_REVERSED,            | ||||
|     }; | ||||
|  | ||||
|     /** \brief Reads a .mo-file | ||||
|      * \param[in] _filename The path to the file to load. | ||||
|      * \return SUCCESS on success or one of the other error-codes in eErrorCode on error. | ||||
|      * | ||||
|      * This is the core-feature. This method loads the .mo-file and stores | ||||
|      * all translation-pairs in a map. You can access this map via the method | ||||
|      * moFileReader::Lookup(). | ||||
|      */ | ||||
|     virtual moFileReader::eErrorCode ParseData(std::string data); | ||||
|  | ||||
|     /** \brief Reads a .mo-file | ||||
|       * \param[in] _filename The path to the file to load. | ||||
|       * \return SUCCESS on success or one of the other error-codes in eErrorCode on error. | ||||
|       * | ||||
|       * This is the core-feature. This method loads the .mo-file and stores | ||||
|       * all translation-pairs in a map. You can access this map via the method | ||||
|       * moFileReader::Lookup(). | ||||
|       */ | ||||
|     virtual eErrorCode ReadFile(const char* filename); | ||||
|  | ||||
|     /** \brief Returns the searched translation or returns the input. | ||||
|       * \param[in,out] id The id of the translation to search for. | ||||
|       * \return The value you passed in via _id or the translated string. | ||||
|       */ | ||||
|     virtual std::string Lookup( const char* id ) const; | ||||
|  | ||||
|     /// \brief Returns the Error Description. | ||||
|     virtual const std::string& GetErrorDescription() const; | ||||
|  | ||||
|     /// \brief Empties the Lookup-Table. | ||||
|     virtual void ClearTable(); | ||||
|      | ||||
|     /** \brief Returns the Number of Entries in our Lookup-Table. | ||||
|       * \note The mo-File-table always contains an empty msgid, which contains informations | ||||
|       *       about the tranlsation-project. So the real number of strings is always minus 1. | ||||
|       */ | ||||
|     virtual unsigned int GetNumStrings() const; | ||||
|  | ||||
|     /** \brief Exports the whole content of the .mo-File as .html | ||||
|       * \param[in] infile The .mo-File to export.  | ||||
|       * \param[in] filename Where to store the .html-file. If empty, the path and filename of the _infile with .html appended.  | ||||
|       * \param[in,out] css The css-script for the visual style of the  | ||||
|       *                     file, in case you don't like mine ;). | ||||
|       * \see g_css for the possible and used css-values. | ||||
|       */ | ||||
|     static eErrorCode ExportAsHTML(const std::string infile, const std::string filename = "", const std::string css = g_css ); | ||||
|  | ||||
| protected: | ||||
|     /// \brief Keeps the last error as String. | ||||
|     std::string m_error; | ||||
|  | ||||
|     /** \brief Swap the endianness of a 4 byte WORD. | ||||
|       * \param[in] in The value to swap. | ||||
|       * \return The swapped value. | ||||
|       */ | ||||
|     unsigned long SwapBytes(unsigned long in);     | ||||
|  | ||||
| private: | ||||
|     // Holds the lookup-table | ||||
|     moLookupList m_lookup; | ||||
|  | ||||
|     void MakeHtmlConform(std::string& _inout); | ||||
|     bool GetPoEditorString(const char* _buffer, std::string& _name, std::string& _value); | ||||
|     void Trim(std::string& _in); | ||||
| }; | ||||
|  | ||||
| /** \brief Convience Class | ||||
|   * | ||||
|   * | ||||
|   * This class derives from moFileReader and builds a singleton to access its methods | ||||
|   * in a global manner.  | ||||
|   * \note This class is a Singleton. Please access it via moFileReaderSingleton::GetInstance() | ||||
|   * or use the provided wrappers:\n | ||||
|   * - moReadMoFile() | ||||
|   * - _() | ||||
|   * - moFileClearTable()   | ||||
|   * - moFileGetErrorDescription() | ||||
|   * - moFileGetNumStrings(); | ||||
|   */ | ||||
| class MOEXPORT moFileReaderSingleton : public moFileReader | ||||
| { | ||||
| private: | ||||
|     // Private Contructor and Copy-Constructor to avoid  | ||||
|     // that this class is instanced. | ||||
|     moFileReaderSingleton(); | ||||
|     moFileReaderSingleton(const moFileReaderSingleton&); | ||||
|     moFileReaderSingleton& operator=(const moFileReaderSingleton&); | ||||
|      | ||||
| public: | ||||
|     /** \brief Singleton-Accessor.  | ||||
|       * \return A static instance of moFileReaderSingleton. | ||||
|       */ | ||||
|     static moFileReaderSingleton& GetInstance();       | ||||
| }; | ||||
|  | ||||
| /** \brief Reads the .mo-File. | ||||
|   * \param[in] _filename The path to the file to use. | ||||
|   * \see moFileReader::ReadFile() for details. | ||||
|   */ | ||||
| inline moFileReader::eErrorCode moReadMoFile(const char* _filename) | ||||
| { | ||||
|     moFileReader::eErrorCode r = moFileReaderSingleton::GetInstance().ReadFile(_filename); | ||||
|     return r; | ||||
| } | ||||
|  | ||||
| /** \brief Looks for the spec. string to translate. | ||||
|   * \param[in] id The string-id to search. | ||||
|   * \return The translation if found, otherwise it returns id. | ||||
|   */ | ||||
| inline std::string _(const char* id) | ||||
| { | ||||
|     std::string r = moFileReaderSingleton::GetInstance().Lookup(id); | ||||
|     return r; | ||||
| } | ||||
|  | ||||
| /// \brief Resets the Lookup-Table. | ||||
| inline void moFileClearTable() | ||||
| { | ||||
|     moFileReaderSingleton::GetInstance().ClearTable(); | ||||
| } | ||||
|  | ||||
| /// \brief Returns the last known error as string or an empty class. | ||||
| inline std::string moFileGetErrorDescription()  | ||||
| { | ||||
|     std::string r = moFileReaderSingleton::GetInstance().GetErrorDescription(); | ||||
|     return r; | ||||
| } | ||||
|  | ||||
| /// \brief Returns the number of entries loaded from the .mo-File. | ||||
| inline int moFileGetNumStrings() | ||||
| { | ||||
|     int r = moFileReaderSingleton::GetInstance().GetNumStrings(); | ||||
|     return r; | ||||
| } | ||||
|  | ||||
| #if defined(_MSC_VER) | ||||
| #   pragma warning (default:4251) | ||||
| #endif /* _MSC_VER */ | ||||
|  | ||||
| MO_END_NAMESPACE | ||||
|  | ||||
| #endif /* __MOFILEREADER_H_INCLUDED__ */ | ||||
							
								
								
									
										1474
									
								
								misc/doxygen.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1474
									
								
								misc/doxygen.conf
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										4
									
								
								misc/footer.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								misc/footer.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| <hr size="1"><address style="align: right;"><small> | ||||
| Generated on $date for $projectname by <a href="http://www.doxygen.org/index.html">Doxygen</a>$doxygenversion</small></address> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										12
									
								
								misc/header.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								misc/header.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | ||||
| <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | ||||
| <title>$title</title> | ||||
| <link href="tabs.css" rel="stylesheet" type="text/css"> | ||||
| <link href="doxygen.css" rel="stylesheet" type="text/css"> | ||||
| </head><body> | ||||
| <div class="qindex"> | ||||
|   <a class="qindex" href="index.html">Main Page</a>   | ||||
|   <a class="qindex" href="namespaces.html">Namespaces</a>   | ||||
|   <a class="qindex" href="annotated.html">Classes</a> ( <a class="qindex" href="inherits.html">Hierarchy</a> )   | ||||
|   <a class="qindex" href="functions.html">Functions & Members</a>     | ||||
| </div> | ||||
							
								
								
									
										30
									
								
								misc/license.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								misc/license.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| moFileReader - A simple .mo-File-Reader | ||||
| Copyright (C) 2009 Domenico Gentner (scorcher24@gmail.com) | ||||
| All rights reserved.                           | ||||
|  | ||||
| Redistribution and use in source and binary forms, with or without | ||||
| modification, are permitted provided that the following conditions | ||||
| are met: | ||||
|  | ||||
|   1. Redistributions of source code must retain the above copyright | ||||
|      notice, this list of conditions and the following disclaimer. | ||||
|   2. Redistributions in binary form must reproduce the above copyright | ||||
|      notice, this list of conditions and the following disclaimer in the | ||||
|      documentation and/or other materials provided with the distribution. | ||||
|  | ||||
|   3. The names of its contributors may not be used to endorse or promote  | ||||
|      products derived from this software without specific prior written  | ||||
|      permission. | ||||
|   | ||||
|   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
|   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
|   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
|   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||||
|   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||||
|   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||||
|   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||||
|   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||||
|   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||||
|   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||
|   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|   | ||||
							
								
								
									
										232
									
								
								src/mo.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								src/mo.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,232 @@ | ||||
| /* | ||||
|  * moFileReader - A simple .mo-File-Reader | ||||
|  * Copyright (C) 2009 Domenico Gentner (scorcher24@gmail.com) | ||||
|  * All rights reserved.                           | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
|  * modification, are permitted provided that the following conditions | ||||
|  * are met: | ||||
|  * | ||||
|  *   1. Redistributions of source code must retain the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer. | ||||
|  * | ||||
|  *   2. Redistributions in binary form must reproduce the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer in the | ||||
|  *      documentation and/or other materials provided with the distribution. | ||||
|  * | ||||
|  *   3. The names of its contributors may not be used to endorse or promote  | ||||
|  *      products derived from this software without specific prior written  | ||||
|  *      permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
|  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
|  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
|  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||||
|  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||||
|  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||||
|  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||||
|  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||||
|  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||||
|  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||
|  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
| #include "../include/moFileReader.h" | ||||
| #include <iostream> | ||||
| #include <cstdlib> | ||||
|  | ||||
| #if defined(_MSC_VER) && defined(_DEBUG) | ||||
| #   include <crtdbg.h>    | ||||
| #endif /* _MSC_VER */ | ||||
|  | ||||
| using namespace moFileLib; | ||||
|  | ||||
| void Usage(const std::string appname) | ||||
| { | ||||
|     std::cout << "Usage: "                                                                  << std::endl; | ||||
|     std::cout << appname << " <option> <params>"                                           << std::endl; | ||||
|     std::cout << "Possible Options: "                                                       << std::endl; | ||||
|     std::cout << "--lookup <mofile> <msgid>        - Outputs the given ID from the file."   << std::endl;     | ||||
|     std::cout << "--export <mofile> [<exportfile>] - Exports the whole .mo-file as HTML."   << std::endl;         | ||||
|     std::cout << "--help,-h,-?  - Prints this screen"                                       << std::endl; | ||||
|     std::cout << "--license     - Prints the license of this program. "                     << std::endl; | ||||
|     std::cout                                                                               << std::endl; | ||||
|     std::cout << "Example: " << appname << " --export my18n.mo exportfile.html"            << std::endl; | ||||
|     std::cout << "Example: " << appname << " --lookup my18n.mo lookupstring"               << std::endl; | ||||
|     std::cout << "Please encapsualte strings or pathes with spaces in \". Thank you."       << std::endl; | ||||
|     std::cout << "Parameters in Brackets [] are optional."                                  << std::endl; | ||||
| } | ||||
|  | ||||
| void PrintLicense() | ||||
| { | ||||
|     std::cout << "\ | ||||
|     moFileReader - A simple .mo-File-Reader\n\ | ||||
|     Copyright (C) 2009 Domenico Gentner (scorcher24@gmail.com)\n\ | ||||
|     All rights reserved.                          \n\ | ||||
|     \n\ | ||||
|     Redistribution and use in source and binary forms, with or without\n\ | ||||
|     modification, are permitted provided that the following conditions\n\ | ||||
|     are met:\n\ | ||||
|     \n\ | ||||
|     1. Redistributions of source code must retain the above copyright\n\ | ||||
|      notice, this list of conditions and the following disclaimer.\n\ | ||||
|     2. Redistributions in binary form must reproduce the above copyright\n\ | ||||
|      notice, this list of conditions and the following disclaimer in the\n\ | ||||
|      documentation and/or other materials provided with the distribution.\n\ | ||||
|     \n\ | ||||
|     3. The names of its contributors may not be used to endorse or promote \n\ | ||||
|      products derived from this software without specific prior written \n\ | ||||
|      permission.\n\ | ||||
|     \n\ | ||||
|     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\ | ||||
|     \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n\ | ||||
|     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\ | ||||
|     A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n\ | ||||
|     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\ | ||||
|     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\ | ||||
|     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\ | ||||
|     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n\ | ||||
|     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n\ | ||||
|     NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n\ | ||||
|     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\ | ||||
|     " << std::endl; | ||||
| } | ||||
|  | ||||
| std::string GetAppName(const char* raw) | ||||
| { | ||||
|     std::string r(raw); | ||||
|     int first = r.find_last_of(moPATHSEP) + 1; | ||||
|     r = r.substr(first, r.length() - first); | ||||
|     return r; | ||||
| } | ||||
|  | ||||
| #if defined(_CONSOLE) | ||||
|  | ||||
| int main( int, char** argv ) | ||||
| { | ||||
| #if defined (_DEBUG) && defined(_MSC_VER) | ||||
|             long flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); | ||||
|             flag |= _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF; | ||||
|             _CrtSetDbgFlag(flag); | ||||
| #endif /* _MSC_VER && _DEBUG */     | ||||
|  | ||||
|     std::string appname = GetAppName(argv[0]); | ||||
|  | ||||
|     if ( argv[1] == NULL ) | ||||
|     { | ||||
|         Usage(appname); | ||||
|         return EXIT_FAILURE; | ||||
|     } | ||||
|     if ( std::string(argv[1]) == "--help" || std::string(argv[1]) == "-?" || std::string(argv[1]) == "-h" ) | ||||
|     { | ||||
|         Usage(appname); | ||||
|         return EXIT_SUCCESS; | ||||
|     } | ||||
|     else if ( std::string(argv[1]) == "-v" || std::string(argv[1]) == "--version" ) | ||||
|     { | ||||
|         std::cout << "This program is part of the moReaderSDK written by Domenico Gentner."    << std::endl; | ||||
|         std::cout << "Released under the Terms of the MIT-License." << std::endl; | ||||
|         std::cout << "Type " << appname << " --license to view it." << std::endl; | ||||
|         std::cout << "Get all News and Updates from http://mofilereader.googlecode.com." << std::endl; | ||||
|         return EXIT_SUCCESS; | ||||
|     } | ||||
|     else if ( std::string(argv[1]) == "--license" ) | ||||
|     { | ||||
|         PrintLicense(); | ||||
|         return EXIT_SUCCESS; | ||||
|     } | ||||
|     else if ( std::string(argv[1]) == "--export" ) | ||||
|     { | ||||
|         std::string outfile; | ||||
|         if ( argv[2] == NULL ) | ||||
|         { | ||||
|             Usage(appname); | ||||
|             return EXIT_FAILURE; | ||||
|         } | ||||
|         if ( argv[3] ) | ||||
|         { | ||||
|             outfile = argv[3]; | ||||
|         } | ||||
|          | ||||
|         moFileReader::eErrorCode r = moFileReader::ExportAsHTML(argv[2], outfile); | ||||
|         if (  r == moFileReader::EC_SUCCESS ) | ||||
|         { | ||||
|             std::cout << "Dumped " << argv[2] << " successfully to " << outfile << std::endl; | ||||
|             return EXIT_SUCCESS; | ||||
|         } | ||||
|         else if ( r == moFileReader::EC_TABLEEMPTY ) | ||||
|         { | ||||
|             std::cout << "Could not dump " << argv[2] << " to " << outfile << " because the lookup-table is empty!" << std::endl; | ||||
|             return EXIT_FAILURE; | ||||
|         } | ||||
|         else if ( r == moFileReader::EC_FILENOTFOUND ) | ||||
|         { | ||||
|             std::cout << "Could not dump " << argv[2] << " to " << outfile << " because I could not open a file!" << std::endl; | ||||
|             return EXIT_FAILURE;             | ||||
|         } | ||||
|         else if ( r == moFileReader::EC_FILEINVALID ) | ||||
|         { | ||||
|             std::cout << "Could not dump " << argv[2] << " to " << outfile << " because the .mo-File was invalid!" << std::endl; | ||||
|             return EXIT_FAILURE; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             std::cout << "Could not dump " << argv[2] << " to " << outfile << ". An unknown error occured." << std::endl; | ||||
|             return EXIT_FAILURE; | ||||
|         } | ||||
|     } | ||||
|     else if ( std::string(argv[1]) == "--lookup") | ||||
|     { | ||||
|         if ( argv[2] == NULL || argv[3] == NULL ) | ||||
|         { | ||||
|             Usage(appname); | ||||
|             if (argv[3] == NULL) | ||||
|                 std::cout << "HINT: If you want to call an empty msgid, please use \"\" as parameter 3." << std::endl; | ||||
|             return EXIT_FAILURE; | ||||
|         } | ||||
|         if ( moReadMoFile(argv[2]) != moFileReader::EC_SUCCESS ) | ||||
|         { | ||||
|             std::cout << "Error while loading the file: " << moFileGetErrorDescription() << std::endl; | ||||
|             return -1; | ||||
|         } | ||||
|         std::cout << "-----------------------------------------" << std::endl; | ||||
|         std::cout << "Lookup: " <<   argv[3]                     << std::endl; | ||||
|         std::cout << "Result: " << _(argv[3])                    << std::endl; | ||||
|         std::cout << "-----------------------------------------" << std::endl; | ||||
|         return EXIT_SUCCESS; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         Usage(appname); | ||||
|         std::cout << std::endl; | ||||
|         std::cout << "HINT: Missing --export or --lookup!" << std::endl; | ||||
|         return EXIT_FAILURE; | ||||
|     } | ||||
| } | ||||
|  | ||||
| #elif defined(_USRDLL) && defined(WIN32) | ||||
|  | ||||
| #include <windows.h> | ||||
| extern "C" | ||||
| int WINAPI DllMain( DWORD reason, LPVOID) | ||||
| { | ||||
|     switch (reason) | ||||
|     { | ||||
|         case DLL_THREAD_ATTACH: | ||||
|         case DLL_PROCESS_ATTACH: | ||||
|             { | ||||
| #if defined (_DEBUG) && defined(_MSC_VER) | ||||
|             long flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); | ||||
|             flag |= _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF; | ||||
|             _CrtSetDbgFlag(flag); | ||||
| #endif /* _MSC_VER && _DEBUG */ | ||||
|             break; | ||||
|             } | ||||
|         default: | ||||
|             return FALSE; | ||||
|     }; | ||||
|  | ||||
|     return TRUE; | ||||
| } | ||||
|  | ||||
| #endif /* Compilation-Mode */ | ||||
|  | ||||
							
								
								
									
										509
									
								
								src/moFileReader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										509
									
								
								src/moFileReader.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,509 @@ | ||||
| /* | ||||
|  * moFileReader - A simple .mo-File-Reader | ||||
|  * Copyright (C) 2009 Domenico Gentner (scorcher24@gmail.com) | ||||
|  * All rights reserved.                           | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
|  * modification, are permitted provided that the following conditions | ||||
|  * are met: | ||||
|  * | ||||
|  *   1. Redistributions of source code must retain the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer. | ||||
|  * | ||||
|  *   2. Redistributions in binary form must reproduce the above copyright | ||||
|  *      notice, this list of conditions and the following disclaimer in the | ||||
|  *      documentation and/or other materials provided with the distribution. | ||||
|  * | ||||
|  *   3. The names of its contributors may not be used to endorse or promote  | ||||
|  *      products derived from this software without specific prior written  | ||||
|  *      permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
|  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
|  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
|  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||||
|  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||||
|  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||||
|  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||||
|  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||||
|  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||||
|  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||
|  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
| #include "../include/moFileReader.h" | ||||
| #include <iostream> | ||||
| #include <cstdlib> | ||||
|  | ||||
| MO_BEGIN_NAMESPACE | ||||
|  | ||||
| unsigned long moFileReader::SwapBytes(unsigned long in)  | ||||
| { | ||||
|     unsigned long b0 = (in >> 0) & 0xff; | ||||
|     unsigned long b1 = (in >> 8) & 0xff; | ||||
|     unsigned long b2 = (in >> 16) & 0xff; | ||||
|     unsigned long b3 = (in >> 24) & 0xff; | ||||
|  | ||||
|     return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3; | ||||
| } | ||||
|  | ||||
| const std::string& moFileReader::GetErrorDescription() const | ||||
| { | ||||
|     return m_error; | ||||
| } | ||||
|  | ||||
| void moFileReader::ClearTable() | ||||
| { | ||||
|     m_lookup.clear(); | ||||
| } | ||||
|  | ||||
| unsigned int moFileReader::GetNumStrings() const | ||||
| { | ||||
|     return m_lookup.size(); | ||||
| } | ||||
|  | ||||
| std::string moFileReader::Lookup( const char* id ) const | ||||
| { | ||||
|     if ( m_lookup.size() <= 0) return id; | ||||
|     moLookupList::const_iterator iterator = m_lookup.find(id);     | ||||
|  | ||||
|     if ( iterator == m_lookup.end() ) | ||||
|     { | ||||
|         return id; | ||||
|     } | ||||
|     return iterator->second; | ||||
| } | ||||
|  | ||||
| moFileReader::eErrorCode moFileReader::ParseData(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; | ||||
| } | ||||
|  | ||||
| moFileReader::eErrorCode moFileReader::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() ) | ||||
|     { | ||||
|         m_error = std::string("Cannot open File ") + std::string(filename); | ||||
|         return moFileReader::EC_FILENOTFOUND; | ||||
|     } | ||||
|  | ||||
|     // 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() ) | ||||
|     { | ||||
|         stream.close(); | ||||
|         m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; | ||||
|         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!"; | ||||
|             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() ) | ||||
|         { | ||||
|             stream.close(); | ||||
|             m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; | ||||
|             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() ) | ||||
|         { | ||||
|             stream.close(); | ||||
|             m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; | ||||
|             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!"; | ||||
|             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!"; | ||||
|             return moFileReader::EC_FILEINVALID; | ||||
|         } | ||||
|  | ||||
|         // Store it in the map.     | ||||
|         m_lookup[std::string(original)] = std::string(translation); | ||||
|  | ||||
|         // Cleanup... | ||||
|         delete original; | ||||
|         delete translation; | ||||
|     } | ||||
|  | ||||
|     // Done :) | ||||
|     stream.close(); | ||||
|     return moFileReader::EC_SUCCESS; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| moFileReader::eErrorCode moFileReader::ExportAsHTML(std::string infile, std::string filename, std::string css ) | ||||
| { | ||||
|     // Read the file | ||||
|     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; | ||||
|     }     | ||||
|  | ||||
|     // Beautify Output | ||||
|     std::string fname; | ||||
|     unsigned int pos = infile.find_last_of(moPATHSEP); | ||||
|     if ( pos != std::string::npos ) | ||||
|     { | ||||
|         fname = infile.substr( pos+1, infile.length() ); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         fname = infile; | ||||
|     } | ||||
|  | ||||
|     // if there is no filename given, we set it to the .mo + html, e.g. test.mo.html | ||||
|     std::string htmlfile(filename); | ||||
|     if (htmlfile.empty()) | ||||
|     { | ||||
|         htmlfile = infile + std::string(".html"); | ||||
|     }    | ||||
|  | ||||
|     // Ok, now prepare output. | ||||
|     std::ofstream stream(htmlfile.c_str()); | ||||
|     if ( stream.is_open() )  | ||||
|     { | ||||
|         stream << "<!DOCTYPE HTML PUBLIC \"- //W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" << std::endl; | ||||
|         stream << "<html><head><style type=\"text/css\">\n" << std::endl; | ||||
|         stream << css << std::endl; | ||||
|         stream << "</style>" << std::endl; | ||||
|         stream << "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">" << std::endl; | ||||
|         stream << "<title>Dump of " << fname << "</title></head>" << std::endl; | ||||
|         stream << "<body>" << std::endl; | ||||
|         stream << "<center>" <<std::endl; | ||||
|         stream << "<h1>" << fname << "</h1>" << std::endl; | ||||
|         stream << "<table border=\"1\"><th colspan=\"2\">Project Info</th>" << std::endl; | ||||
|  | ||||
|         std::stringstream parsee; | ||||
|         parsee << reader.Lookup(""); | ||||
|       | ||||
|         while ( !parsee.eof() ) | ||||
|         { | ||||
|             char buffer[1024]; | ||||
|             parsee.getline(buffer, 1024); | ||||
|             std::string name; | ||||
|             std::string value; | ||||
|  | ||||
|             reader.GetPoEditorString( buffer, name, value ); | ||||
|             if ( !(name.empty() || value.empty()) ) | ||||
|             { | ||||
|                 stream << "<tr><td>" << name << "</td><td>" <<  value << "</td></tr>" << std::endl; | ||||
|             } | ||||
|         } | ||||
|         stream << "</table>" << std::endl; | ||||
|         stream << "<hr noshade/>" << std::endl; | ||||
|  | ||||
|         // Now output the content | ||||
|         stream << "<table border=\"1\"><th colspan=\"2\">Content</th>" << std::endl;         | ||||
|         for ( moLookupList::const_iterator it = reader.m_lookup.begin();  | ||||
|              it != reader.m_lookup.end(); it++) | ||||
|         { | ||||
|             if ( it->first != "" ) // Skip the empty msgid, its the table we handled above. | ||||
|             { | ||||
|                 stream << "<tr><td>" << it->first << "</td><td>" <<  it->second << "</td></tr>" << std::endl; | ||||
|             } | ||||
|         } | ||||
|         stream << "</table><br/>" << std::endl; | ||||
|  | ||||
|         stream << "</center>" << std::endl; | ||||
|         stream << "<div class=\"copyleft\">File generated by <a href=\"http://mofilereader.googlecode.com\" target=\"_blank\">moFileReaderSDK</a></div>" << std::endl;         | ||||
|         stream << "</body></html>" << std::endl; | ||||
|         stream.close(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         return moFileReader::EC_FILENOTFOUND; | ||||
|     } | ||||
|     | ||||
|     return moFileReader::EC_SUCCESS; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Removes spaces from front and end.  | ||||
| void moFileReader::Trim(std::string& in) | ||||
| { | ||||
|     while ( in[0] == ' ' ) | ||||
|     { | ||||
|         in = in.substr(1, in.length() ); | ||||
|     } | ||||
|     while( in[in.length()] == ' ' ) | ||||
|     { | ||||
|         in = in.substr(0, in.length() - 1 ); | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Extracts a value-pair from the po-edit-information | ||||
| bool moFileReader::GetPoEditorString(const char* buffer, std::string& name, std::string& value) | ||||
| { | ||||
|     std::string line(buffer); | ||||
|     size_t first = line.find_first_of(":"); | ||||
|  | ||||
|     if ( first != std::string::npos ) | ||||
|     { | ||||
|         name   = line.substr( 0, first ); | ||||
|         value  = line.substr( first + 1, line.length() ); | ||||
|  | ||||
|         // Replace <> with () for Html-Conformity. | ||||
|         MakeHtmlConform(value); | ||||
|         MakeHtmlConform(name); | ||||
|  | ||||
|         // Remove spaces from front and end. | ||||
|         Trim(value); | ||||
|         Trim(name); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
|  | ||||
| // Replaces < with ( to satisfy html-rules. | ||||
| void moFileReader::MakeHtmlConform(std::string& inout) | ||||
| { | ||||
|     std::string temp = inout; | ||||
|     for ( unsigned int i = 0; i < temp.length(); i++) | ||||
|     { | ||||
|         if ( temp[i] == '>') | ||||
|         { | ||||
|             inout.replace(i, 1, ")"); | ||||
|         } | ||||
|         if ( temp[i] == '<' ) | ||||
|         { | ||||
|             inout.replace(i, 1, "("); | ||||
|         } | ||||
|     }     | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| moFileReaderSingleton& moFileReaderSingleton::GetInstance() | ||||
| { | ||||
|     static moFileReaderSingleton theoneandonly; | ||||
|     return theoneandonly; | ||||
| }  | ||||
|  | ||||
|  | ||||
| moFileReaderSingleton::moFileReaderSingleton(const moFileReaderSingleton& ) | ||||
| { | ||||
| } | ||||
|  | ||||
| moFileReaderSingleton::moFileReaderSingleton() | ||||
| { | ||||
| } | ||||
|  | ||||
| moFileReaderSingleton& moFileReaderSingleton::operator=(const moFileReaderSingleton&) | ||||
| { | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| MO_END_NAMESPACE | ||||
							
								
								
									
										1
									
								
								test/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								test/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| /*.exe | ||||
							
								
								
									
										6
									
								
								test/test.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								test/test.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| void foo() | ||||
| { | ||||
| 	_("String English One"); | ||||
| 	_("String English Two"); | ||||
| 	_("String English Three"); | ||||
| } | ||||
							
								
								
									
										31
									
								
								test/test.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								test/test.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| <!DOCTYPE HTML PUBLIC "- //W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||||
| <html><head><style type="text/css"> | ||||
|  | ||||
| body {    background-color: black;    color: silver;}table {width: 80%;}th {background-color: orange;color: black;}hr { color: red;width: 80%; size: 5px; }a:link{color: gold;}a:visited{color: grey;}a:hover{color:blue;}.copyleft{    font-size: 12px;     text-align: center;} | ||||
| </style> | ||||
| <meta http-equiv="content-type" content="text/html; charset=utf-8"> | ||||
| <title>Dump of test.mo</title></head> | ||||
| <body> | ||||
| <center> | ||||
| <h1>test.mo</h1> | ||||
| <table border="1"><th colspan="2">Project Info</th> | ||||
| <tr><td>Project-Id-Version</td><td>moFileTest</td></tr> | ||||
| <tr><td>POT-Creation-Date</td><td>2012-05-20 00:51+0100</td></tr> | ||||
| <tr><td>PO-Revision-Date</td><td>2012-05-20 00:57+0100</td></tr> | ||||
| <tr><td>Last-Translator</td><td>scorcher24 <scorcher24@gmail.>om></td></tr> | ||||
| <tr><td>MIME-Version</td><td>1.0</td></tr> | ||||
| <tr><td>Content-Type</td><td>text/plain; charset=UTF-8</td></tr> | ||||
| <tr><td>Content-Transfer-Encoding</td><td>8bit</td></tr> | ||||
| <tr><td>X-Poedit-KeywordsList</td><td>_;gettext;gettext_noop</td></tr> | ||||
| <tr><td>X-Poedit-Basepath</td><td>.</td></tr> | ||||
| <tr><td>X-Poedit-SearchPath-0</td><td>.</td></tr> | ||||
| </table> | ||||
| <hr noshade/> | ||||
| <table border="1"><th colspan="2">Content</th> | ||||
| <tr><td>String English One</td><td>Zeichenkette Englisch Eins</td></tr> | ||||
| <tr><td>String English Three</td><td>Zeichenkette Englisch Drei</td></tr> | ||||
| <tr><td>String English Two</td><td>Zeichenkette Englisch Zwei</td></tr> | ||||
| </table><br/> | ||||
| </center> | ||||
| <div class="copyleft">File generated by <a href="http://mofilereader.googlecode.com" target="_blank">moFileReaderSDK</a></div> | ||||
| </body></html> | ||||
							
								
								
									
										
											BIN
										
									
								
								test/test.mo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/test.mo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										27
									
								
								test/test.po
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								test/test.po
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| msgid "" | ||||
| msgstr "" | ||||
| "Project-Id-Version: moFileTest\n" | ||||
| "Report-Msgid-Bugs-To: \n" | ||||
| "POT-Creation-Date: 2012-05-20 00:51+0100\n" | ||||
| "PO-Revision-Date: 2012-05-20 00:57+0100\n" | ||||
| "Last-Translator: scorcher24 <scorcher24@gmail.com>\n" | ||||
| "Language-Team: \n" | ||||
| "MIME-Version: 1.0\n" | ||||
| "Content-Type: text/plain; charset=UTF-8\n" | ||||
| "Content-Transfer-Encoding: 8bit\n" | ||||
| "X-Poedit-KeywordsList: _;gettext;gettext_noop\n" | ||||
| "X-Poedit-Basepath: .\n" | ||||
| "X-Poedit-SearchPath-0: .\n" | ||||
|  | ||||
| #: test.cpp:3 | ||||
| msgid "String English One" | ||||
| msgstr "Zeichenkette Englisch Eins" | ||||
|  | ||||
| #: test.cpp:4 | ||||
| msgid "String English Two" | ||||
| msgstr "Zeichenkette Englisch Zwei" | ||||
|  | ||||
| #: test.cpp:5 | ||||
| msgid "String English Three" | ||||
| msgstr "Zeichenkette Englisch Drei" | ||||
|  | ||||
		Reference in New Issue
	
	Block a user