pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2983 - in branches/pingus_sdl: . src src/tinygettext


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2983 - in branches/pingus_sdl: . src src/tinygettext
Date: Fri, 17 Aug 2007 16:38:08 +0200

Author: grumbel
Date: 2007-08-17 16:38:08 +0200 (Fri, 17 Aug 2007)
New Revision: 2983

Added:
   branches/pingus_sdl/src/tinygettext/iconv.cpp
   branches/pingus_sdl/src/tinygettext/iconv.hpp
Modified:
   branches/pingus_sdl/TODO
   branches/pingus_sdl/src/SConscript
   branches/pingus_sdl/src/pingus_main.cpp
   branches/pingus_sdl/src/tinygettext/po_file_reader.cpp
Log:
- splitted of another iconv file
- some TODO stuff

Modified: branches/pingus_sdl/TODO
===================================================================
--- branches/pingus_sdl/TODO    2007-08-17 04:33:30 UTC (rev 2982)
+++ branches/pingus_sdl/TODO    2007-08-17 14:38:08 UTC (rev 2983)
@@ -48,9 +48,6 @@
 Important:
 ==========
 
-- copy all translations in level files over to the LANG.po file (take care of 
encoding!)
-
-
 - paralax handling is different between 0.6 and SDL, see
   data/levels/playable/slidenride1-grumbel.pingus
 
@@ -61,18 +58,16 @@
 
 - remove all the remaining unneeded debuging std::cout's
 
-- Latin1 clean (also Latin-2 and Latin-9, see:
-  http://kapsa.cz/~tomasb/pingus/intl-patch.tgz)
+- Latin-2 and Latin-9 aren't not working, see language tr, cs, sr
 
 - src/components/pingus_counter.hpp font should be fixed-width/monospace
 
-- forgein languages break many parts of the GUI
+- forgein languages break many parts of the GUI (font align, mostly worldmap)
 
-
 Nice to Have:
 =============
 
-- sv.po - ISO-8859-1 - (incomplete)
+- sv.po, Swedish is incomplete, lacks level and story text
 
 - story graphics have a missing vertical line (due to age old gimp scaling bug)
 

Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript  2007-08-17 04:33:30 UTC (rev 2982)
+++ branches/pingus_sdl/src/SConscript  2007-08-17 14:38:08 UTC (rev 2983)
@@ -245,7 +245,8 @@
 'math/origin.cpp',
 'math/rect.cpp',
 'system.cpp', 
-'timer.cpp', 
+'timer.cpp',
+'tinygettext/iconv.cpp',
 'tinygettext/po_file_reader.cpp',
 'tinygettext/dictionary_manager.cpp',
 'tinygettext/dictionary.cpp',

Modified: branches/pingus_sdl/src/pingus_main.cpp
===================================================================
--- branches/pingus_sdl/src/pingus_main.cpp     2007-08-17 04:33:30 UTC (rev 
2982)
+++ branches/pingus_sdl/src/pingus_main.cpp     2007-08-17 14:38:08 UTC (rev 
2983)
@@ -632,9 +632,8 @@
   // dictionary_manager.set_language("de"); 
   dictionary_manager.add_directory(path_manager.complete("po/"));
 
-  std::string language = 
dictionary_manager.get_dictionary().get_language().name;
+  std::string language = 
dictionary_manager.get_dictionary().get_language().code;
 
-  language.resize(2);
   if(language == "cs" || language == "sr")
     {
       dictionary_manager.set_charset("ISO-8859-2");

Added: branches/pingus_sdl/src/tinygettext/iconv.cpp
===================================================================
--- branches/pingus_sdl/src/tinygettext/iconv.cpp       2007-08-17 04:33:30 UTC 
(rev 2982)
+++ branches/pingus_sdl/src/tinygettext/iconv.cpp       2007-08-17 14:38:08 UTC 
(rev 2983)
@@ -0,0 +1,151 @@
+//  $Id$
+// 
+//  TinyGetText - A small flexible gettext() replacement
+//  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+//
+//  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 <config.h>
+#include <iostream>
+#include <sstream>
+#include <errno.h>
+#include <stdexcept>
+#include "iconv.hpp"
+
+namespace TinyGetText {
+
+IConv::IConv() : m_conv(0)
+{}
+ 
+IConv::IConv(const std::string& from_charset_, const std::string& to_charset_)
+  : to_charset(to_charset_),
+    from_charset(from_charset_),
+    m_conv(0)
+{
+  // Create the converter.
+  if(!(m_conv = iconv_open(to_charset.c_str(), from_charset.c_str())))
+    {
+      if(errno == EINVAL)
+        {
+          std::ostringstream sstr;
+          sstr << "iconv: unsupported conversion: " << from_charset
+               << " => " << to_charset << "!";
+          throw std::runtime_error(sstr.str());
+        }
+      else
+        {
+          throw std::runtime_error(strerror(errno));
+        }
+      std::cout << "iconv: omething when very wrong" << std::endl;
+      exit(1);
+    }
+}
+ 
+IConv::~IConv()
+{
+  close();
+}
+ 
+void
+IConv::close()
+{
+  // Free, if exists.
+  if(m_conv)
+    {
+      iconv_close(m_conv);
+      m_conv = 0;
+    }
+}
+ 
+/// Convert a string from encoding to another.
+std::string
+IConv::convert(std::string text)
+{
+  if(!m_conv) return text;
+ 
+  size_t in_size = text.size();
+  size_t out_size = 4*in_size; // Worst case scenario: ASCII -> UTF-32?
+  std::string result(out_size, ' ');
+  ICONV_CONST char* in_str  = &text[0];
+  char* out_str = &result[0];
+ 
+  // Try to convert the text.
+  if(iconv(m_conv, &in_str, &in_size, &out_str, &out_size) != 0) {
+    std::cout << "TinyGetText: text: \"" << text << "\"" << std::endl;
+    std::cout << "TinyGetText: Error while converting (" 
+              << from_charset << " -> " << to_charset 
+              << "): " << strerror(errno) << std::endl;
+    exit(1);
+  }
+  // Eat off the spare space.
+  result.resize(out_str - &result[0]);
+  return result;
+}
+
+/** Convert \a which is in \a from_charset to \a to_charset and return it */
+std::string
+IConv::convert(const std::string& text,
+               const std::string& from_charset,
+               const std::string& to_charset)           
+{
+  if (from_charset == to_charset)
+    return text;
+
+  IConv* c = new IConv(from_charset, to_charset);
+  std::string ret = c->convert(text);
+  c->close();
+  return ret;
+}
+/*
+  iconv_t cd = iconv_open(to_charset.c_str(), from_charset.c_str());
+  
+  size_t in_len  = text.length();
+  size_t out_len = text.length()*4; // Should be large enough to hold UTF-32
+
+  char*  out_orig = new char[out_len]; // FIXME: cross fingers that this is 
enough
+  char*  in_orig  = new char[in_len+1];
+  strcpy(in_orig, text.c_str());
+
+  char* out = out_orig;
+  const char* in  = in_orig;
+
+  //std::cout << "IN: " << (int)in << " " << in_len << " " << (int)out << " " 
<< out_len << std::endl;
+  int retval = iconv(cd, &in, &in_len, &out, &out_len);
+  //std::cout << "OUT: " << (int)in << " " << in_len << " " << (int)out << " " 
<< out_len << std::endl;
+
+  if (retval != 0)
+    {
+      std::cerr << strerror(errno) << std::endl;
+      std::cerr << "Error: conversion from " << from_charset
+                << " to " << to_charset << " went wrong: " << retval << 
std::endl;
+    }
+  iconv_close(cd);
+
+  
+    <dolphin> your code is also buggy
+<dolphin> there will be extra spaces at the end of the string
+<dolphin> the lenght of the final string should be: out_str - out_orig
+<dolphin> or: out_size_before_iconv_call - out_size_after_iconv_call
+   
+  std::string ret(out_orig, out_len);
+  delete[] out_orig;
+  delete[] in_orig;
+  return ret;
+}
+*/
+
+} // namespace TinyGetText
+
+/* EOF */


Property changes on: branches/pingus_sdl/src/tinygettext/iconv.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: branches/pingus_sdl/src/tinygettext/iconv.hpp
===================================================================
--- branches/pingus_sdl/src/tinygettext/iconv.hpp       2007-08-17 04:33:30 UTC 
(rev 2982)
+++ branches/pingus_sdl/src/tinygettext/iconv.hpp       2007-08-17 14:38:08 UTC 
(rev 2983)
@@ -0,0 +1,52 @@
+//  $Id$
+// 
+//  TinyGetText - A small flexible gettext() replacement
+//  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+//
+//  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_ICONV_HPP
+#define HEADER_ICONV_HPP
+
+#include <string>
+
+namespace TinyGetText {
+
+class IConv
+{
+public:
+  std::string to_charset;
+  std::string from_charset;
+  iconv_t m_conv;
+
+  IConv();
+  IConv(const std::string& fromcode, const std::string& tocode);
+  ~IConv();
+
+  void close();
+ 
+  /// Convert a string from encoding to another.
+  std::string convert(std::string text);
+
+  static std::string convert(const std::string& text,
+                             const std::string& from_charset,
+                             const std::string& to_charset);
+};
+
+} // namespace TinyGetText
+
+#endif
+
+/* EOF */


Property changes on: branches/pingus_sdl/src/tinygettext/iconv.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: branches/pingus_sdl/src/tinygettext/po_file_reader.cpp
===================================================================
--- branches/pingus_sdl/src/tinygettext/po_file_reader.cpp      2007-08-17 
04:33:30 UTC (rev 2982)
+++ branches/pingus_sdl/src/tinygettext/po_file_reader.cpp      2007-08-17 
14:38:08 UTC (rev 2983)
@@ -23,6 +23,7 @@
 #include <errno.h>
 #include <sstream>
 #include <stdexcept>
+#include "iconv.hpp"
 #include "po_file_reader.hpp"
 
 namespace TinyGetText {
@@ -35,139 +36,6 @@
     return lhs.compare(0, rhs.length(), rhs) == 0;
 }
 
-
-class charconv
-{
-public:
-  std::string incharset;
-  std::string outcharset;
-
-       charconv() : m_conv(0)
-       {}
- 
-       charconv(const std::string& incharset_, const std::string& outcharset_)
-          : incharset(incharset_),
-            outcharset(outcharset_),
-            m_conv(0)
-       {
-               create(incharset, outcharset);
-       }
- 
-       ~charconv()
-       {
-               close();
-       }
- 
-       void create(const std::string& incharset, const std::string& outcharset)
-       {
-               // Create the converter.
-               if(!(m_conv = iconv_open(incharset.c_str(), 
outcharset.c_str())))
-               {
-                       if(errno == EINVAL)
-                          {
-                            std::ostringstream sstr;
-                            sstr << "Unsupported conversion: " << incharset
-                                 << " => " << outcharset << "!";
-                            throw std::runtime_error(sstr.str());
-                          }
-                       else
-                          {
-                            throw std::runtime_error(strerror(errno));
-                          }
-                        std::cout << "Something when very wrong" << std::endl;
-                       exit(1);
-               }
-       }
- 
-       void close()
-       {
-               // Free, if exists.
-               if(m_conv)
-               {
-                       iconv_close(m_conv);
-                       m_conv = 0;
-               }
-       }
- 
-       /// Convert a string from encoding to another.
-       std::string convert(std::string text)
-       {
-               if(!m_conv) return text;
- 
-               size_t in_size = text.size();
-               size_t out_size = 4*in_size; // Worst case scenario: ASCII -> 
UTF-32?
-               std::string result(out_size, ' ');
-                ICONV_CONST char* in_str  = &text[0];
-               char* out_str = &result[0];
- 
-               // Try to convert the text.
-               if(iconv(m_conv, &in_str, &in_size, &out_str, &out_size) != 0) {
-                  std::cout << "TinyGetText: text: \"" << text << "\"" << 
std::endl;
-                  std::cout << "TinyGetText: Error while converting (" 
-                            << incharset << " -> " << outcharset 
-                            << "): " << strerror(errno) << std::endl;
-                  exit(1);
-                }
-               // Eat off the spare space.
-               result.resize(out_str - &result[0]);
-               return result;
-       }
-protected:
-       iconv_t m_conv;
-};
-
-
-/** Convert \a which is in \a from_charset to \a to_charset and return it */
-std::string convert(const std::string& text,
-                    const std::string& from_charset,
-                    const std::string& to_charset)           
-{
-  if (from_charset == to_charset)
-    return text;
-
-  charconv *cc = new charconv(from_charset, to_charset);
-  std::string ret = cc->convert(text);
-  cc->close();
-  return ret;
-}
-/*
-  iconv_t cd = iconv_open(to_charset.c_str(), from_charset.c_str());
-  
-  size_t in_len  = text.length();
-  size_t out_len = text.length()*4; // Should be large enough to hold UTF-32
-
-  char*  out_orig = new char[out_len]; // FIXME: cross fingers that this is 
enough
-  char*  in_orig  = new char[in_len+1];
-  strcpy(in_orig, text.c_str());
-
-  char* out = out_orig;
-  const char* in  = in_orig;
-
-  //std::cout << "IN: " << (int)in << " " << in_len << " " << (int)out << " " 
<< out_len << std::endl;
-  int retval = iconv(cd, &in, &in_len, &out, &out_len);
-  //std::cout << "OUT: " << (int)in << " " << in_len << " " << (int)out << " " 
<< out_len << std::endl;
-
-  if (retval != 0)
-    {
-      std::cerr << strerror(errno) << std::endl;
-      std::cerr << "Error: conversion from " << from_charset
-                << " to " << to_charset << " went wrong: " << retval << 
std::endl;
-    }
-  iconv_close(cd);
-
-  
-    <dolphin> your code is also buggy
-<dolphin> there will be extra spaces at the end of the string
-<dolphin> the lenght of the final string should be: out_str - out_orig
-<dolphin> or: out_size_before_iconv_call - out_size_after_iconv_call
-   
-  std::string ret(out_orig, out_len);
-  delete[] out_orig;
-  delete[] in_orig;
-  return ret;
-}
-*/
-
 POFileReader::POFileReader(std::istream& in, Dictionary& dict_)
   : dict(dict_)
 {
@@ -258,7 +126,8 @@
             }
           else
             {
-              dict.add_translation(current_msgid, convert(token.content, 
from_charset, to_charset));
+              dict.add_translation(current_msgid, 
+                                   IConv::convert(token.content, from_charset, 
to_charset));
             }
           state = WANT_MSGID;
         } 
@@ -279,7 +148,7 @@
             } 
           else 
             {
-              msgstr_plural[num] = convert(token.content, from_charset, 
to_charset);
+              msgstr_plural[num] = IConv::convert(token.content, from_charset, 
to_charset);
             }
         }
       else 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]