From 4f8dd4cb0f017323688f9bb7bcf30fdc407e920b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 Oct 2018 20:47:23 +0200 Subject: [PATCH] checker is going to use locales, fix them up, too. --- src/CMakeLists.txt | 2 +- src/bind_eressea.c | 2 +- src/checker.c | 26 ++++++++++++++++++++++++++ src/kernel/config.c | 1 + src/platform.h | 7 ------- src/util/language.c | 15 +++------------ src/util/language.h | 4 ++-- src/util/log.c | 3 ++- src/util/path.h | 6 ++++++ 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8bb751258..4e8db8bf9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -186,6 +186,7 @@ endif() add_library(version STATIC ${VERSION_SRC}) add_library(parser ${PARSER_SRC}) target_link_libraries(parser + ${CLIBS_LIBRARIES} ${CRYPTO_LIBRARIES} ) @@ -205,7 +206,6 @@ target_link_libraries(eressea ${TOLUA_LIBRARIES} ${LUA_LIBRARIES} ${STORAGE_LIBRARIES} - ${CLIBS_LIBRARIES} ${CJSON_LIBRARIES} ${INIPARSER_LIBRARIES} ) diff --git a/src/bind_eressea.c b/src/bind_eressea.c index e5acbac99..4d3918899 100755 --- a/src/bind_eressea.c +++ b/src/bind_eressea.c @@ -22,7 +22,7 @@ void eressea_free_game(void) { free_gamedata(); init_resources(); - init_locales(); + init_locales(init_locale); } int eressea_read_game(const char * filename) { diff --git a/src/checker.c b/src/checker.c index 4138a372a..a2c29dd7c 100644 --- a/src/checker.c +++ b/src/checker.c @@ -3,9 +3,14 @@ #endif #include "util/order_parser.h" +#include "util/keyword.h" +#include "util/language.h" +#include "util/path.h" +#include "util/pofile.h" #include #include +#include typedef struct parser_state { FILE * F; @@ -47,6 +52,26 @@ int parsefile(FILE *F) { return err; } +static int handle_po(const char *msgid, const char *msgstr, const char *msgctxt, void *data) { + struct locale *lang = (struct locale *)data; + if (msgctxt) { + if (strcmp(msgctxt, "keyword") == 0) { + keyword_t kwd = findkeyword(msgid); + init_keyword(lang, kwd, msgstr); + locale_setstring(lang, mkname("keyword", keywords[kwd]), msgstr); + } + } + return 0; +} + +static void read_config(const char *respath) { + char path[PATH_MAX]; + struct locale *lang; + lang = get_or_create_locale("de"); + path_join(respath, "translations/strings.de.po", path, sizeof(path)); + pofile_read(path, handle_po, lang); +} + int main(int argc, char **argv) { FILE * F = stdin; if (argc > 1) { @@ -57,6 +82,7 @@ int main(int argc, char **argv) { return -1; } } + read_config("../git"); parsefile(F); if (F != stdin) { fclose(F); diff --git a/src/kernel/config.c b/src/kernel/config.c index 75601e831..15387dca7 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -239,6 +239,7 @@ static void init_magic(struct locale *lang) free(sstr); } } + void init_locale(struct locale *lang) { init_magic(lang); diff --git a/src/platform.h b/src/platform.h index fdc3760f9..7b52782e3 100644 --- a/src/platform.h +++ b/src/platform.h @@ -4,8 +4,6 @@ #define _LP64 0 /* fix a warning in pdcurses 3.4 */ #endif -#ifdef _MSC_VER - /* @see https://developercommunity.visualstudio.com/content/problem/69874/warning-c4001-in-standard-library-stringh-header.html */ #if _MSC_VER >= 1900 #pragma warning(disable: 4710 4820 4001) @@ -17,10 +15,5 @@ #pragma warning(disable: 4214) // bit field types other than int #endif -/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */ -#define PATH_MAX 260 - -#endif - #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/src/util/language.c b/src/util/language.c index 77a7d2a4e..afc9d01d0 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -353,29 +353,20 @@ void *get_translation(const struct locale *lang, const char *str, int index) { return NULL; } -void locale_foreach(void(*callback)(const struct locale *, const char *)) { - const locale * lang; - for (lang = locales; lang; lang = lang->next) { - callback(lang, lang->name); - } -} - const char *localenames[] = { "de", "en", NULL }; -extern void init_locale(struct locale *lang); - static int locale_init = 0; -void init_locales(void) +void init_locales(locale_handler init) { locale * lang; if (locale_init) return; assert(locales); - for (lang = locales; lang; lang = lang->next) { - init_locale(lang); + for (lang = locales; lang; lang = nextlocale(lang)) { + init(lang); } locale_init = 1; } diff --git a/src/util/language.h b/src/util/language.h index f269a5f06..735fd4a95 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -39,7 +39,8 @@ extern "C" { /** managing multiple locales: **/ struct locale *get_locale(const char *name); struct locale *get_or_create_locale(const char *key); - void init_locales(void); + typedef void(*locale_handler)(struct locale *lang); + void init_locales(locale_handler callback); void free_locales(void); void reset_locales(void); @@ -57,7 +58,6 @@ extern "C" { void make_locales(const char *str); - void locale_foreach(void(*callback)(const struct locale *lang, const char *name)); void po_write_msg(FILE *F, const char *id, const char *str, const char *ctxt); #define LOC(lang, s) (lang?locale_string(lang, s, true):s) diff --git a/src/util/log.c b/src/util/log.c index 4b29332a8..b8549d60e 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -12,8 +12,9 @@ without prior permission by the authors of Eressea. #include #include "log.h" -#include "unicode.h" +#include "path.h" #include "strings.h" +#include "unicode.h" #include #include diff --git a/src/util/path.h b/src/util/path.h index 5a4e22270..649777171 100644 --- a/src/util/path.h +++ b/src/util/path.h @@ -1,4 +1,10 @@ +#pragma once #include +#ifdef _MSC_VER +/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */ +#define PATH_MAX 260 +#endif + char * path_join(const char *p1, const char *p2, char *dst, size_t len);