From b252de2ab611cdef2ff3cb11e835a43f37da7c5a Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 7 Jul 2004 22:47:06 +0000 Subject: [PATCH] Fixed the translating of the shown text files. SVN-Revision: 1538 --- src/lispreader.cpp | 4 ++-- src/screen/font.cpp | 40 +++++++++++++++++++++++----------------- src/screen/font.h | 2 ++ 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/lispreader.cpp b/src/lispreader.cpp index 58e184cfe..0c52260a7 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -44,7 +44,7 @@ #define TOKEN_FALSE 10 -#define MAX_TOKEN_LENGTH 1024 +#define MAX_TOKEN_LENGTH 4096 static char token_string[MAX_TOKEN_LENGTH + 1] = ""; static int token_length = 0; @@ -1208,7 +1208,7 @@ LispReader::read_char_vector (const char* name, std::vector& vec) bool LispReader::read_string (const char* name, std::string& str) { - char str_[1204]; + char str_[1024]; sprintf(str_, "%s-%s", name, getenv("LANG")); lisp_object_t* obj = search_for (str_); diff --git a/src/screen/font.cpp b/src/screen/font.cpp index d414e1fc8..decdc6595 100644 --- a/src/screen/font.cpp +++ b/src/screen/font.cpp @@ -141,33 +141,39 @@ void display_text_file(const std::string& file, Surface* surface, float scroll_s { std::string text; std::vector names; - - 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) - { - LispReader reader(lisp_cdr(root_obj)); - reader.read_string("text", text); - } - else + LispReader* reader = LispReader::load(datadir + "/" + file, "supertux-text"); + + if(!reader) { - std::cerr << "Error: Could not open text. Ignoring...\n"; - return; + std::cerr << "Error: Could not open text. Ignoring...\n"; + return; } - unsigned int l, i; - l = 0; + + reader->read_string("text", text); + delete reader; + + names.clear(); + unsigned int i, l; + i = 0; while(true) { - i = l; l = text.find("\n", i); - if(l != std::string::npos) + + if(l == std::string::npos) + { + char temp[1024]; + temp[text.copy(temp, text.size() - i, i)] = '\0'; + names.push_back(temp); break; + } - char* temp = 0; - text.copy(temp, l, i); + char temp[1024]; + temp[text.copy(temp, l-i, i)] = '\0'; names.push_back(temp); + + i = l+1; } int done = 0; diff --git a/src/screen/font.h b/src/screen/font.h index 369410b60..68681f18c 100644 --- a/src/screen/font.h +++ b/src/screen/font.h @@ -26,6 +26,8 @@ #include "surface.h" #include "vector.h" +/** Reads a text file (using LispReader, so it as to be in its formatting) + and displays it in a StarTrek fashion */ void display_text_file(const std::string& file, const std::string& surface, float scroll_speed); void display_text_file(const std::string& file, Surface* surface, float scroll_speed); -- 2.11.0