Messaging subsystem rewrite, step I
[supertux.git] / src / tinygettext / tinygettext.cpp
index b31cf2f..424e97c 100644 (file)
@@ -26,7 +26,9 @@
 #include <errno.h>
 
 #include "tinygettext.hpp"
+#include "msg.hpp"
 #include "physfs/physfs_stream.hpp"
+#include "msg.hpp"
 
 //#define TRANSLATION_DEBUG
 
@@ -58,9 +60,8 @@ std::string convert(const std::string& text,
   out_len -= out_len_temp; // see above
   if (retval == (size_t) -1)
     {
-      std::cerr << strerror(errno) << std::endl;
-      std::cerr << "Error: conversion from " << from_charset
-                << " to " << to_charset << " went wrong: " << retval << std::endl;
+      msg_warning << strerror(errno) << std::endl;
+      msg_warning << "Error: conversion from " << from_charset << " to " << to_charset << " went wrong: " << retval << std::endl;
       return "";
     }
   iconv_close(cd);
@@ -236,7 +237,7 @@ DictionaryManager::get_dictionary(const std::string& spec)
     }
   else // Dictionary for languages lang isn't loaded, so we load it
     {
-      //std::cout << "get_dictionary: " << lang << std::endl;
+      //msg_debug << "get_dictionary: " << lang << std::endl;
       Dictionary& dict = dictionaries[lang];
 
       dict.set_language(get_language_def(lang));
@@ -248,7 +249,7 @@ DictionaryManager::get_dictionary(const std::string& spec)
           char** files = PHYSFS_enumerateFiles(p->c_str());
           if(!files) 
             {
-              std::cerr << "Error: enumerateFiles() failed on " << *p << std::endl;
+              msg_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
             }
           else
             {
@@ -260,8 +261,8 @@ DictionaryManager::get_dictionary(const std::string& spec)
                       IFileStream in(pofile);
                       read_po_file(dict, in);
                   } catch(std::exception& e) {
-                      std::cerr << "Error: Failure file opening: " << pofile << std::endl;
-                      std::cerr << e.what() << "\n";
+                      msg_warning << "Error: Failure file opening: " << pofile << std::endl;
+                      msg_warning << e.what() << "" << std::endl;
                   }
                 }
               }
@@ -283,7 +284,7 @@ DictionaryManager::get_languages()
       char** files = PHYSFS_enumerateFiles(p->c_str());
       if (!files)
         {
-          std::cerr << "Error: opendir() failed on " << *p << std::endl;
+          msg_warning << "Error: opendir() failed on " << *p << std::endl;
         }
       else
         {
@@ -404,10 +405,10 @@ Dictionary::translate(const std::string& msgid, const std::string& msgid2, int n
   else
     {
 #ifdef TRANSLATION_DEBUG
-      std::cerr << "Warning: Couldn't translate: " << msgid << std::endl;
-      std::cerr << "Candidates: " << std::endl;
+      msg_warning << "Couldn't translate: " << msgid << std::endl;
+      msg_warning << "Candidates: " << std::endl;
       for (PluralEntries::iterator i = plural_entries.begin(); i != plural_entries.end(); ++i)
-        std::cout << "'" << i->first << "'" << std::endl;
+        msg_debug << "'" << i->first << "'" << std::endl;
 #endif
 
       if (plural2_1(num)) // default to english rules
@@ -428,7 +429,7 @@ Dictionary::translate(const char* msgid)
   else
     {
 #ifdef TRANSLATION_DBEUG
-      std::cout << "Error: Couldn't translate: " << msgid << std::endl;
+      msg_warning << "Couldn't translate: " << msgid << std::endl;
 #endif
       return msgid;
     }
@@ -445,7 +446,7 @@ Dictionary::translate(const std::string& msgid)
   else
     {
 #ifdef TRANSLATION_DBEUG
-      std::cout << "Error: Couldn't translate: " << msgid << std::endl;
+      msg_warning << "Couldn't translate: " << msgid << std::endl;
 #endif
       return msgid;
     }
@@ -529,7 +530,7 @@ public:
 
     if (from_charset.empty() || from_charset == "CHARSET")
       {
-        std::cerr << "Error: Charset not specified for .po, fallback to ISO-8859-1" << std::endl;
+        msg_warning << "Error: Charset not specified for .po, fallback to ISO-8859-1" << std::endl;
         from_charset = "ISO-8859-1";
       }
 
@@ -553,12 +554,11 @@ public:
           }
         else if (token.keyword.empty())
           {
-            //std::cerr << "Got EOF, everything looks ok." << std::endl;
+            //msg_warning << "Got EOF, everything looks ok." << std::endl;
           }
         else
           {
-            std::cerr << "tinygettext: expected 'msgid' keyword, got " << token.keyword 
-                      << " at line " << line_num << std::endl;
+            msg_warning << "tinygettext: expected 'msgid' keyword, got " << token.keyword << " at line " << line_num << std::endl;
           }
         break;
     
@@ -590,8 +590,7 @@ public:
           } 
         else
           {
-            std::cerr << "tinygettext: expected 'msgstr' keyword, got " << token.keyword 
-                      << " at line " << line_num << std::endl;
+            msg_warning << "tinygettext: expected 'msgstr' keyword, got " << token.keyword << " at line " << line_num << std::endl;
           }
         break;
 
@@ -601,7 +600,7 @@ public:
             int num;
             if (sscanf(token.keyword.c_str(), "msgstr[%d]", &num) != 1) 
               {
-                std::cerr << "Error: Couldn't parse: " << token.keyword << std::endl;
+                msg_warning << "Error: Couldn't parse: " << token.keyword << std::endl;
               } 
             else 
               {
@@ -640,7 +639,7 @@ public:
 
     while((c = getchar(in)) != EOF)
       {
-        //std::cout << "Lexing char: " << char(c) << " " << state << std::endl;
+        //msg_debug << "Lexing char: " << char(c) << " " << state << std::endl;
         switch(state)
           {
           case READ_KEYWORD:
@@ -691,12 +690,12 @@ public:
                   else if (c == '"') token.content += '"';
                   else
                     {
-                      std::cout << "Unhandled escape character: " << char(c) << std::endl;
+                      msg_warning << "Unhandled escape character: " << char(c) << std::endl;
                     }
                 }
               else
                 {
-                  std::cout << "Unterminated string" << std::endl;
+                  msg_warning << "Unterminated string" << std::endl;
                 }
             } else if (c == '"') { // Content string is terminated
               state = READ_CONTENT;