#303: Typo fixes from mathnerd314
[supertux.git] / src / tinygettext / tinygettext.cpp
index d2df1e5..41e94b4 100644 (file)
@@ -31,8 +31,6 @@
 #include "tinygettext.hpp"
 #include "log.hpp"
 #include "physfs/physfs_stream.hpp"
-#include <unison/vfs/FileSystem.hpp>
-#include "log.hpp"
 #include "findlocale.hpp"
 
 //#define TRANSLATION_DEBUG
@@ -225,7 +223,7 @@ DictionaryManager::parseLocaleAliases()
 
   char c = ' ';
   while(in.good() && !in.eof()) {
-    while(isspace(c) && !in.eof())
+    while(isspace(static_cast<unsigned char>(c)) && !in.eof())
       in.get(c);
 
     if(c == '#') { // skip comments
@@ -235,14 +233,14 @@ DictionaryManager::parseLocaleAliases()
     }
 
     std::string alias;
-    while(!isspace(c) && !in.eof()) {
+    while(!isspace(static_cast<unsigned char>(c)) && !in.eof()) {
       alias += c;
       in.get(c);
     }
-    while(isspace(c) && !in.eof())
+    while(isspace(static_cast<unsigned char>(c)) && !in.eof())
       in.get(c);
     std::string language;
-    while(!isspace(c) && !in.eof()) {
+    while(!isspace(static_cast<unsigned char>(c)) && !in.eof()) {
       language += c;
       in.get(c);
     }
@@ -265,99 +263,65 @@ DictionaryManager::get_dictionary(const std::string& spec)
 
   Dictionaries::iterator i = dictionaries.find(get_language_from_spec(lang));
   if (i != dictionaries.end())
-  {
-    return i->second;
-  }
+    {
+      return i->second;
+    }
   else // Dictionary for languages lang isn't loaded, so we load it
-  {
-    //log_debug << "get_dictionary: " << lang << std::endl;
-    Dictionary& dict = dictionaries[lang];
-
-    dict.set_language(get_language_def(lang));
-    if(charset != "")
-      dict.set_charset(charset);
-
-    for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
     {
-      std::vector<std::string> files = Unison::VFS::FileSystem::get().ls(*p);
-      for(std::vector<std::string>::iterator iter = files.begin();iter != files.end();++iter)
-      {
-        // check if filename matches requested language
-        std::string fname = *iter;
-        std::string load_from_file = "";
-        if(fname == lang + ".po") {
-          load_from_file = fname;
-        } else {
-          std::string::size_type s = lang.find("_");
-          if(s != std::string::npos) {
-            std::string lang_short = std::string(lang, 0, s);
-            if (fname == lang_short + ".po") {
-              load_from_file = lang_short;
-            }
-          }
-        }
+      //log_debug << "get_dictionary: " << lang << std::endl;
+      Dictionary& dict = dictionaries[lang];
 
-        // if it matched, load dictionary
-        if (load_from_file != "") {
-          //log_debug << "Loading dictionary for language \"" << lang << "\" from \"" << filename << "\"" << std::endl;
-          std::string pofile = *p + "/" + *iter;
-          try {
-            IFileStream in(pofile);
-            read_po_file(dict, in);
-          } catch(std::exception& e) {
-            log_warning << "Error: Failure file opening: " << pofile << std::endl;
-            log_warning << e.what() << "" << std::endl;
-          }
-        }
-      }
+      dict.set_language(get_language_def(lang));
+      if(charset != "")
+        dict.set_charset(charset);
 
-#if 0
-      char** files = PHYSFS_enumerateFiles(p->c_str());
-      if(!files)
-      {
-        log_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
-      }
-      else
-      {
-        for(const char* const* filename = files;
-        *filename != 0; filename++) {
-
-        // check if filename matches requested language
-        std::string fname = std::string(*filename);
-        std::string load_from_file = "";
-        if(fname == lang + ".po") {
-          load_from_file = fname;
-        } else {
-          std::string::size_type s = lang.find("_");
-          if(s != std::string::npos) {
-            std::string lang_short = std::string(lang, 0, s);
-          if (fname == lang_short + ".po") {
-            load_from_file = lang_short;
-          }
-        }
-      }
+      for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
+        {
+          char** files = PHYSFS_enumerateFiles(p->c_str());
+          if(!files)
+            {
+              log_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
+            }
+          else
+            {
+              for(const char* const* filename = files;
+                      *filename != 0; filename++) {
+
+                // check if filename matches requested language
+               std::string fname = std::string(*filename);
+               std::string load_from_file = "";
+                if(fname == lang + ".po") {
+                 load_from_file = fname;
+               } else {
+                  std::string::size_type s = lang.find("_");
+                  if(s != std::string::npos) {
+                    std::string lang_short = std::string(lang, 0, s);
+                   if (fname == lang_short + ".po") {
+                     load_from_file = lang_short;
+                   }
+                  }
+               }
+
+               // if it matched, load dictionary
+               if (load_from_file != "") {
+                  //log_debug << "Loading dictionary for language \"" << lang << "\" from \"" << filename << "\"" << std::endl;
+                  std::string pofile = *p + "/" + *filename;
+                  try {
+                      IFileStream in(pofile);
+                      read_po_file(dict, in);
+                  } catch(std::exception& e) {
+                      log_warning << "Error: Failure file opening: " << pofile << std::endl;
+                      log_warning << e.what() << "" << std::endl;
+                  }
+                }
 
-      // if it matched, load dictionary
-      if (load_from_file != "") {
-        //log_debug << "Loading dictionary for language \"" << lang << "\" from \"" << filename << "\"" << std::endl;
-        std::string pofile = *p + "/" + *filename;
-        try {
-          IFileStream in(pofile);
-          read_po_file(dict, in);
-        } catch(std::exception& e) {
-          log_warning << "Error: Failure file opening: " << pofile << std::endl;
-          log_warning << e.what() << "" << std::endl;
+              }
+              PHYSFS_freeList(files);
+            }
         }
-      }
 
-      }
-      PHYSFS_freeList(files);
-      }
-#endif
+      return dict;
     }
-
-    return dict;
-  }
 }
 
 std::set<std::string>
@@ -367,15 +331,6 @@ DictionaryManager::get_languages()
 
   for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
     {
-      std::vector<std::string> files = Unison::VFS::FileSystem::get().ls(*p);
-      for(std::vector<std::string>::iterator iter = files.begin();iter != files.end();++iter)
-      {
-        if(has_suffix(*iter, ".po")) {
-          std::string filename = *iter;
-          languages.insert(filename.substr(0, filename.length()-3));
-        }
-      }
-#if 0
       char** files = PHYSFS_enumerateFiles(p->c_str());
       if (!files)
         {
@@ -391,7 +346,6 @@ DictionaryManager::get_languages()
           }
           PHYSFS_freeList(files);
         }
-#endif
     }
   return languages;
 }
@@ -535,7 +489,7 @@ Dictionary::translate(const char* msgid)
     }
   else
     {
-#ifdef TRANSLATION_DBEUG
+#ifdef TRANSLATION_DEBUG
       log_warning << "Couldn't translate: " << msgid << std::endl;
 #endif
       return msgid;
@@ -552,7 +506,7 @@ Dictionary::translate(const std::string& msgid)
     }
   else
     {
-#ifdef TRANSLATION_DBEUG
+#ifdef TRANSLATION_DEBUG
       log_warning << "Couldn't translate: " << msgid << std::endl;
 #endif
       return msgid;
@@ -614,7 +568,7 @@ public:
 
   void parse_header(const std::string& header)
   {
-    // Seperate the header in lines
+    // Separate the header in lines
     typedef std::vector<std::string> Lines;
     Lines lines;
 
@@ -754,6 +708,9 @@ public:
               {
                 state = SKIP_COMMENT;
               }
+            else if (c == '\n')
+              {
+              }
             else
               {
                 // Read a new token
@@ -761,7 +718,7 @@ public:
 
                 do { // Read keyword
                   token.keyword += c;
-                } while((c = getchar(in)) != EOF && !isspace(c));
+                } while((c = getchar(in)) != EOF && !isspace(static_cast<unsigned char>(c)));
                 in.unget();
 
                 state = READ_CONTENT;
@@ -775,12 +732,13 @@ public:
                   // Found start of content
                   state = READ_CONTENT_IN_STRING;
                   break;
-                } else if (isspace(c)) {
+                } else if (isspace(static_cast<unsigned char>(c))) {
                   // skip
                 } else { // Read something that may be a keyword
                   in.unget();
                   state = READ_KEYWORD;
                   add_token(token);
+                  token = Token();
                   break;
                 }
               }
@@ -819,6 +777,7 @@ public:
           }
       }
     add_token(token);
+    token = Token();
   }
 };