diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2021-03-16 18:16:48 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2021-03-16 18:16:48 (EDT) |
commit | 42c3f607730c5e24f5e9648cde2b66f5c9b59c59 (patch) | |
tree | f7b5d8f797da515cae56498b5da736c3df8c2e75 | |
parent | 4f032d290913d008e06f1ba0cf4e4268711edf28 (diff) | |
download | dodge-balls-42c3f607730c5e24f5e9648cde2b66f5c9b59c59.zip dodge-balls-42c3f607730c5e24f5e9648cde2b66f5c9b59c59.tar.gz dodge-balls-42c3f607730c5e24f5e9648cde2b66f5c9b59c59.tar.bz2 |
db_games_find(): Match name and description lang
TODO: Make this matching less strict.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/game.c | 36 |
2 files changed, 31 insertions, 7 deletions
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]) @@ -23,6 +23,7 @@ #include <stdlib.h> #include <string.h> #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); |