Merge branch 'use_log_in_tinygettext'
This commit is contained in:
commit
959c86d816
@ -1,5 +1,5 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -16,9 +16,10 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include <assert.h>
|
||||
#include "log_stream.hpp"
|
||||
#include "dictionary.hpp"
|
||||
|
||||
#include "utils/log.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
Dictionary::Dictionary(const std::string& charset_) :
|
||||
@ -168,8 +169,9 @@ Dictionary::add_translation(const std::string& msgid, const std::string& msgstr)
|
||||
}
|
||||
else
|
||||
{
|
||||
log_warning << "collision in add_translation: '"
|
||||
<< msgid << "' -> '" << msgstr << "' vs '" << vec[0] << "'" << std::endl;
|
||||
Log::warn("tinygettext",
|
||||
"Collision in add translation: '%s' -> '%s' vs '%s'.",
|
||||
msgid.c_str(), msgstr.c_str(), vec[0].c_str());
|
||||
vec[0] = msgstr;
|
||||
}
|
||||
}
|
||||
@ -186,7 +188,9 @@ Dictionary::add_translation(const std::string& msgctxt,
|
||||
}
|
||||
else
|
||||
{
|
||||
log_warning << "collision in add_translation(\"" << msgctxt << "\", \"" << msgid << "\", \"" << msgid_plural << "\")" << std::endl;
|
||||
Log::warn("tinygettext",
|
||||
"collision in add_translation(\"%s\", \"%s\", \"%s\")",
|
||||
msgctxt.c_str(), msgid.c_str(), msgid_plural.c_str());
|
||||
vec = msgstrs;
|
||||
}
|
||||
}
|
||||
@ -201,7 +205,8 @@ Dictionary::add_translation(const std::string& msgctxt, const std::string& msgid
|
||||
}
|
||||
else
|
||||
{
|
||||
log_warning << "collision in add_translation(\"" << msgctxt << "\", \"" << msgid << "\")" << std::endl;
|
||||
Log::warn("tinygettext", "collision in add_translation(\"%s\", \"%s\")",
|
||||
msgctxt.c_str(), msgid.c_str());
|
||||
vec[0] = msgstr;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include "dictionary_manager.hpp"
|
||||
|
||||
#include "utils/log.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@ -24,7 +26,6 @@
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "log_stream.hpp"
|
||||
#include "po_parser.hpp"
|
||||
#include "stk_file_system.hpp"
|
||||
|
||||
@ -134,7 +135,8 @@ DictionaryManager::get_dictionary(const Language& language)
|
||||
|
||||
if (!po_language)
|
||||
{
|
||||
log_warning << *filename << ": warning: ignoring, unknown language" << std::endl;
|
||||
Log::warn("tinygettext", "%s: warning: ignoring, unknown language",
|
||||
filename->c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -157,7 +159,8 @@ DictionaryManager::get_dictionary(const Language& language)
|
||||
std::auto_ptr<std::istream> in = filesystem->open_file(pofile);
|
||||
if (!in.get())
|
||||
{
|
||||
log_error << "error: failure opening: " << pofile << std::endl;
|
||||
Log::error("tinygettext", "error: failure opening: '%s'.",
|
||||
pofile.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -166,8 +169,8 @@ DictionaryManager::get_dictionary(const Language& language)
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
log_error << "error: failure parsing: " << pofile << std::endl;
|
||||
log_error << e.what() << "" << std::endl;
|
||||
Log::error("tinygettext", "error: failure parsing: '%s'.", pofile.c_str());
|
||||
Log::error("tinygettext", "%s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,150 +0,0 @@
|
||||
// tinygettext - A gettext replacement that works directly on .po files
|
||||
// Copyright (C) 2009-2015 Ingo Ruhnke <grumbel@gmx.de>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
/*
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
#include <errno.h>
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "iconv.hpp"
|
||||
#include "log_stream.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
#ifndef tinygettext_ICONV_CONST
|
||||
# define tinygettext_ICONV_CONST
|
||||
#endif
|
||||
|
||||
IConv::IConv()
|
||||
: to_charset(),
|
||||
from_charset(),
|
||||
cd(0)
|
||||
{}
|
||||
|
||||
IConv::IConv(const std::string& from_charset_, const std::string& to_charset_)
|
||||
: to_charset(),
|
||||
from_charset(),
|
||||
cd(0)
|
||||
{
|
||||
set_charsets(from_charset_, to_charset_);
|
||||
}
|
||||
|
||||
IConv::~IConv()
|
||||
{
|
||||
if (cd)
|
||||
tinygettext_iconv_close(cd);
|
||||
}
|
||||
|
||||
void
|
||||
IConv::set_charsets(const std::string& from_charset_, const std::string& to_charset_)
|
||||
{
|
||||
if (cd)
|
||||
tinygettext_iconv_close(cd);
|
||||
|
||||
from_charset = from_charset_;
|
||||
to_charset = to_charset_;
|
||||
|
||||
for(std::string::iterator i = to_charset.begin(); i != to_charset.end(); ++i)
|
||||
*i = static_cast<char>(toupper(*i));
|
||||
|
||||
for(std::string::iterator i = from_charset.begin(); i != from_charset.end(); ++i)
|
||||
*i = static_cast<char>(toupper(*i));
|
||||
|
||||
if (to_charset == from_charset)
|
||||
{
|
||||
cd = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cd = tinygettext_iconv_open(to_charset.c_str(), from_charset.c_str());
|
||||
if (cd == reinterpret_cast<tinygettext_iconv_t>(-1))
|
||||
{
|
||||
if(errno == EINVAL)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "IConv construction failed: conversion from '" << from_charset
|
||||
<< "' to '" << to_charset << "' not available";
|
||||
throw std::runtime_error(str.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "IConv: construction failed: " << strerror(errno);
|
||||
throw std::runtime_error(str.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a string from encoding to another.
|
||||
std::string
|
||||
IConv::convert(const std::string& text)
|
||||
{
|
||||
if (!cd)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t inbytesleft = text.size();
|
||||
size_t outbytesleft = 4*inbytesleft; // Worst case scenario: ASCII -> UTF-32?
|
||||
|
||||
// We try to avoid to much copying around, so we write directly into
|
||||
// a std::string
|
||||
tinygettext_ICONV_CONST char* inbuf = const_cast<char*>(&text[0]);
|
||||
std::string result(outbytesleft, 'X');
|
||||
char* outbuf = &result[0];
|
||||
|
||||
// Try to convert the text.
|
||||
size_t ret = tinygettext_iconv(cd, (const char**)&inbuf, &inbytesleft, &outbuf, &outbytesleft);
|
||||
if (ret == static_cast<size_t>(-1))
|
||||
{
|
||||
if (errno == EILSEQ || errno == EINVAL)
|
||||
{ // invalid multibyte sequence
|
||||
tinygettext_iconv(cd, NULL, NULL, NULL, NULL); // reset state
|
||||
|
||||
// FIXME: Could try to skip the invalid byte and continue
|
||||
log_error << "error: tinygettext:iconv: invalid multibyte sequence in: \"" << text << "\"" << std::endl;
|
||||
}
|
||||
else if (errno == E2BIG)
|
||||
{ // output buffer to small
|
||||
assert(!"tinygettext/iconv.cpp: E2BIG: This should never be reached");
|
||||
}
|
||||
else if (errno == EBADF)
|
||||
{
|
||||
assert(!"tinygettext/iconv.cpp: EBADF: This should never be reached");
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!"tinygettext/iconv.cpp: <unknown>: This should never be reached");
|
||||
}
|
||||
}
|
||||
|
||||
result.resize(4*text.size() - outbytesleft);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace tinygettext
|
||||
*/
|
||||
|
||||
/* EOF */
|
@ -1,72 +0,0 @@
|
||||
// tinygettext - A gettext replacement that works directly on .po files
|
||||
// Copyright (C) 2006-2015 Ingo Ruhnke <grumbel@gmx.de>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
#ifndef HEADER_TINYGETTEXT_ICONV_HPP
|
||||
#define HEADER_TINYGETTEXT_ICONV_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
# include "SDL.h"
|
||||
|
||||
# define tinygettext_ICONV_CONST const
|
||||
# define tinygettext_iconv_t SDL_iconv_t
|
||||
# define tinygettext_iconv SDL_iconv
|
||||
# define tinygettext_iconv_open SDL_iconv_open
|
||||
# define tinygettext_iconv_close SDL_iconv_close
|
||||
#else
|
||||
# include <iconv.h>
|
||||
|
||||
# ifdef HAVE_ICONV_CONST
|
||||
# define tinygettext_ICONV_CONST ICONV_CONST
|
||||
# else
|
||||
# define tinygettext_ICONV_CONST
|
||||
# endif
|
||||
|
||||
# define tinygettext_iconv_t iconv_t
|
||||
# define tinygettext_iconv iconv
|
||||
# define tinygettext_iconv_open iconv_open
|
||||
# define tinygettext_iconv_close iconv_close
|
||||
#endif
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
class IConv
|
||||
{
|
||||
private:
|
||||
std::string to_charset;
|
||||
std::string from_charset;
|
||||
tinygettext_iconv_t cd;
|
||||
|
||||
public:
|
||||
IConv();
|
||||
IConv(const std::string& fromcode, const std::string& tocode);
|
||||
~IConv();
|
||||
|
||||
void set_charsets(const std::string& fromcode, const std::string& tocode);
|
||||
std::string convert(const std::string& text);
|
||||
|
||||
private:
|
||||
IConv (const IConv&);
|
||||
IConv& operator= (const IConv&);
|
||||
};
|
||||
|
||||
} // namespace tinygettext
|
||||
|
||||
#endif
|
||||
*/
|
||||
/* EOF */
|
@ -1,34 +0,0 @@
|
||||
// tinygettext - A gettext replacement that works directly on .po files
|
||||
// Copyright (C) 2009-2015 Ingo Ruhnke <grumbel@gmx.de>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_TINYGETTEXT_LOG_STREAM_HPP
|
||||
#define HEADER_TINYGETTEXT_LOG_STREAM_HPP
|
||||
|
||||
#include "tgt_log.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
// FIXME: very bad to have such things in the API
|
||||
#define log_error if (!Log::log_error_callback); else (Log(Log::log_error_callback)).get()
|
||||
#define log_warning if (!Log::log_warning_callback); else (Log(Log::log_warning_callback)).get()
|
||||
#define log_info if (!Log::log_info_callback); else (Log(Log::log_warning_callback)).get()
|
||||
|
||||
} // namespace tinygettext
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
@ -22,15 +22,16 @@
|
||||
#include <string>
|
||||
#include <istream>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "language.hpp"
|
||||
#include "log_stream.hpp"
|
||||
#include "iconv.hpp"
|
||||
#include "dictionary.hpp"
|
||||
#include "plural_forms.hpp"
|
||||
|
||||
#include "utils/log.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
bool POParser::pedantic = true;
|
||||
@ -65,14 +66,15 @@ POParser::~POParser()
|
||||
void
|
||||
POParser::warning(const std::string& msg)
|
||||
{
|
||||
log_warning << filename << ":" << line_number << ": warning: " << msg << ": " << current_line << std::endl;
|
||||
//log_warning << "Line: " << current_line << std::endl;
|
||||
Log::warn("tinygettext", "%s line %d %s: \"%s\"",
|
||||
filename.c_str(), line_number, msg.c_str(), current_line.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
POParser::error(const std::string& msg)
|
||||
{
|
||||
log_error << filename << ":" << line_number << ": error: " << msg << ": " << current_line << std::endl;
|
||||
Log::error("tinygettext", "%s line %d %s: \"%s\"",
|
||||
filename.c_str(), line_number, msg.c_str(), current_line.c_str());
|
||||
|
||||
// Try to recover from an error by searching for start of another entry
|
||||
do
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
||||
//#include "iconv.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
class Dictionary;
|
||||
|
@ -1,70 +0,0 @@
|
||||
// tinygettext - A gettext replacement that works directly on .po files
|
||||
// Copyright (C) 2009-2015 Ingo Ruhnke <grumbel@gmx.de>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include <iostream>
|
||||
#include "tgt_log.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
Log::log_callback_t Log::log_info_callback = &Log::default_log_callback;
|
||||
Log::log_callback_t Log::log_warning_callback = &Log::default_log_callback;
|
||||
Log::log_callback_t Log::log_error_callback = &Log::default_log_callback;
|
||||
|
||||
void
|
||||
Log::default_log_callback(const std::string& str)
|
||||
{
|
||||
std::cerr << "tinygettext: " << str;
|
||||
}
|
||||
|
||||
void
|
||||
Log::set_log_info_callback(log_callback_t callback)
|
||||
{
|
||||
log_info_callback = callback;
|
||||
}
|
||||
|
||||
void
|
||||
Log::set_log_warning_callback(log_callback_t callback)
|
||||
{
|
||||
log_warning_callback = callback;
|
||||
}
|
||||
|
||||
void
|
||||
Log::set_log_error_callback(log_callback_t callback)
|
||||
{
|
||||
log_error_callback = callback;
|
||||
}
|
||||
|
||||
Log::Log(log_callback_t callback_) :
|
||||
callback(callback_),
|
||||
out()
|
||||
{
|
||||
}
|
||||
|
||||
Log::~Log()
|
||||
{
|
||||
callback(out.str());
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
Log::get()
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace tinygettext
|
||||
|
||||
/* EOF */
|
@ -1,56 +0,0 @@
|
||||
// tinygettext - A gettext replacement that works directly on .po files
|
||||
// Copyright (C) 2009-2015 Ingo Ruhnke <grumbel@gmx.de>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_TINYGETTEXT_LOG_HPP
|
||||
#define HEADER_TINYGETTEXT_LOG_HPP
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
typedef void (*log_callback_t)(const std::string&);
|
||||
|
||||
static log_callback_t log_info_callback;
|
||||
static log_callback_t log_warning_callback;
|
||||
static log_callback_t log_error_callback;
|
||||
|
||||
|
||||
static void default_log_callback(const std::string& str);
|
||||
|
||||
static void set_log_info_callback(log_callback_t callback);
|
||||
static void set_log_warning_callback(log_callback_t callback);
|
||||
static void set_log_error_callback(log_callback_t callback);
|
||||
|
||||
private:
|
||||
log_callback_t callback;
|
||||
std::ostringstream out;
|
||||
|
||||
public:
|
||||
Log(log_callback_t callback);
|
||||
~Log();
|
||||
|
||||
std::ostream& get();
|
||||
};
|
||||
|
||||
} // namespace tinygettext
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
Loading…
x
Reference in New Issue
Block a user