X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=wgt-config-xml.c;fp=wgt-config-xml.c;h=f92ae3aeb9ae4a8cbdff60685a67e7824d3d3a97;hb=381842f4c264e5946ad964f43608f7e543fbcb19;hp=41c208530052ca7e7daad99bbc04e28089233d8b;hpb=7fc1ab01c2309d3078e3d66cfff05bf27fdad26f;p=src%2Fapp-framework-main.git diff --git a/wgt-config-xml.c b/wgt-config-xml.c index 41c2085..f92ae3a 100644 --- a/wgt-config-xml.c +++ b/wgt-config-xml.c @@ -14,6 +14,7 @@ limitations under the License. */ +#include #include #include #include @@ -46,18 +47,31 @@ static xmlNodePtr first(const char *type) return NULL; } +static int scorelang(xmlNodePtr node) +{ + char *lang = xmlNodeGetLang(node); + int score = locales_score(lang); + xmlFree(lang); + return score; +} + static xmlNodePtr element_based_localisation(const char *type) { - xmlNodePtr resu; - char *lang; + xmlNodePtr resu, elem; + int sr, s; resu = first(type); - while (resu) { - lang = xmlNodeGetLang(resu); - if (lang) { - xmlFree(lang); + if (resu) { + sr = scorelang(resu); + elem = next(resu->next, type); + while (resu) { + s = scorelang(elem); + if (s < sr) { + resu = elem; + sr = s; + } + elem = next(elem->next, type); } - resu = next(resu->next, type); } return resu; } @@ -72,8 +86,15 @@ void confixml_close() int confixml_open() { + int fd; assert(!configxml); - configxml = xmlReadFile(_config_xml_, NULL, 0); + fd = widget_open_read(_config_xml_); + if (fd < 0) { + syslog(LOG_ERR, "can't open config file %s", _config_xml_); + return fd; + } + configxml = xmlReadFd(fd, "_config_xml_", NULL, 0); + close(fd); if (configxml == NULL) { syslog(LOG_ERR, "xml parse of config file %s failed", _config_xml_); return -1;