From 42c3f607730c5e24f5e9648cde2b66f5c9b59c59 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 16 Mar 2021 18:16:48 -0400 Subject: db_games_find(): Match name and description lang TODO: Make this matching less strict. --- diff --git a/configure.ac b/configure.ac index d98283d..64384b3 100644 --- a/configure.ac +++ b/configure.ac @@ -37,7 +37,7 @@ funcs_missing=false AC_CHECK_FUNCS( [\ alphasort calloc dirname free isspace malloc printf putchar \ - realpath scandir sscanf strcmp strdup strndup vprintf + realpath scandir sscanf strcasecmp strcmp strdup strndup vprintf ], [], [funcs_missing=true]) diff --git a/src/game.c b/src/game.c index 0103332..791abe7 100644 --- a/src/game.c +++ b/src/game.c @@ -23,6 +23,7 @@ #include #include #include "game.h" +#include "locale.h" #include "output.h" #include "xml.h" @@ -214,6 +215,7 @@ _db_game_xml_game_el_start(void *pv, const char *name, const char **attr) XML_Parser p; struct db_game *game; char *lang; + char *lc_messages; db_dbg(" <%s> (game child)", name); @@ -226,26 +228,48 @@ _db_game_xml_game_el_start(void *pv, const char *name, const char **attr) if (lang == NULL) { return; } - db_dbg(" lang=\"%s\"", lang); + lc_messages = strdup(db_lc_messages_get()); + db_dbg(" lang=\"%s\" (looking for \"%s\")", + lang, lc_messages); + if (strcasecmp(lang, lc_messages) == 0) { + goto name_ok; + } + db_xml_node_push(p, game, _db_game_xml_invalid_start, + _db_game_xml_name_end, + NULL); + goto name_err; + name_ok: game->xml_parsing = DB_GAME_XML_PARSING_NAME; - /* TODO */ - free(lang); db_xml_node_push(p, game, _db_game_xml_invalid_start, _db_game_xml_name_end, _db_game_xml_cdata); + name_err: + free(lang); + free(lc_messages); } else if (db_xml_check_tag(name, "description")) { lang = NULL; db_xml_get_string_attr(p, attr, "lang", &lang, 1); if (lang == NULL) { return; } - db_dbg(" lang=\"%s\"", lang); + lc_messages = strdup(db_lc_messages_get()); + db_dbg(" lang=\"%s\" (looking for \"%s\")", + lang, lc_messages); + if (strcasecmp(lang, lc_messages) == 0) { + goto desc_ok; + } + db_xml_node_push(p, game, _db_game_xml_invalid_start, + _db_game_xml_description_end, + NULL); + goto desc_err; + desc_ok: game->xml_parsing = DB_GAME_XML_PARSING_DESCRIPTION; - /* TODO */ - free(lang); db_xml_node_push(p, game, _db_game_xml_invalid_start, _db_game_xml_description_end, _db_game_xml_cdata); + desc_err: + free(lang); + free(lc_messages); } else if (db_xml_check_tag(name, "levels")) { db_xml_node_push(p, game, _db_game_xml_levels_el_start, _db_game_xml_levels_end, NULL); -- cgit v0.9.1