From 381842f4c264e5946ad964f43608f7e543fbcb19 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 8 Dec 2015 14:44:38 +0100 Subject: work relatively to a root directory Change-Id: I7cbb96bd3f699092ddfded8cc8893ec780a97d8c --- wgt-config-xml.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'wgt-config-xml.c') 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; -- cgit 1.2.3-korg