Improved stay-on-platform code to handle non-32x32 badguys. Implemented s-o-p for...
[supertux.git] / src / lisp / parser.cpp
index cd74886..54af44f 100644 (file)
 #include <cassert>
 #include <iostream>
 
-#include "tinygettext/tinygettext.h"
-#include "parser.h"
-#include "lisp.h"
-#include "file_system.h"
+#include "tinygettext/tinygettext.hpp"
+#include "physfs/physfs_stream.hpp"
+#include "parser.hpp"
+#include "lisp.hpp"
 
 namespace lisp
 {
@@ -38,7 +38,7 @@ Parser::Parser(bool translate)
 {
   if(translate) {
     dictionary_manager = new TinyGetText::DictionaryManager();
-    dictionary_manager->set_charset("ISO8859-1");
+    dictionary_manager->set_charset("UTF-8");
   }
 }
 
@@ -48,10 +48,19 @@ Parser::~Parser()
   delete dictionary_manager;
 }
 
+static std::string dirname(std::string filename)
+{
+  std::string::size_type p = filename.find_last_of('/');
+  if(p == std::string::npos)
+    return "";
+
+  return filename.substr(0, p+1);
+}
+
 Lisp*
 Parser::parse(const std::string& filename)
 {
-  std::ifstream in(filename.c_str());
+  IFileStream in(filename);
   if(!in.good()) {
     std::stringstream msg;
     msg << "Parser problem: Couldn't open file '" << filename << "'.";
@@ -59,7 +68,7 @@ Parser::parse(const std::string& filename)
   }
 
   if(dictionary_manager) {
-    dictionary_manager->add_directory(FileSystem::dirname(filename));
+    dictionary_manager->add_directory(dirname(filename));
     dictionary = & (dictionary_manager->get_dictionary());
   }
   
@@ -115,7 +124,7 @@ Parser::read()
         // evaluate translation function (_ str) in place here
         token = lexer->getNextToken();
         if(token != Lexer::TOKEN_STRING)
-          throw new std::runtime_error("Expected string after '(_'");
+          throw std::runtime_error("Expected string after '(_'");
         
         result = new Lisp(Lisp::TYPE_STRING);
         if(dictionary) {
@@ -129,7 +138,7 @@ Parser::read()
         }
         token = lexer->getNextToken();
         if(token != Lexer::TOKEN_CLOSE_PAREN)
-          throw new std::runtime_error("Expected ')' after '(_ string'");
+          throw std::runtime_error("Expected ')' after '(_ string'");
         break;
       }