From bc20e9c433c1c7bd2a9516a936d1d7ffee1e90f2 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sat, 13 Jun 2009 17:18:06 +0000 Subject: localization update --- src/game/localization.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/game/localization.cpp') diff --git a/src/game/localization.cpp b/src/game/localization.cpp index cfc659f5..58ec539c 100644 --- a/src/game/localization.cpp +++ b/src/game/localization.cpp @@ -1,6 +1,10 @@ #include "localization.hpp" +extern "C" { +#include +} + static unsigned str_hash(const char *str) { unsigned hash = 5381; @@ -43,8 +47,48 @@ void LOCALIZATIONDATABASE::add_string(const char *org_str, const char *new_str) s.hash = str_hash(org_str); s.replacement = new_str; strings.add(s); +} + +bool LOCALIZATIONDATABASE::load(const char *filename) +{ + LINEREADER lr; + IOHANDLE io = io_open(filename, IOFLAG_READ); + if(!io) + return false; + + dbg_msg("localization", "loaded '%s'", filename); + strings.clear(); + + linereader_init(&lr, io); + char *line; + while((line = linereader_get(&lr))) + { + if(!str_length(line)) + continue; + + if(line[0] == '#') // skip comments + continue; + + char *replacement = linereader_get(&lr); + if(!replacement) + { + dbg_msg("", "unexpected end of file"); + break; + } + + if(replacement[0] != '=' || replacement[1] != '=' || replacement[2] != ' ') + { + dbg_msg("", "malform replacement line for '%s'", line); + continue; + } + + replacement += 3; + localization.add_string(line, replacement); + } + current_version++; + return true; } const char *LOCALIZATIONDATABASE::find_string(unsigned hash) -- cgit 1.4.1