From e99d667f6b4fd64c4ac422a3945374306c7f3363 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 7 Jul 2004 19:19:19 +0000 Subject: [PATCH] =?utf8?q?Added=20support=20for=20data=20files=20internati?= =?utf8?q?onalization=20by=20a=20simple=203=20lines=20code=20in=20lispread?= =?utf8?q?er's=20read=5Fstring().=20To=20translate=20a=20level's=20title?= =?utf8?q?=20to=20European=20Portuguese,=20I=20would=20look=20at:=20(title?= =?utf8?q?=20"Hello=20World!")=20and=20add:=20(title-pt=5FPT=20"Ol?= =?utf8?q?=EF=BF=BD=20Mundo!")?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also, made display_text_file() using lispreader (to make it i18n too). Unfortunately, there is a crash of lisp_reader in my system (not related), so I wasn't able to give it a try. data/*.txt files also need updating to work. Else, it should just skip it, without crashing. SVN-Revision: 1537 --- src/lispreader.cpp | 8 +++++++- src/screen/font.cpp | 49 +++++++++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/lispreader.cpp b/src/lispreader.cpp index 3750b1cf5..58e184cfe 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -1208,7 +1208,13 @@ LispReader::read_char_vector (const char* name, std::vector& vec) bool LispReader::read_string (const char* name, std::string& str) { - lisp_object_t* obj = search_for (name); + char str_[1204]; + sprintf(str_, "%s-%s", name, getenv("LANG")); + lisp_object_t* obj = search_for (str_); + + if(!obj) + obj = search_for (name); + if (!obj) return false; diff --git a/src/screen/font.cpp b/src/screen/font.cpp index 4ea0469f5..d414e1fc8 100644 --- a/src/screen/font.cpp +++ b/src/screen/font.cpp @@ -26,6 +26,7 @@ #include "screen.h" #include "font.h" #include "drawing_context.h" +#include "../lispreader.h" Font::Font(const std::string& file, FontType ntype, int nw, int nh, int nshadowsize) @@ -138,36 +139,40 @@ void display_text_file(const std::string& file, const std::string& surface, floa void display_text_file(const std::string& file, Surface* surface, float scroll_speed) { - int done; - float scroll; - float speed; - FILE* fi; - char temp[1024]; + std::string text; std::vector names; - char filename[1024]; - sprintf(filename,"%s/%s", datadir.c_str(), file.c_str()); - if((fi = fopen(filename,"r")) != NULL) + lisp_object_t* root_obj = lisp_read_from_file(datadir + file); + lisp_object_t* cur = lisp_car(root_obj); + + if (lisp_symbol_p(cur) && strcmp(lisp_symbol(cur), "text") == 0) { - while(fgets(temp, sizeof(temp), fi) != NULL) - { - temp[strlen(temp)-1]='\0'; - names.push_back(temp); - } - fclose(fi); + LispReader reader(lisp_cdr(root_obj)); + reader.read_string("text", text); } else { - names.push_back("File was not found!"); - names.push_back(filename); - names.push_back("Shame on the guy, who"); - names.push_back("forgot to include it"); - names.push_back("in your SuperTux distribution."); + std::cerr << "Error: Could not open text. Ignoring...\n"; + return; + } + + unsigned int l, i; + l = 0; + while(true) + { + i = l; + l = text.find("\n", i); + if(l != std::string::npos) + break; + + char* temp = 0; + text.copy(temp, l, i); + names.push_back(temp); } - scroll = 0; - speed = scroll_speed / 50; - done = 0; + int done = 0; + float scroll = 0; + float speed = scroll_speed / 50; DrawingContext context; SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); -- 2.11.0