#include <sstream>
#include <stdexcept>
+#include <tinygettext/tinygettext.hpp>
+#include <physfs.h>
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
-#include "obstack/obstackpp.hpp"
+#include "util/gettext.hpp"
+#include "util/obstackpp.hpp"
#include "physfs/ifile_stream.hpp"
#include "physfs/ifile_streambuf.hpp"
#include "supertux/globals.hpp"
-#include "tinygettext/tinygettext.hpp"
#include "supertux/gameconfig.hpp"
namespace lisp {
Parser::Parser(bool translate) :
- lexer(0),
+ lexer(0),
filename(),
- dictionary_manager(0),
+ dictionary_manager(0),
dictionary(0),
token(),
+ searchpath(),
obst()
{
if(translate) {
dictionary_manager = new tinygettext::DictionaryManager();
dictionary_manager->set_charset("UTF-8");
- if (g_config && (g_config->locale != ""))
- dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale));
+ if (g_config) {
+ if (g_config->locale != "") {
+ dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale));
+ }
+ else if(g_dictionary_manager && g_dictionary_manager->get_language()) {
+ // Language set to auto-detect?
+ dictionary_manager->set_language(g_dictionary_manager->get_language());
+ }
+ }
}
obstack_init(&obst);
+ searchpath = PHYSFS_getSearchPath();
}
Parser::~Parser()
obstack_free(&obst, NULL);
delete lexer;
delete dictionary_manager;
+ PHYSFS_freeList(searchpath);
}
static std::string dirname(const std::string& filename)
}
const Lisp*
-Parser::parse(const std::string& filename)
+Parser::parse(const std::string& filename_)
{
- IFileStreambuf ins(filename);
+ IFileStreambuf ins(filename_);
std::istream in(&ins);
if(!in.good()) {
std::stringstream msg;
- msg << "Parser problem: Couldn't open file '" << filename << "'.";
+ msg << "Parser problem: Couldn't open file '" << filename_ << "'.";
throw std::runtime_error(msg.str());
}
if(dictionary_manager) {
- dictionary_manager->add_directory(dirname(filename));
+ std::string rel_dir = dirname (filename_);
+ for(char** i = searchpath; *i != NULL; i++)
+ {
+ std::string abs_dir = std::string (*i) + PHYSFS_getDirSeparator () + rel_dir;
+ dictionary_manager->add_directory (abs_dir);
+ }
dictionary = & (dictionary_manager->get_dictionary());
}
- return parse(in, filename);
+ return parse(in, filename_);
}
const Lisp*
}
case Lexer::TOKEN_INTEGER:
result = new(obst) Lisp(Lisp::TYPE_INTEGER);
- sscanf(lexer->getString(), "%d", &result->v.integer);
+ result->v.integer = atoi(lexer->getString());
break;
case Lexer::TOKEN_REAL:
result = new(obst) Lisp(Lisp::TYPE_REAL);
- sscanf(lexer->getString(), "%f", &result->v.real);
+ result->v.real = strtof(lexer->getString(), NULL);
break;
case Lexer::TOKEN_TRUE:
result = new(obst) Lisp(Lisp::TYPE_BOOLEAN);
default:
// this should never happen
+ result = NULL;
assert(false);
}